PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/tests/TestOfCheckVersionController.php

http://github.com/ginatrapani/ThinkUp
PHP | 125 lines | 80 code | 18 blank | 27 comment | 0 complexity | e9173d087e6d22c3ebf20043968e79af MD5 | raw file
Possible License(s): Apache-2.0, GPL-2.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. *
  4. * ThinkUp/tests/TestOfCheckVersionController.php
  5. *
  6. * Copyright (c) 2011-2016 Gina Trapani
  7. *
  8. * LICENSE:
  9. *
  10. * This file is part of ThinkUp (http://thinkup.com).
  11. *
  12. * ThinkUp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
  13. * License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any
  14. * later version.
  15. *
  16. * ThinkUp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
  17. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  18. * details.
  19. *
  20. * You should have received a copy of the GNU General Public License along with ThinkUp. If not, see
  21. * <http://www.gnu.org/licenses/>.
  22. *
  23. * Test of CheckCrawlerController
  24. *
  25. * @license http://www.gnu.org/licenses/gpl.html
  26. * @copyright 2011-2016 Gina Trapani
  27. * @author Gina Trapani <ginatrapani[at]gmail[dot]com>
  28. */
  29. require_once dirname(__FILE__).'/init.tests.php';
  30. require_once THINKUP_WEBAPP_PATH.'_lib/extlib/simpletest/autorun.php';
  31. require_once THINKUP_WEBAPP_PATH.'config.inc.php';
  32. class TestOfCheckVersionController extends ThinkUpUnitTestCase {
  33. public function setUp(){
  34. parent::setUp();
  35. }
  36. public function tearDown(){
  37. parent::tearDown();
  38. }
  39. public function testConstructor() {
  40. $controller = new CheckVersionController(true);
  41. $this->assertTrue(isset($controller));
  42. }
  43. public function testNotLoggedIn() {
  44. $controller = new CheckVersionController(true);
  45. $results = $controller->go();
  46. $this->assertPattern( '/session\/login.php\?redirect\=/', $controller->redirect_destination);
  47. }
  48. public function testLoggedin() {
  49. $this->simulateLogin('me@example.com');
  50. $controller = new CheckVersionController(true);
  51. $results = $controller->go();
  52. $this->assertNoPattern('/You must <a href="\/session\/login.php">log in<\/a> to do this/', $results);
  53. $this->assertPattern('/var ROOT = \'thinkup_version\'/', $results);
  54. }
  55. public function testOptedOut() {
  56. include THINKUP_WEBAPP_PATH.'install/version.php';
  57. $bvalues = array('namespace' => OptionDAO::APP_OPTIONS, 'option_name' => 'is_opted_out_usage_stats',
  58. 'option_value' => 'true');
  59. $bdata = FixtureBuilder::build('options', $bvalues);
  60. $this->simulateLogin('me@example.com');
  61. $controller = new CheckVersionController(true);
  62. $results = $controller->go();
  63. $this->assertNoPattern('/You must <a href="\/session\/login.php">log in<\/a> to do this/', $results);
  64. $this->assertPattern('/var ROOT = \'thinkup_version\'/', $results);
  65. $this->assertPattern('/var CONTENT_URL = \'http:\/\/thinkup.com\/version.php\?usage=n\&v='.$THINKUP_VERSION.
  66. '/', $results);
  67. }
  68. public function testNotOptedOut() {
  69. include THINKUP_WEBAPP_PATH.'install/version.php';
  70. $this->simulateLogin('me@example.com');
  71. $controller = new CheckVersionController(true);
  72. $results = $controller->go();
  73. $this->assertPattern('/var CONTENT_URL = \'http:\/\/thinkup.com\/version.php\?v='.$THINKUP_VERSION.
  74. '/', $results);
  75. $this->assertNoPattern('/var CONTENT_URL = \'http:\/\/thinkup.com\/version.php?v='.$THINKUP_VERSION.
  76. '\&usage=n/', $results);
  77. }
  78. public function testInBetaNotOptedOut() {
  79. include THINKUP_WEBAPP_PATH.'install/version.php';
  80. $bvalues = array('namespace' => OptionDAO::APP_OPTIONS, 'option_name' => 'is_subscribed_to_beta',
  81. 'option_value' => 'true');
  82. $bdata = FixtureBuilder::build('options', $bvalues);
  83. $this->simulateLogin('me@example.com');
  84. $controller = new CheckVersionController(true);
  85. $results = $controller->go();
  86. $this->assertPattern('/var CONTENT_URL = \'http:\/\/thinkup.com\/version.php\?channel=beta\&v='.
  87. $THINKUP_VERSION.'/', $results);
  88. $this->assertNoPattern('/var CONTENT_URL = \'http:\/\/thinkup.com\/version.php?v='.$THINKUP_VERSION.
  89. '\&usage=n/', $results);
  90. }
  91. public function testInBetaOptedOut() {
  92. include THINKUP_WEBAPP_PATH.'install/version.php';
  93. $bvalues = array('namespace' => OptionDAO::APP_OPTIONS, 'option_name' => 'is_subscribed_to_beta',
  94. 'option_value' => 'true');
  95. $bdata = FixtureBuilder::build('options', $bvalues);
  96. $bvalues1 = array('namespace' => OptionDAO::APP_OPTIONS, 'option_name' => 'is_opted_out_usage_stats',
  97. 'option_value' => 'true');
  98. $bdata2= FixtureBuilder::build('options', $bvalues);
  99. $this->simulateLogin('me@example.com');
  100. $controller = new CheckVersionController(true);
  101. $results = $controller->go();
  102. $this->assertPattern('/var CONTENT_URL = \'http:\/\/thinkup.com\/version.php\?channel=beta\&v='.
  103. $THINKUP_VERSION.'/', $results);
  104. $this->assertNoPattern('/var CONTENT_URL = \'http:\/\/thinkup.com\/version.php?v='.$THINKUP_VERSION.
  105. '\&usage=n/', $results);
  106. }
  107. }