OnlineTest.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_Flickr
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @category Zend
  24. * @package Zend_Service_Flickr
  25. * @subpackage UnitTests
  26. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  27. * @license http://framework.zend.com/license/new-bsd New BSD License
  28. * @group Zend_Service
  29. * @group Zend_Service_Flickr
  30. */
  31. class Zend_Service_Flickr_OnlineTest extends PHPUnit_Framework_TestCase
  32. {
  33. /**
  34. * Reference to Flickr service consumer object
  35. *
  36. * @var Zend_Service_Flickr
  37. */
  38. protected $_flickr;
  39. /**
  40. * Socket based HTTP client adapter
  41. *
  42. * @var Zend_Http_Client_Adapter_Socket
  43. */
  44. protected $_httpClientAdapterSocket;
  45. /**
  46. * Sets up this test case
  47. *
  48. * @return void
  49. */
  50. public function setUp()
  51. {
  52. /**
  53. * @see Zend_Service_Flickr
  54. */
  55. require_once 'Zend/Service/Flickr.php';
  56. $this->_flickr = new Zend_Service_Flickr(constant('TESTS_ZEND_SERVICE_FLICKR_ONLINE_APIKEY'));
  57. /**
  58. * @see Zend_Http_Client_Adapter_Socket
  59. */
  60. require_once 'Zend/Http/Client/Adapter/Socket.php';
  61. $this->_httpClientAdapterSocket = new Zend_Http_Client_Adapter_Socket();
  62. $this->_flickr->getRestClient()
  63. ->getHttpClient()
  64. ->setAdapter($this->_httpClientAdapterSocket);
  65. }
  66. /**
  67. * Basic testing to ensure that groupPoolGetPhotos works as expected
  68. *
  69. * @return void
  70. */
  71. public function testGroupPoolGetPhotosBasic()
  72. {
  73. $options = array('per_page' => 10,
  74. 'page' => 1,
  75. 'extras' => 'license, date_upload, date_taken, owner_name, icon_server');
  76. $resultSet = $this->_flickr->groupPoolGetPhotos('20083316@N00', $options);
  77. $this->assertGreaterThan(20000, $resultSet->totalResultsAvailable);
  78. $this->assertEquals(10, $resultSet->totalResults());
  79. $this->assertEquals(10, $resultSet->totalResultsReturned);
  80. $this->assertEquals(1, $resultSet->firstResultPosition);
  81. $this->assertEquals(0, $resultSet->key());
  82. try {
  83. $resultSet->seek(-1);
  84. $this->fail('Expected OutOfBoundsException not thrown');
  85. } catch (OutOfBoundsException $e) {
  86. $this->assertContains('Illegal index', $e->getMessage());
  87. }
  88. $resultSet->seek(9);
  89. try {
  90. $resultSet->seek(10);
  91. $this->fail('Expected OutOfBoundsException not thrown');
  92. } catch (OutOfBoundsException $e) {
  93. $this->assertContains('Illegal index', $e->getMessage());
  94. }
  95. $resultSet->rewind();
  96. $count = 0;
  97. foreach ($resultSet as $result) {
  98. $this->assertTrue($result instanceof Zend_Service_Flickr_Result);
  99. $count++;
  100. }
  101. $this->assertEquals(10, $count);
  102. }
  103. /**
  104. * Basic testing to ensure that userSearch() works as expected
  105. *
  106. * @return void
  107. */
  108. public function testUserSearchBasic()
  109. {
  110. $options = array('per_page' => 10,
  111. 'page' => 1,
  112. 'extras' => 'license, date_upload, date_taken, owner_name, icon_server');
  113. $resultSet = $this->_flickr->userSearch('darby.felton@yahoo.com', $options);
  114. $this->assertEquals(16, $resultSet->totalResultsAvailable);
  115. $this->assertEquals(10, $resultSet->totalResults());
  116. $this->assertEquals(10, $resultSet->totalResultsReturned);
  117. $this->assertEquals(1, $resultSet->firstResultPosition);
  118. $this->assertEquals(0, $resultSet->key());
  119. try {
  120. $resultSet->seek(-1);
  121. $this->fail('Expected OutOfBoundsException not thrown');
  122. } catch (OutOfBoundsException $e) {
  123. $this->assertContains('Illegal index', $e->getMessage());
  124. }
  125. $resultSet->seek(9);
  126. try {
  127. $resultSet->seek(10);
  128. $this->fail('Expected OutOfBoundsException not thrown');
  129. } catch (OutOfBoundsException $e) {
  130. $this->assertContains('Illegal index', $e->getMessage());
  131. }
  132. $resultSet->rewind();
  133. $count = 0;
  134. foreach ($resultSet as $result) {
  135. $this->assertTrue($result instanceof Zend_Service_Flickr_Result);
  136. $count++;
  137. }
  138. $this->assertEquals(10, $count);
  139. }
  140. /**
  141. * Basic testing to ensure that getIdByUsername() works as expected
  142. *
  143. * @return void
  144. */
  145. public function testGetIdByUsernameBasic()
  146. {
  147. $userId = $this->_flickr->getIdByUsername('darby.felton');
  148. $this->assertEquals('7414329@N07', $userId);
  149. }
  150. /**
  151. * Ensures that tagSearch() works as expected with the sort option
  152. *
  153. * @return void
  154. */
  155. public function testTagSearchOptionSort()
  156. {
  157. $options = array(
  158. 'per_page' => 10,
  159. 'page' => 1,
  160. 'tag_mode' => 'or',
  161. 'sort' => 'date-taken-asc',
  162. 'extras' => 'license, date_upload, date_taken, owner_name, icon_server'
  163. );
  164. $resultSet = $this->_flickr->tagSearch('php', $options);
  165. $this->assertTrue(10 < $resultSet->totalResultsAvailable);
  166. $this->assertEquals(10, $resultSet->totalResults());
  167. $this->assertEquals(10, $resultSet->totalResultsReturned);
  168. $this->assertEquals(1, $resultSet->firstResultPosition);
  169. foreach ($resultSet as $result) {
  170. $this->assertTrue($result instanceof Zend_Service_Flickr_Result);
  171. if (isset($dateTakenPrevious)) {
  172. $this->assertTrue(strcmp($result->datetaken, $dateTakenPrevious) > 0);
  173. }
  174. $dateTakenPrevious = $result->datetaken;
  175. }
  176. }
  177. /**
  178. * @see ZF-6397
  179. */
  180. function testTotalForEmptyResultSet()
  181. {
  182. $this->assertEquals(0, $this->_flickr->tagSearch('zendflickrtesttagnoresults')->totalResults());
  183. }
  184. }
  185. /**
  186. * @category Zend
  187. * @package Zend_Service_Flickr
  188. * @subpackage UnitTests
  189. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  190. * @license http://framework.zend.com/license/new-bsd New BSD License
  191. * @group Zend_Service
  192. * @group Zend_Service_Flickr
  193. */
  194. class Zend_Service_Flickr_OnlineTest_Skip extends PHPUnit_Framework_TestCase
  195. {
  196. public function testNothing()
  197. {
  198. $this->markTestSkipped('Zend_Service_Flickr online tests not enabled in TestConfiguration.php');
  199. }
  200. }