OnlineTest.php 7.0 KB

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