PageRenderTime 78ms CodeModel.GetById 50ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/TestOfCheckVersionController.php

https://github.com/ShadMickelberry/ThinkUp
PHP | 129 lines | 83 code | 19 blank | 27 comment | 0 complexity | 87dc878cd8451ce66c370f1a83ae2ca2 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, Apache-2.0, GPL-2.0
  1. <?php
  2. /**
  3. *
  4. * ThinkUp/tests/TestOfCheckVersionController.php
  5. *
  6. * Copyright (c) 2011-2013 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-2013 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. $v_mgr = $controller->getViewManager();
  47. $config = Config::getInstance();
  48. $this->assertEqual('You must <a href="'.$config->getValue('site_root_path').
  49. 'session/login.php">log in</a> to do this.', $v_mgr->getTemplateDataItem('error_msg'));
  50. }
  51. public function testLoggedin() {
  52. $this->simulateLogin('me@example.com');
  53. $controller = new CheckVersionController(true);
  54. $results = $controller->go();
  55. $this->assertNoPattern('/You must <a href="\/session\/login.php">log in<\/a> to do this/', $results);
  56. $this->assertPattern('/var ROOT = \'thinkup_version\'/', $results);
  57. }
  58. public function testOptedOut() {
  59. include THINKUP_WEBAPP_PATH.'install/version.php';
  60. $bvalues = array('namespace' => OptionDAO::APP_OPTIONS, 'option_name' => 'is_opted_out_usage_stats',
  61. 'option_value' => 'true');
  62. $bdata = FixtureBuilder::build('options', $bvalues);
  63. $this->simulateLogin('me@example.com');
  64. $controller = new CheckVersionController(true);
  65. $results = $controller->go();
  66. $this->assertNoPattern('/You must <a href="\/session\/login.php">log in<\/a> to do this/', $results);
  67. $this->assertPattern('/var ROOT = \'thinkup_version\'/', $results);
  68. $this->assertPattern('/var CONTENT_URL = \'http:\/\/thinkup.com\/version.php\?usage=n\&v='.$THINKUP_VERSION.
  69. '/', $results);
  70. }
  71. public function testNotOptedOut() {
  72. include THINKUP_WEBAPP_PATH.'install/version.php';
  73. $this->simulateLogin('me@example.com');
  74. $controller = new CheckVersionController(true);
  75. $results = $controller->go();
  76. $this->assertPattern('/var CONTENT_URL = \'http:\/\/thinkup.com\/version.php\?v='.$THINKUP_VERSION.
  77. '/', $results);
  78. $this->assertNoPattern('/var CONTENT_URL = \'http:\/\/thinkup.com\/version.php?v='.$THINKUP_VERSION.
  79. '\&usage=n/', $results);
  80. }
  81. public function testInBetaNotOptedOut() {
  82. include THINKUP_WEBAPP_PATH.'install/version.php';
  83. $bvalues = array('namespace' => OptionDAO::APP_OPTIONS, 'option_name' => 'is_subscribed_to_beta',
  84. 'option_value' => 'true');
  85. $bdata = FixtureBuilder::build('options', $bvalues);
  86. $this->simulateLogin('me@example.com');
  87. $controller = new CheckVersionController(true);
  88. $results = $controller->go();
  89. $this->assertPattern('/var CONTENT_URL = \'http:\/\/thinkup.com\/version.php\?channel=beta\&v='.
  90. $THINKUP_VERSION.'/', $results);
  91. $this->assertNoPattern('/var CONTENT_URL = \'http:\/\/thinkup.com\/version.php?v='.$THINKUP_VERSION.
  92. '\&usage=n/', $results);
  93. }
  94. public function testInBetaOptedOut() {
  95. include THINKUP_WEBAPP_PATH.'install/version.php';
  96. $bvalues = array('namespace' => OptionDAO::APP_OPTIONS, 'option_name' => 'is_subscribed_to_beta',
  97. 'option_value' => 'true');
  98. $bdata = FixtureBuilder::build('options', $bvalues);
  99. $bvalues1 = array('namespace' => OptionDAO::APP_OPTIONS, 'option_name' => 'is_opted_out_usage_stats',
  100. 'option_value' => 'true');
  101. $bdata2= FixtureBuilder::build('options', $bvalues);
  102. $this->simulateLogin('me@example.com');
  103. $controller = new CheckVersionController(true);
  104. $results = $controller->go();
  105. $this->assertPattern('/var CONTENT_URL = \'http:\/\/thinkup.com\/version.php\?channel=beta\&v='.
  106. $THINKUP_VERSION.'/', $results);
  107. $this->assertNoPattern('/var CONTENT_URL = \'http:\/\/thinkup.com\/version.php?v='.$THINKUP_VERSION.
  108. '\&usage=n/', $results);
  109. }
  110. }