PageRenderTime 59ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/webapp/plugins/expandurls/tests/TestOfFlickrAPIAccessor.php

https://github.com/SimonCoopey/ThinkUp
PHP | 81 lines | 40 code | 14 blank | 27 comment | 0 complexity | 37762ad5ba85bc3d57309ee8117af5c3 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * ThinkUp/webapp/plugins/flickrthumbnails/tests/TestOfFlickrAPIAccessor.php
  5. *
  6. * Copyright (c) 2009-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. * @author Gina Trapani <ginatrapani[at]gmail[dot]com>
  24. * @license http://www.gnu.org/licenses/gpl.html
  25. * @copyright 2009-2016 Gina Trapani
  26. */
  27. require_once dirname(__FILE__) . '/../../../../tests/init.tests.php';
  28. require_once THINKUP_WEBAPP_PATH.'_lib/extlib/simpletest/autorun.php';
  29. require_once THINKUP_WEBAPP_PATH.'_lib/extlib/simpletest/web_tester.php';
  30. require_once THINKUP_WEBAPP_PATH.'plugins/expandurls/tests/classes/mock.FlickrAPIAccessor.php';
  31. class TestOfFlickrAPIAccessor extends UnitTestCase {
  32. public function testGetFlickrPhotoSourceFlickrAPINonResponsive() {
  33. $logger = Logger::getInstance();
  34. $flickr_api = new FlickrAPIAccessor('dummykey', $logger);
  35. $photo_details = $flickr_api->getFlickrPhotoSource('http://flic.kr/p/6YS7AEasdfasdfasdfasdfasdf');
  36. //this file does not exist so response will be false
  37. $this->assertEqual($photo_details["image_src"], '');
  38. $this->assertEqual($photo_details["error"], 'No response from Flickr API');
  39. $logger->close();
  40. }
  41. public function testGetFlickrPhotoSourceNoFlickrAPIKey() {
  42. $logger = Logger::getInstance();
  43. $flickr_api = new FlickrAPIAccessor('', $logger);
  44. $photo_details = $flickr_api->getFlickrPhotoSource('http://flic.kr/p/6YS7AE');
  45. $this->assertEqual($photo_details["image_src"], '');
  46. $this->assertEqual($photo_details["error"], '');
  47. //logger will have logged that the API key was not set
  48. $logger->close();
  49. }
  50. public function testGetFlickrPhotoSourceFlickrAPIReturnsError() {
  51. $logger = Logger::getInstance();
  52. $flickr_api = new FlickrAPIAccessor('dummykey', $logger);
  53. $photo_details = $flickr_api->getFlickrPhotoSource('http://flic.kr/p/6YS7AE');
  54. $this->assertEqual($photo_details["image_src"], '');
  55. $this->assertEqual($photo_details["error"], 'Photo not found');
  56. $logger->close();
  57. }
  58. public function testGetFlickrPhotoSourceSuccess() {
  59. $logger = Logger::getInstance();
  60. $flickr_api = new FlickrAPIAccessor('dummykey', $logger);
  61. $this->assertTrue(isset($flickr_api));
  62. $photo_details = $flickr_api->getFlickrPhotoSource('http://flic.kr/p/7QAWC7');
  63. $this->assertEqual($photo_details["image_src"],
  64. 'http://farm3.static.flickr.com/2755/4488149974_04d9558212_m.jpg');
  65. $logger->close();
  66. }
  67. }