OnlineTest.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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_Ebay
  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: OnlineTest.php 22824 2010-08-09 18:59:54Z renanbr $
  21. */
  22. /**
  23. * @see Zend_Service_Ebay_Finding
  24. */
  25. require_once 'Zend/Service/Ebay/Finding.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Service_Ebay
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2015 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_Ebay_Finding_OnlineTest extends PHPUnit_Framework_TestCase
  34. {
  35. /**
  36. * @var Zend_Service_Ebay_Finding
  37. */
  38. protected $_finding;
  39. protected $_httpClientOriginal;
  40. protected function setUp()
  41. {
  42. $this->_finding = new Zend_Service_Ebay_Finding(constant('TESTS_ZEND_SERVICE_EBAY_ONLINE_APPID'));
  43. $this->_httpClientOriginal = Zend_Rest_Client::getHttpClient();
  44. Zend_Rest_Client::setHttpClient(new Zend_Http_Client());
  45. }
  46. public function tearDown()
  47. {
  48. Zend_Rest_Client::setHttpClient($this->_httpClientOriginal);
  49. }
  50. public function testInvalidAppId()
  51. {
  52. $this->_finding->setOption(Zend_Service_Ebay_Abstract::OPTION_APP_ID, 'foo');
  53. $appId = $this->_finding->getOption(Zend_Service_Ebay_Abstract::OPTION_APP_ID);
  54. $this->assertEquals('foo', $appId);
  55. try {
  56. $response = $this->_finding->findItemsByKeywords('harry+potter');
  57. $this->fail('No exception found');
  58. } catch (Exception $e) {
  59. $this->assertTrue($e instanceof Zend_Service_Ebay_Finding_Exception);
  60. $this->assertContains('eBay error', $e->getMessage());
  61. }
  62. }
  63. public function testResponseTypeFinds()
  64. {
  65. $services = array('findItemsAdvanced' => array('tolkien'),
  66. 'findItemsByCategory' => array('10181'),
  67. 'findItemsByKeywords' => array('harry+potter'),
  68. 'findItemsByProduct' => array('53039031'),
  69. 'findItemsInEbayStores' => array("Laura_Chen's_Small_Store"));
  70. $item = null;
  71. $category = null;
  72. $store = null;
  73. foreach ($services as $service => $params) {
  74. $response = call_user_func_array(array($this->_finding, $service), $params);
  75. $this->assertTrue($response instanceof Zend_Service_Ebay_Finding_Response_Items);
  76. if (!$item && $response->attributes('searchResult', 'count') > 0) {
  77. $item = $response->searchResult->item->current();
  78. }
  79. if (!$category && $response->attributes('searchResult', 'count') > 0) {
  80. foreach ($response->searchResult->item as $node) {
  81. if ($node->primaryCategory) {
  82. $category = $node->primaryCategory;
  83. }
  84. }
  85. }
  86. if (!$store && $response->attributes('searchResult', 'count') > 0) {
  87. foreach ($response->searchResult->item as $node) {
  88. if ($node->storeInfo) {
  89. $store = $node->storeInfo;
  90. }
  91. }
  92. }
  93. }
  94. $response2 = $item->findItemsByProduct($this->_finding);
  95. $this->assertTrue($response2 instanceof Zend_Service_Ebay_Finding_Response_Items);
  96. $response3 = $category->findItems($this->_finding, array());
  97. $this->assertTrue($response3 instanceof Zend_Service_Ebay_Finding_Response_Items);
  98. $response4 = $store->findItems($this->_finding, array());
  99. $this->assertTrue($response4 instanceof Zend_Service_Ebay_Finding_Response_Items);
  100. }
  101. public function testResponseTypeGets()
  102. {
  103. $response = $this->_finding->getSearchKeywordsRecommendation('hary');
  104. $this->assertTrue($response instanceof Zend_Service_Ebay_Finding_Response_Keywords);
  105. $response2 = $response->findItems($this->_finding, array());
  106. $this->assertTrue($response2 instanceof Zend_Service_Ebay_Finding_Response_Items);
  107. $response3 = $this->_finding->getHistograms('11233');
  108. $this->assertTrue($response3 instanceof Zend_Service_Ebay_Finding_Response_Histograms);
  109. }
  110. public function testItemsPagination()
  111. {
  112. // page 1
  113. // make sure this search will generate more than one page as result
  114. $page1 = $this->_finding->findItemsByKeywords('laptop');
  115. $this->assertEquals(1, $page1->paginationOutput->pageNumber);
  116. // out of range, page #0
  117. try {
  118. $page1->page($this->_finding, 0);
  119. $this->fail('No exception found for page #0');
  120. } catch (Exception $e) {
  121. $this->assertTrue($e instanceof Zend_Service_Ebay_Finding_Exception);
  122. $this->assertContains('Page number ', $e->getMessage());
  123. }
  124. // out of range, one page after last one
  125. try {
  126. $number = $page1->paginationOutput->totalPages + 1;
  127. $page1->page($this->_finding, $number);
  128. $this->fail("No exception found for page out of range #$number");
  129. } catch (Exception $e) {
  130. $this->assertTrue($e instanceof Zend_Service_Ebay_Finding_Exception);
  131. $this->assertContains('Page number ', $e->getMessage());
  132. }
  133. // page next
  134. $page2 = $page1->pageNext($this->_finding);
  135. $this->assertEquals(2, $page2->paginationOutput->pageNumber);
  136. // previous
  137. $previous = $page2->pagePrevious($this->_finding);
  138. $this->assertEquals(1, $previous->paginationOutput->pageNumber);
  139. $this->assertNull($page1->pagePrevious($this->_finding));
  140. // first
  141. $first = $page2->pageFirst($this->_finding);
  142. $this->assertEquals(1, $first->paginationOutput->pageNumber);
  143. // last
  144. $last = $page2->pageLast($this->_finding);
  145. $this->assertNotEquals(1, $last->paginationOutput->pageNumber);
  146. // page #2
  147. $some = $page1->page($this->_finding, 2);
  148. $this->assertEquals(2, $some->paginationOutput->pageNumber);
  149. }
  150. }
  151. /**
  152. * @category Zend
  153. * @package Zend_Service_Ebay
  154. * @subpackage UnitTests
  155. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  156. * @license http://framework.zend.com/license/new-bsd New BSD License
  157. * @group Zend_Service
  158. * @group Zend_Service_Ebay
  159. */
  160. class Zend_Service_Ebay_Finding_OnlineSkipTest extends PHPUnit_Framework_TestCase
  161. {
  162. public function setUp()
  163. {
  164. $this->markTestSkipped('Zend_Service_Ebay online tests not enabled with an APPID in TestConfiguration.php');
  165. }
  166. public function testNothing()
  167. {
  168. }
  169. }