PageRenderTime 26ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/TestOfExportController.php

https://github.com/suth/ThinkUp
PHP | 197 lines | 142 code | 27 blank | 28 comment | 0 complexity | c2c4c3014cc97678f625dd9ba7e827e1 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * ThinkUp/tests/TestOfExportController.php
  5. *
  6. * Copyright (c) 2009-2013 Gina Trapani, Mark Wilkie, Michael Louis Thaler
  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. *
  24. * @author Gina Trapani <ginatrapani[at]gmail[dot]com>
  25. * @author Mark Wilkie <mark[at]bitterpill[dot]org>
  26. * @author Michael Louis Thaler <michael[dot]louis[dot]thaler[at]gmail[dot]com>
  27. * @license http://www.gnu.org/licenses/gpl.html
  28. * @copyright 2009-2013 Gina Trapani, Mark Wilkie, Michael Louis Thaler
  29. */
  30. require_once dirname(__FILE__).'/init.tests.php';
  31. require_once THINKUP_WEBAPP_PATH.'_lib/extlib/simpletest/autorun.php';
  32. require_once THINKUP_WEBAPP_PATH.'config.inc.php';
  33. class TestOfExportController extends ThinkUpUnitTestCase {
  34. public function testConstructor() {
  35. $controller = new ExportController(true);
  36. $this->assertTrue(isset($controller));
  37. }
  38. public function testNotLoggedIn() {
  39. $controller = new ExportController(true);
  40. $this->assertTrue(isset($controller));
  41. $results = $controller->go();
  42. $v_mgr = $controller->getViewManager();
  43. $config = Config::getInstance();
  44. $this->assertEqual('You must <a href="'.$config->getValue('site_root_path').
  45. 'session/login.php">log in</a> to do this.', $v_mgr->getTemplateDataItem('error_msg'));
  46. }
  47. public function testMissingParams() {
  48. $this->simulateLogin('me@example.com');
  49. $controller = new ExportController(true);
  50. $this->assertTrue(isset($controller));
  51. $results = $controller->control();
  52. $this->assertPattern("/No user to retrieve./", $results);
  53. }
  54. public function testNonExistentUser() {
  55. $this->simulateLogin('me@example.com');
  56. $_GET['u'] = 'idontexist';
  57. $_GET['n'] = 'idontexist';
  58. $controller = new ExportController(true);
  59. $this->assertTrue(isset($controller));
  60. $results = $controller->control();
  61. $this->assertPattern("/User idontexist on idontexist is not in ThinkUp./", $results);
  62. }
  63. public function testOwnerWithoutAccess() {
  64. $builders = $this->buildData();
  65. $this->simulateLogin('me@example.com');
  66. $_GET['u'] = 'someuser2';
  67. $_GET['n'] = 'twitter';
  68. $controller = new ExportController(true);
  69. $this->assertTrue(isset($controller));
  70. $results = $controller->control();
  71. $this->assertPattern("/Insufficient privileges/", $results);
  72. }
  73. public function testOwnerWithAccess() {
  74. $builders = $this->buildData();
  75. $builders2 = $this->buildFacebookData();
  76. $this->simulateLogin('me@example.com');
  77. $_GET['u'] = 'someuser1';
  78. $_GET['n'] = 'twitter';
  79. $controller = new ExportController(true);
  80. $this->assertTrue(isset($controller));
  81. ob_start();
  82. $controller->control();
  83. $results = ob_get_contents();
  84. ob_end_clean();
  85. $this->assertPattern("/My first post/", $results);
  86. $this->assertPattern("/My second post/", $results);
  87. $this->assertNoPattern("/My first Facebook post/", $results);
  88. }
  89. public function testOwnerWithAccessFacebookPageData() {
  90. $builders = $this->buildFacebookData();
  91. $builders2 = $this->buildData();
  92. $this->simulateLogin('me2@example.com');
  93. $_GET['u'] = 'someuser1';
  94. $_GET['n'] = 'facebook page';
  95. $controller = new ExportController(true);
  96. $this->assertTrue(isset($controller));
  97. ob_start();
  98. $controller->control();
  99. $results = ob_get_contents();
  100. ob_end_clean();
  101. $this->assertPattern("/My first Facebook post/", $results);
  102. $this->assertPattern("/My second Facebook post/", $results);
  103. $this->assertNoPattern("/My first post/", $results);
  104. }
  105. public function testExplicitPostsExport() {
  106. $builders = $this->buildData();
  107. $this->simulateLogin('me@example.com');
  108. $_GET['u'] = 'someuser1';
  109. $_GET['n'] = 'twitter';
  110. $_GET['type'] = 'posts';
  111. $controller = new ExportController(true);
  112. $this->assertTrue(isset($controller));
  113. ob_start();
  114. $controller->control();
  115. $results = ob_get_contents();
  116. ob_end_clean();
  117. $this->assertPattern("/My first post/", $results);
  118. }
  119. public function testRepliesExport() {
  120. $builders = $this->buildData();
  121. $this->simulateLogin('me@example.com');
  122. $_GET['u'] = 'someuser1';
  123. $_GET['n'] = 'twitter';
  124. $_GET['type'] = 'replies';
  125. $_GET['post_id'] = '1';
  126. $controller = new ExportController(true);
  127. $this->assertTrue(isset($controller));
  128. ob_start();
  129. $controller->control();
  130. $results = ob_get_contents();
  131. ob_end_clean();
  132. $this->assertPattern("/Reply to first post/", $results);
  133. }
  134. private function buildData() {
  135. $builders[] = FixtureBuilder::build('owners', array('id'=>1, 'email'=>'me@example.com'));
  136. $builders[] = FixtureBuilder::build('instances', array('id'=>1, 'network_username'=>'someuser1',
  137. 'network'=>'twitter'));
  138. $builders[] = FixtureBuilder::build('instances', array('id'=>2, 'network_username'=>'someuser2',
  139. 'network'=>'twitter'));
  140. $builders[] = FixtureBuilder::build('owner_instances', array('instance_id'=>1, 'owner_id'=>1));
  141. $builders[] = FixtureBuilder::build('posts', array('post_id' => '1', 'author_username'=>'someuser1',
  142. 'post_text'=>'My first post', 'network'=>'twitter'));
  143. $builders[] = FixtureBuilder::build('posts', array('post_id' => '2', 'author_username'=>'someuser1',
  144. 'post_text'=>'My second post', 'network'=>'twitter'));
  145. $builders[] = FixtureBuilder::build('posts', array('post_id' => '3', 'author_username'=>'someuser2',
  146. 'post_text'=>'Reply to first post', 'network'=>'twitter', 'in_reply_to_post_id' => '1',
  147. 'author_user_id'=>'15'));
  148. $builders[] = FixtureBuilder::build('users', array('user_id'=>'15', 'network_username'=>'someuser2',
  149. 'network'=>'twitter'));
  150. return $builders;
  151. }
  152. private function buildFacebookData() {
  153. $builders[] = FixtureBuilder::build('owners', array('id'=>2, 'email'=>'me2@example.com'));
  154. $builders[] = FixtureBuilder::build('instances', array('id'=>3, 'network_username'=>'someuser1',
  155. 'network'=>'facebook page'));
  156. $builders[] = FixtureBuilder::build('instances', array('id'=>4, 'network_username'=>'someuser2',
  157. 'network'=>'facebeook page'));
  158. $builders[] = FixtureBuilder::build('owner_instances', array('instance_id'=>3, 'owner_id'=>2));
  159. $builders[] = FixtureBuilder::build('posts', array('post_id' => '1', 'author_username'=>'someuser1',
  160. 'post_text'=>'My first Facebook post', 'network'=>'facebook page'));
  161. $builders[] = FixtureBuilder::build('posts', array('post_id' => '2', 'author_username'=>'someuser1',
  162. 'post_text'=>'My second Facebook post', 'network'=>'facebook page'));
  163. $builders[] = FixtureBuilder::build('posts', array('post_id' => '3', 'author_username'=>'someuser2',
  164. 'post_text'=>'Reply to first Facebook post', 'network'=>'facebook page', 'in_reply_to_post_id' => '1',
  165. 'author_user_id'=>'15'));
  166. $builders[] = FixtureBuilder::build('users', array('user_id'=>'15', 'network_username'=>'someuser2',
  167. 'network'=>'facebook'));
  168. return $builders;
  169. }
  170. }