OnlineTest.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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-2008 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. * Test helper
  24. */
  25. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Service_Flickr
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Service_Flickr_OnlineTest extends PHPUnit_Framework_TestCase
  34. {
  35. /**
  36. * Reference to Flickr service consumer object
  37. *
  38. * @var Zend_Service_Flickr
  39. */
  40. protected $_flickr;
  41. /**
  42. * Socket based HTTP client adapter
  43. *
  44. * @var Zend_Http_Client_Adapter_Socket
  45. */
  46. protected $_httpClientAdapterSocket;
  47. /**
  48. * Sets up this test case
  49. *
  50. * @return void
  51. */
  52. public function setUp()
  53. {
  54. /**
  55. * @see Zend_Service_Flickr
  56. */
  57. require_once 'Zend/Service/Flickr.php';
  58. $this->_flickr = new Zend_Service_Flickr(constant('TESTS_ZEND_SERVICE_FLICKR_ONLINE_APIKEY'));
  59. /**
  60. * @see Zend_Http_Client_Adapter_Socket
  61. */
  62. require_once 'Zend/Http/Client/Adapter/Socket.php';
  63. $this->_httpClientAdapterSocket = new Zend_Http_Client_Adapter_Socket();
  64. $this->_flickr->getRestClient()
  65. ->getHttpClient()
  66. ->setAdapter($this->_httpClientAdapterSocket);
  67. }
  68. /**
  69. * Basic testing to ensure that groupPoolGetPhotos works as expected
  70. *
  71. * @return void
  72. */
  73. public function testGroupPoolGetPhotosBasic()
  74. {
  75. $options = array('per_page' => 10,
  76. 'page' => 1,
  77. 'extras' => 'license, date_upload, date_taken, owner_name, icon_server');
  78. $resultSet = $this->_flickr->groupPoolGetPhotos('20083316@N00', $options);
  79. $this->assertEquals(21770, $resultSet->totalResultsAvailable);
  80. $this->assertEquals(10, $resultSet->totalResults());
  81. $this->assertEquals(10, $resultSet->totalResultsReturned);
  82. $this->assertEquals(1, $resultSet->firstResultPosition);
  83. $this->assertEquals(0, $resultSet->key());
  84. try {
  85. $resultSet->seek(-1);
  86. $this->fail('Expected OutOfBoundsException not thrown');
  87. } catch (OutOfBoundsException $e) {
  88. $this->assertContains('Illegal index', $e->getMessage());
  89. }
  90. $resultSet->seek(9);
  91. try {
  92. $resultSet->seek(10);
  93. $this->fail('Expected OutOfBoundsException not thrown');
  94. } catch (OutOfBoundsException $e) {
  95. $this->assertContains('Illegal index', $e->getMessage());
  96. }
  97. $resultSet->rewind();
  98. $count = 0;
  99. foreach ($resultSet as $result) {
  100. $this->assertTrue($result instanceof Zend_Service_Flickr_Result);
  101. $count++;
  102. }
  103. $this->assertEquals(10, $count);
  104. }
  105. /**
  106. * Basic testing to ensure that userSearch() works as expected
  107. *
  108. * @return void
  109. */
  110. public function testUserSearchBasic()
  111. {
  112. $options = array('per_page' => 10,
  113. 'page' => 1,
  114. 'extras' => 'license, date_upload, date_taken, owner_name, icon_server');
  115. $resultSet = $this->_flickr->userSearch('darby.felton@yahoo.com', $options);
  116. $this->assertEquals(16, $resultSet->totalResultsAvailable);
  117. $this->assertEquals(10, $resultSet->totalResults());
  118. $this->assertEquals(10, $resultSet->totalResultsReturned);
  119. $this->assertEquals(1, $resultSet->firstResultPosition);
  120. $this->assertEquals(0, $resultSet->key());
  121. try {
  122. $resultSet->seek(-1);
  123. $this->fail('Expected OutOfBoundsException not thrown');
  124. } catch (OutOfBoundsException $e) {
  125. $this->assertContains('Illegal index', $e->getMessage());
  126. }
  127. $resultSet->seek(9);
  128. try {
  129. $resultSet->seek(10);
  130. $this->fail('Expected OutOfBoundsException not thrown');
  131. } catch (OutOfBoundsException $e) {
  132. $this->assertContains('Illegal index', $e->getMessage());
  133. }
  134. $resultSet->rewind();
  135. $count = 0;
  136. foreach ($resultSet as $result) {
  137. $this->assertTrue($result instanceof Zend_Service_Flickr_Result);
  138. $count++;
  139. }
  140. $this->assertEquals(10, $count);
  141. }
  142. /**
  143. * Basic testing to ensure that getIdByUsername() works as expected
  144. *
  145. * @return void
  146. */
  147. public function testGetIdByUsernameBasic()
  148. {
  149. $userId = $this->_flickr->getIdByUsername('darby.felton');
  150. $this->assertEquals('7414329@N07', $userId);
  151. }
  152. /**
  153. * Ensures that tagSearch() works as expected with the sort option
  154. *
  155. * @return void
  156. */
  157. public function testTagSearchOptionSort()
  158. {
  159. $options = array(
  160. 'per_page' => 10,
  161. 'page' => 1,
  162. 'tag_mode' => 'or',
  163. 'sort' => 'date-taken-asc',
  164. 'extras' => 'license, date_upload, date_taken, owner_name, icon_server'
  165. );
  166. $resultSet = $this->_flickr->tagSearch('php', $options);
  167. $this->assertTrue(10 < $resultSet->totalResultsAvailable);
  168. $this->assertEquals(10, $resultSet->totalResults());
  169. $this->assertEquals(10, $resultSet->totalResultsReturned);
  170. $this->assertEquals(1, $resultSet->firstResultPosition);
  171. foreach ($resultSet as $result) {
  172. $this->assertTrue($result instanceof Zend_Service_Flickr_Result);
  173. if (isset($dateTakenPrevious)) {
  174. $this->assertTrue(strcmp($result->datetaken, $dateTakenPrevious) > 0);
  175. }
  176. $dateTakenPrevious = $result->datetaken;
  177. }
  178. }
  179. }
  180. class Zend_Service_Flickr_OnlineTest_Skip extends PHPUnit_Framework_TestCase
  181. {
  182. public function testNothing()
  183. {
  184. $this->markTestSkipped('Zend_Service_Flickr online tests not enabled in TestConfiguration.php');
  185. }
  186. }