OnlineTest.php 7.2 KB

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