PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/webapp/plugins/foursquare/tests/TestOfFoursquarePluginConfigurationController.php

https://github.com/ShadMickelberry/ThinkUp
PHP | 526 lines | 294 code | 53 blank | 179 comment | 0 complexity | 6fbf5469f2a68e3927444d401cf54696 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, Apache-2.0, GPL-2.0
  1. <?php
  2. /**
  3. *
  4. * ThinkUp/webapp/plugins/foursquare/tests/TestOfFoursquarePluginConfigurationController.php
  5. *
  6. * Copyright (c) 2012-2013 Aaron Kalair
  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 Aaron Kalair <aaronkalair[at]gmail[dot]com>
  25. * @license http://www.gnu.org/licenses/gpl.html
  26. * @copyright 2012-2013 Aaron Kalair
  27. */
  28. require_once dirname(__FILE__) . '/../../../../tests/init.tests.php';
  29. require_once THINKUP_ROOT_PATH.'webapp/_lib/extlib/simpletest/autorun.php';
  30. require_once THINKUP_ROOT_PATH.'webapp/config.inc.php';
  31. require_once THINKUP_ROOT_PATH.'tests/classes/class.ThinkUpBasicUnitTestCase.php';
  32. require_once THINKUP_ROOT_PATH.'webapp/plugins/foursquare/controller/class.FoursquarePluginConfigurationController.php';
  33. require_once THINKUP_ROOT_PATH.'webapp/plugins/foursquare/model/class.FoursquareCrawler.php';
  34. require_once THINKUP_ROOT_PATH.'webapp/plugins/foursquare/model/class.FoursquarePlugin.php';
  35. // Handle API queries locally
  36. require_once THINKUP_ROOT_PATH.'webapp/plugins/foursquare/tests/classes/mock.FoursquareAPIAccessor.php';
  37. class TestOfFoursquarePluginConfigurationController extends ThinkUpUnitTestCase {
  38. // Do some set up work, registering the plugin and settings variables like server name etc.
  39. public function setUp(){
  40. // Call the ThinkUpUnitTestCase constructor
  41. parent::setUp();
  42. // Get an instance
  43. $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
  44. // Register the foursquare plugin
  45. $webapp_plugin_registrar->registerPlugin('foursquare', 'FoursquarePlugin');
  46. // Set the server name variable as we don't actually have a server
  47. $_SERVER['SERVER_NAME'] = 'test';
  48. }
  49. public function tearDown() {
  50. // Clean up any database changes we made
  51. parent::tearDown();
  52. }
  53. // Build various structures like options, controller and the owner
  54. private function buildController() {
  55. // Create an owner
  56. $builder_owner = FixtureBuilder::build('owners', array('email' => 'me@example.com', 'user_activated' => 1) );
  57. // Set the name space to plugin_options-pluginid
  58. $sql = "select id from " . $this->table_prefix . "plugins where folder_name = 'foursquare'";
  59. $stmt = PluginMySQLDAO::$PDO->query($sql);
  60. $data = $stmt->fetch(PDO::FETCH_ASSOC);
  61. $namespace = OptionDAO::PLUGIN_OPTIONS . '-'.$data['id'];
  62. // Create the client id option
  63. $builder_plugin_options[] =
  64. FixtureBuilder::build('options',
  65. array('namespace' => $namespace, 'option_name' => 'foursquare_client_id',
  66. 'option_value' => "ci") );
  67. // Create the client secret option
  68. $builder_plugin_options[] =
  69. FixtureBuilder::build('options',
  70. array('namespace' => $namespace, 'option_name' => 'foursquare_client_secret',
  71. 'option_value' => "cs") );
  72. // Log the user in
  73. $this->simulateLogin('me@example.com');
  74. // Get an owner DAO
  75. $owner_dao = DAOFactory::getDAO('OwnerDAO');
  76. // Get the logged in users email
  77. $owner = $owner_dao->getByEmail(Session::getLoggedInUser());
  78. // Create a new foursquare config controller for the owner
  79. $controller = new FoursquarePluginConfigurationController($owner);
  80. // Return an array with the controller, owner, and options
  81. return array($controller, $builder_owner, $builder_plugin_options);
  82. }
  83. public function getElementById($doc, $id) {
  84. $xpath = new DOMXPath($doc);
  85. return $xpath->query("//*[@id='$id']")->item(0);
  86. }
  87. // Insert the plugin options in the database
  88. private function buildPluginOptions() {
  89. $builders = array();
  90. // Set the plugin ID
  91. $sql = "select id from " . $this->table_prefix . "plugins where folder_name = 'foursquare'";
  92. $stmt = PluginMySQLDAO::$PDO->query($sql);
  93. $data = $stmt->fetch(PDO::FETCH_ASSOC);
  94. $namespace = OptionDAO::PLUGIN_OPTIONS . '-'.$data['id'];
  95. // Create the client id option
  96. $builders[] = FixtureBuilder::build('options', array('namespace' => $namespace,
  97. 'option_name' => 'foursquare_client_id', 'option_value' => "ci") );
  98. // Create the client secret option
  99. $builders[] = FixtureBuilder::build('options', array('namespace' => $namespace,
  100. 'option_name' => 'foursquare_client_secret', 'option_value' => "cs") );
  101. return $builders;
  102. }
  103. public function testConstructor() {
  104. // Create a new controller
  105. $controller = new FoursquarePluginConfigurationController(null);
  106. // Check the controller was created
  107. $this->assertNotNull($controller);
  108. // Check the controller is of type foursquare
  109. $this->assertIsA($controller, 'FoursquarePluginConfigurationController');
  110. }
  111. public function testOutput() {
  112. // Not logged in, no owner set
  113. $controller = new FoursquarePluginConfigurationController(null);
  114. // Run the plugin configuration controller
  115. $output = $controller->go();
  116. // Get a view manager
  117. $v_mgr = $controller->getViewManager();
  118. // Get an instance
  119. $config = Config::getInstance();
  120. // Check the user sees a message telling them they need to login
  121. $this->assertEqual('You must <a href="'.$config->getValue('site_root_path').
  122. 'session/login.php">log in</a> to do this.', $v_mgr->getTemplateDataItem('error_msg'));
  123. // Logged in
  124. // Build a user
  125. $builder = FixtureBuilder::build('owners', array('email' => 'me@example.com', 'user_activated' => 1) );
  126. // Log the user in
  127. $this->simulateLogin('me@example.com');
  128. // Get a owner DAO
  129. $owner_dao = DAOFactory::getDAO('OwnerDAO');
  130. // Get the owners email
  131. $owner = $owner_dao->getByEmail(Session::getLoggedInUser());
  132. // Create a new foursquare controller for the owner
  133. $controller = new FoursquarePluginConfigurationController($owner);
  134. // Run the plugin configuration controller
  135. $output = $controller->go();
  136. // Get a view manager
  137. $v_mgr = $controller->getViewManager();
  138. }
  139. public function testConfigOptionsNotAdmin() {
  140. self::buildInstanceData();
  141. // build some options data
  142. $options_array = $this->buildPluginOptions();
  143. $this->simulateLogin('me@example.com');
  144. $owner_dao = DAOFactory::getDAO('OwnerDAO');
  145. $owner = $owner_dao->getByEmail(Session::getLoggedInUser());
  146. $controller = new FoursquarePluginConfigurationController($owner);
  147. $output = $controller->go();
  148. // we have a text form element with proper data
  149. $this->assertNoPattern('/Pause crawling/', $output);
  150. $this->assertNoPattern('/Start crawling/', $output);
  151. $this->assertNoPattern('/Save Settings/', $output); // should have no submit option
  152. $this->assertNoPattern('/plugin_options_foursquare_client_id_label/', $output); // should have no app id
  153. $this->assertNoPattern('/plugin_options_foursquare_client_secret_label/', $output); // no secret
  154. $this->assertPattern('/var is_admin = false/', $output); // not a js admin
  155. $this->assertPattern('/var required_values_set = true/', $output); // is configured
  156. //app not configured
  157. $sql = "select id from " . $this->table_prefix . "plugins where folder_name = 'foursquare'";
  158. $stmt = PluginMySQLDAO::$PDO->query($sql);
  159. $data = $stmt->fetch(PDO::FETCH_ASSOC);
  160. $namespace = OptionDAO::PLUGIN_OPTIONS . '-'.$data['id'];
  161. $prefix = Config::getInstance()->getValue('table_prefix');
  162. OwnerMySQLDAO::$PDO->query("delete from " . $prefix . "options where namespace = '$namespace'");
  163. $controller = new FoursquarePluginConfigurationController($owner);
  164. $output = $controller->go();
  165. $this->assertPattern('/var required_values_set = false/', $output); // is not configured
  166. }
  167. public function testConfigOptionsIsAdmin() {
  168. $builders = self::buildInstanceData();
  169. // build some options data
  170. $options_array = $this->buildPluginOptions();
  171. $this->simulateLogin('me@example.com', true);
  172. $owner_dao = DAOFactory::getDAO('OwnerDAO');
  173. $owner = $owner_dao->getByEmail(Session::getLoggedInUser());
  174. $controller = new FoursquarePluginConfigurationController($owner);
  175. $output = $controller->go();
  176. // we have a text form element with proper data
  177. $this->assertPattern('/Pause crawling/', $output);
  178. $this->assertPattern('/Save Settings/', $output); // should have submit option
  179. $this->assertPattern('/plugin_options_foursquare_client_id/', $output); // should have no app id
  180. $this->assertPattern('/plugin_options_foursquare_client_secret/', $output); // no secret
  181. $this->assertPattern('/var is_admin = true/', $output); // is a js admin
  182. $this->assertPattern('/var required_values_set = true/', $output); // is configured
  183. //app not configured
  184. $sql = "select id from " . $this->table_prefix . "plugins where folder_name = 'foursquare'";
  185. $stmt = PluginMySQLDAO::$PDO->query($sql);
  186. $data = $stmt->fetch(PDO::FETCH_ASSOC);
  187. $prefix = Config::getInstance()->getValue('table_prefix');
  188. $namespace = OptionDAO::PLUGIN_OPTIONS . '-'.$data['id'];
  189. OwnerMySQLDAO::$PDO->query("delete from " . $prefix . "options where namespace = '$namespace'");
  190. $controller = new FoursquarePluginConfigurationController($owner);
  191. $output = $controller->go();
  192. $this->debug($output);
  193. $this->assertPattern('/var required_values_set = false/', $output); // is not configured
  194. }
  195. private function buildInstanceData() {
  196. $builders = array();
  197. $builders[] = FixtureBuilder::build('owners', array('id'=>1, 'full_name'=>'ThinkUp J. User',
  198. 'email'=>'me@example.com', 'is_activated'=>1));
  199. //Add instance
  200. $builders[] = FixtureBuilder::build('instances', array('id'=>1, 'network_user_id'=>'606837591',
  201. 'network_username'=>'Gina Trapani', 'network'=>'foursquare', 'is_active'=>1));
  202. //Add owner instance_owner
  203. $builders[] = FixtureBuilder::build('owner_instances', array('owner_id'=>1, 'instance_id'=>1,
  204. 'oauth_access_token'=>'faux-access-token1', 'auth_error'=>'Token has expired.'));
  205. //Add second instance
  206. $builders[] = FixtureBuilder::build('instances', array('id'=>2, 'network_user_id'=>'668406218',
  207. 'network_username'=>'Penelope Caridad', 'network'=>'foursquare', 'is_active'=>1));
  208. //Add second owner instance_owner
  209. $builders[] = FixtureBuilder::build('owner_instances', array('owner_id'=>2, 'instance_id'=>2,
  210. 'oauth_access_token'=>'faux-access-token2', 'auth_error'=>''));
  211. return $builders;
  212. }
  213. // Check the options were inserted correctly into the database
  214. public function testOptionList2HashByOptionName() {
  215. // Build a controller
  216. $build_data = $this->buildController();
  217. // Get the controller from the first element of the array the above command returned
  218. $controller = $build_data[0];
  219. // Get a hash of plugin options with option_name as the key
  220. $options_hash = $controller->optionList2HashByOptionName();
  221. // Check the client id is the 2nd option set
  222. $this->assertEqual($options_hash['foursquare_client_id']->id, 2);
  223. // Check the name of the client id option is foursquare_client_id
  224. $this->assertEqual($options_hash['foursquare_client_id']->option_name, 'foursquare_client_id');
  225. // Check the value is test_client_id
  226. $this->assertEqual($options_hash['foursquare_client_id']->option_value, 'ci');
  227. // Check the client secret is the 3rd option set
  228. $this->assertEqual($options_hash['foursquare_client_secret']->id, 3);
  229. // Check that the name of the client secret option is foursquare_client_secret
  230. $this->assertEqual($options_hash['foursquare_client_secret']->option_name, 'foursquare_client_secret');
  231. // Check the value of the client secret is test_client_secret
  232. $this->assertEqual($options_hash['foursquare_client_secret']->option_value, 'cs');
  233. }
  234. // Check all the correct options get added to the template for a non admin
  235. public function testAddTextOptionNotAdmin() {
  236. // Build some things we need
  237. $build_data = $this->buildController();
  238. // Get the controller from the array the above call returned
  239. $controller = $build_data[0];
  240. // Get the owner from the array the above call returned
  241. $owner = $build_data[1];
  242. // Get the plugin options from the array the above call returned
  243. $plugin_option = $build_data[2];
  244. // Just user, not an admin, so view only
  245. // Run the controller
  246. $output = $controller->go();
  247. // Check some option elements were set
  248. $this->assertNotNull( $controller->option_elements);
  249. // Check 2 option elements were set
  250. $this->assertEqual( count($controller->option_elements), 2);
  251. // Check the foursquare client ID option is set
  252. $this->assertNotNull( $controller->option_elements['foursquare_client_id']);
  253. //
  254. $this->assertEqual(
  255. PluginConfigurationController::FORM_TEXT_ELEMENT,
  256. $controller->option_elements['foursquare_client_id']['type'] );
  257. // Check the default value was set
  258. $this->assertTrue( isset($controller->option_elements['foursquare_client_id']['default_value']) );
  259. // Check 2 required messages are present on the entire page
  260. $this->assertEqual( count($controller->option_required_message), 2);
  261. // Check the client id has a message
  262. $this->assertTrue( isset($controller->option_required_message['foursquare_client_id']));
  263. // Check the client secret option is set
  264. $this->assertNotNull( $controller->option_elements['foursquare_client_secret']);
  265. //
  266. $this->assertEqual(
  267. PluginConfigurationController::FORM_TEXT_ELEMENT,
  268. $controller->option_elements['foursquare_client_secret']['type'] );
  269. // Check the client secret has a default value
  270. $this->assertTrue(isset($controller->option_elements['foursquare_client_secret']['default_value']) );
  271. // Check it has a required message
  272. $this->assertTrue(isset($controller->option_required_message['foursquare_client_secret']));
  273. // Get a view manager
  274. $v_mgr = $controller->getViewManager();
  275. // Get the markup for options
  276. $options_markup = $v_mgr->getTemplateDataItem('options_markup');
  277. // Check the options markup was actually set
  278. $this->assertNotNull($options_markup);
  279. // Parse option_markup
  280. $doc = new DOMDocument();
  281. // Parse our html
  282. $doc->loadHTML("<html><body>" . $options_markup . "</body></html>");
  283. }
  284. // Check all the correct options get added to the template for a admin
  285. public function testAddTextOptionIsAdmin() {
  286. // Set admin to be true
  287. $is_admin = 1;
  288. // Log the owner in
  289. $this->simulateLogin('me@example.com', true);
  290. // Build the data structures
  291. $build_data = $this->buildController();
  292. // Get the controller from the array
  293. $controller = $build_data[0];
  294. // Get the owner from the array
  295. $owner = $build_data[1];
  296. // Get the plugin options from the array
  297. $plugin_option = $build_data[2];
  298. // Just name, is admin, so form should be enabled
  299. $output = $controller->go();
  300. $this->assertNotNull( $controller->option_elements);
  301. $this->assertEqual( count($controller->option_elements), 2);
  302. $this->assertNotNull( $controller->option_elements['foursquare_client_id']);
  303. $this->assertEqual(
  304. PluginConfigurationController::FORM_TEXT_ELEMENT,
  305. $controller->option_elements['foursquare_client_id']['type'] );
  306. $this->assertTrue( isset($controller->option_elements['foursquare_client_id']['default_value']) );
  307. $this->assertEqual( count($controller->option_required_message), 2);
  308. $this->assertTrue( isset($controller->option_required_message['foursquare_client_id']));
  309. $v_mgr = $controller->getViewManager();
  310. $options_markup = $v_mgr->getTemplateDataItem('options_markup');
  311. $this->assertNotNull($options_markup);
  312. // Parse option_markup
  313. $doc = new DOMDocument();
  314. // Parse our html
  315. //$doc = $doc->loadHTML("<html><body>" . $options_markup . "</body></html>");
  316. $doc->loadHTML("<html><body>" . $options_markup . "</body></html>");
  317. // We have a text form element with proper data
  318. $input_field = self::getElementById($doc, 'plugin_options_foursquare_client_id');
  319. $this->assertEqual($input_field->getAttribute('value'), $plugin_option[0]->columns['option_value']);
  320. $input_field = self::getElementById($doc, 'plugin_options_foursquare_client_secret');
  321. $this->assertEqual($input_field->getAttribute('value'), $plugin_option[1]->columns['option_value']);
  322. // Submit and elements should be disabled
  323. $this->assertFalse($input_field->getAttribute('disabled'));
  324. $submit_p = self::getElementById($doc, 'plugin_option_submit_p');
  325. $this->assertPattern('/type="submit".*Save Settings/', $doc->saveXML( $submit_p ) );
  326. }
  327. // Test we can get the options correctly
  328. public function testGetPluginOptions() {
  329. // Build the data structures
  330. $build_data = $this->buildController();
  331. // Get the controller from the array
  332. $controller = $build_data[0];
  333. // Get a hash of the options
  334. $options_hash = $controller->getPluginOptions();
  335. // Check they are all set correctly
  336. $this->assertEqual($options_hash['foursquare_client_id']->id, 2);
  337. $this->assertEqual($options_hash['foursquare_client_id']->option_name, 'foursquare_client_id');
  338. $this->assertEqual($options_hash['foursquare_client_id']->option_value, 'ci');
  339. // Get a single undefined option
  340. $this->assertFalse($controller->getPluginOption('not defined'));
  341. // Get a single defined option
  342. $this->assertEqual($controller->getPluginOption('foursquare_client_id'), 'ci');
  343. }
  344. // Check the correct screen is presented to the users when the configuration is not complete
  345. public function testConfigNotSet() {
  346. // Create a owner
  347. $builder = FixtureBuilder::build('owners', array('email' => 'me@example.com', 'user_activated' => 1) );
  348. // Get a options DAO
  349. $plugin_options_dao = DAOFactory::getDAO("PluginOptionDAO");
  350. //
  351. PluginOptionMySQLDAO::$cached_options = array();
  352. // Log the owner in
  353. $this->simulateLogin('me@example.com');
  354. // Get a owner DAO
  355. $owner_dao = DAOFactory::getDAO('OwnerDAO');
  356. // Get the logged in owners email address
  357. $owner = $owner_dao->getByEmail(Session::getLoggedInUser());
  358. // Create a new foursquare config controller for the owner
  359. $controller = new FoursquarePluginConfigurationController($owner);
  360. $results = $controller->go();
  361. $v_mgr = $controller->getViewManager();
  362. // Config is not complete so they should see a error message
  363. $info = $v_mgr->getTemplateDataItem('info_msgs');
  364. $this->assertEqual($info['setup'], 'Please complete plugin setup to start using it');
  365. // Shouldn't see the authorize link
  366. $this->assertNoPattern("/Click on this button to authorize ThinkUp to access your foursquare account./",
  367. $results);
  368. $this->assertNoPattern("/Authorize ThinkUp on foursquare/", $results);
  369. }
  370. // Test the owner has the option to add a foursquare user when the plugin is configured
  371. public function testConfigSet() {
  372. // Build the plugin options to configure the plugin
  373. $builders = $this->buildPluginOptions();
  374. // Create an owner
  375. $builder = FixtureBuilder::build('owners', array('email' => 'me@example.com', 'user_activated' => 1) );
  376. // Get a plugin options DAO
  377. $plugin_options_dao = DAOFactory::getDAO("PluginOptionDAO");
  378. //
  379. PluginOptionMySQLDAO::$cached_options = array();
  380. // Log the owner in
  381. $this->simulateLogin('me@example.com');
  382. // Get a owner DAO
  383. $owner_dao = DAOFactory::getDAO('OwnerDAO');
  384. // Get the logged in owners email
  385. $owner = $owner_dao->getByEmail(Session::getLoggedInUser());
  386. // Create a config controller for them
  387. $controller = new FoursquarePluginConfigurationController($owner);
  388. $results = $controller->go();
  389. // Shouldn't see error message
  390. $this->assertNoPattern("/Please set your Foursquare client ID and secret./", $results);
  391. // Should see authorize link
  392. $this->assertPattern("/Add a Foursquare User/", $results);
  393. }
  394. // Test getting the OAuth tokens from foursquare
  395. public function testGetOAuthTokens() {
  396. // Set the plugin options
  397. $builders = $this->buildPluginOptions();
  398. // Get an instance
  399. $config = Config::getInstance();
  400. // Set the root path
  401. $config->setValue('site_root_path', '/');
  402. // Get a plugin options DAO
  403. $plugin_options_dao = DAOFactory::getDAO("PluginOptionDAO");
  404. //
  405. PluginOptionMySQLDAO::$cached_options = array();
  406. // Build an owner
  407. $builders[] = FixtureBuilder::build('owners', array('email' => 'me@example.com', 'user_activated' => 1) );
  408. $instance_builder = FixtureBuilder::build('instances', array('id'=>1, 'network_user_id'=>'18127856',
  409. 'network_username'=>'me@me.com', 'network'=>'foursquare', 'is_active'=>1));
  410. //Add owner instance_owner
  411. $owner_instance_builder = FixtureBuilder::build('owner_instances', array('owner_id'=>1, 'instance_id'=>1,
  412. 'oauth_access_token'=>'secret'));
  413. // Log them in
  414. $this->simulateLogin('me@example.com');
  415. // Get an owner DAO
  416. $owner_dao = DAOFactory::getDAO('OwnerDAO');
  417. // Get the logged in owners email
  418. $owner = $owner_dao->getByEmail(Session::getLoggedInUser());
  419. // Create a new config controller for the owner
  420. $controller = new FoursquarePluginConfigurationController($owner);
  421. // Set the code foursquare would return from a real request
  422. $_GET['code'] = '5dn';
  423. // Check we get the tokens and tell the user it was a sucess
  424. $results = $controller->go();
  425. $v_mgr = $controller->getViewManager();
  426. $msgs = $v_mgr->getTemplateDataItem('success_msgs');
  427. $this->assertEqual($msgs['user_add'], 'Success! Your foursquare account has been added to ThinkUp.');
  428. // Get an owner instance DAO
  429. $owner_instance_dao = new OwnerInstanceMySQLDAO();
  430. // Get a instance DAO
  431. $instance_dao = new InstanceMySQLDAO();
  432. // Check we created a foursquare instance
  433. $instance = $instance_dao->getByUserIdOnNetwork('18127856', 'foursquare');
  434. $this->assertNotNull($instance);
  435. // Check a owner instance for this user with the instance ID was created
  436. $owner_instance = $owner_instance_dao->get($owner->id, $instance->id);
  437. $this->assertNotNull($owner_instance);
  438. // OAuth tokens set
  439. $this->assertEqual($owner_instance->oauth_access_token, 'secret');
  440. }
  441. // Supply a bad return code from foursquare and check the user is told theres an error
  442. public function testGetOAuthTokensWithError() {
  443. // Build the plugin options
  444. $builders = $this->buildPluginOptions();
  445. // Get an instance
  446. $config = Config::getInstance();
  447. // Set the root path
  448. $config->setValue('site_root_path', '/');
  449. // Get a plugin option DAO
  450. $plugin_options_dao = DAOFactory::getDAO("PluginOptionDAO");
  451. //
  452. PluginOptionMySQLDAO::$cached_options = array();
  453. // Build a owner
  454. $builders[] = FixtureBuilder::build('owners', array('email' => 'me@example.com', 'user_activated' => 1) );
  455. // Log the owner in
  456. $this->simulateLogin('me@example.com');
  457. // Get a owner DAO
  458. $owner_dao = DAOFactory::getDAO('OwnerDAO');
  459. // Get the logged in owners email address
  460. $owner = $owner_dao->getByEmail(Session::getLoggedInUser());
  461. // Create a new controller for this user
  462. $controller = new FoursquarePluginConfigurationController($owner);
  463. // Set the return code from foursquare to anything not valid
  464. $_GET['code'] = 'error5dn';
  465. // Check the user is told theres a problem
  466. $results = $controller->go();
  467. $v_mgr = $controller->getViewManager();
  468. $this->assertEqual($v_mgr->getTemplateDataItem('success_msg'), '');
  469. $msgs = $v_mgr->getTemplateDataItem('error_msgs');
  470. $this->assertEqual($msgs['authorization'], 'Oops! Something went wrong while obtaining OAuth tokens.'.
  471. ' foursquare says "foursquare_error_text." Please double-check your settings and try again.');
  472. }
  473. }