OnlineTest.php 7.0 KB

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