OfflineTest.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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: OfflineTest.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. * @see Zend_Service_Ebay_Finding_Response_Keywords
  28. */
  29. require_once 'Zend/Service/Ebay/Finding/Response/Keywords.php';
  30. /**
  31. * @see Zend_Service_Ebay_Finding_Response_Items
  32. */
  33. require_once 'Zend/Service/Ebay/Finding/Response/Items.php';
  34. /**
  35. * @category Zend
  36. * @package Zend_Service_Ebay
  37. * @subpackage UnitTests
  38. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. */
  41. class Zend_Service_Ebay_OfflineTest extends PHPUnit_Framework_TestCase
  42. {
  43. /**
  44. * @var Zend_Service_Ebay_Finding
  45. */
  46. protected $_finding;
  47. protected function setUp()
  48. {
  49. $this->_finding = new Zend_Service_Ebay_Finding('foo');
  50. }
  51. public function testClient()
  52. {
  53. $this->assertTrue($this->_finding->getClient() instanceof Zend_Rest_Client);
  54. require_once dirname(__FILE__) . '/_files/ClientCustom.php';
  55. $this->assertTrue($this->_finding->setClient(new ClientCustom()) instanceof Zend_Service_Ebay_Finding);
  56. $this->assertTrue($this->_finding->getClient() instanceof ClientCustom);
  57. $this->setExpectedException('Zend_Service_Ebay_Finding_Exception');
  58. $this->_finding->setClient(new stdClass());
  59. }
  60. public function testConstructor()
  61. {
  62. $this->assertEquals('EBAY-US', $this->_finding->getOption(Zend_Service_Ebay_Finding::OPTION_GLOBAL_ID));
  63. $this->assertEquals('foo', $this->_finding->getOption(Zend_Service_Ebay_Finding::OPTION_APP_ID));
  64. $options = array(
  65. Zend_Service_Ebay_Finding::OPTION_APP_ID => 'app-id',
  66. Zend_Service_Ebay_Finding::OPTION_GLOBAL_ID => 'EBAY-GB',
  67. 'foo' => 'bar'
  68. );
  69. $finding = new Zend_Service_Ebay_Finding($options);
  70. $this->assertEquals('EBAY-GB', $finding->getOption(Zend_Service_Ebay_Finding::OPTION_GLOBAL_ID));
  71. $this->assertEquals('app-id', $finding->getOption(Zend_Service_Ebay_Finding::OPTION_APP_ID));
  72. $this->assertEquals('bar', $finding->getOption('foo'));
  73. $this->setExpectedException('Zend_Service_Ebay_Finding_Exception');
  74. $finding = new Zend_Service_Ebay_Finding(array('foo' => 'bar'));
  75. }
  76. public function testResponseAbstract()
  77. {
  78. $xml = file_get_contents(dirname(__FILE__) . '/_files/get-search-keywords-recomendation.xml');
  79. // no error xml
  80. $response = $this->_createResponseKeywords($xml);
  81. $this->assertNotNull($response->ack);
  82. $this->assertNotNull($response->timestamp);
  83. $this->assertNotNull($response->version);
  84. }
  85. public function testErrorMessage()
  86. {
  87. $xml = file_get_contents(dirname(__FILE__) . '/_files/error.xml');
  88. // xml with error inside
  89. $response = $this->_createResponseKeywords($xml);
  90. $this->assertNotNull($response->ack);
  91. $this->assertNotNull($response->timestamp);
  92. $this->assertNotNull($response->version);
  93. $this->assertTrue($response->errorMessage instanceof Zend_Service_Ebay_Finding_Error_Message);
  94. // Zend_Service_Ebay_Finding_Error_Message
  95. $object = $response->errorMessage;
  96. $this->assertTrue($object->error instanceof Zend_Service_Ebay_Finding_Error_Data_Set);
  97. // Zend_Service_Ebay_Finding_Error_Data
  98. $object = $object->error->current();
  99. $this->assertNotNull($object->category);
  100. $this->assertNotNull($object->domain);
  101. $this->assertNotNull($object->errorId);
  102. $this->assertNotNull($object->message);
  103. $this->assertTrue(is_array($object->parameter));
  104. $this->assertTrue(is_array($object->attributes('parameter', 'name')));
  105. $this->assertNotNull($object->severity);
  106. $this->assertNotNull($object->subdomain);
  107. // missing attributes in XML
  108. //$this->assertNotNull($object->exceptionId);
  109. }
  110. public function testResponseKeywords()
  111. {
  112. $xml = file_get_contents(dirname(__FILE__) . '/_files/get-search-keywords-recomendation.xml');
  113. $response = $this->_createResponseKeywords($xml);
  114. $this->assertNotNull($response->keywords);
  115. }
  116. public function testResponseItems()
  117. {
  118. $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
  119. $response = $this->_createResponseItems($xml);
  120. $this->assertTrue($response->paginationOutput instanceof Zend_Service_Ebay_Finding_PaginationOutput);
  121. $this->assertTrue($response->searchResult instanceof Zend_Service_Ebay_Finding_Search_Result);
  122. $this->assertNotNull($response->attributes('searchResult', 'count'));
  123. }
  124. public function testPaginationOutput()
  125. {
  126. $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
  127. $response = $this->_createResponseItems($xml);
  128. $object = $response->paginationOutput;
  129. $this->assertNotNull($object->entriesPerPage);
  130. $this->assertNotNull($object->pageNumber);
  131. $this->assertNotNull($object->totalEntries);
  132. $this->assertNotNull($object->totalPages);
  133. }
  134. public function testSearchResult()
  135. {
  136. $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
  137. $response = $this->_createResponseItems($xml);
  138. $object = $response->searchResult;
  139. $this->assertTrue($object->item instanceof Zend_Service_Ebay_Finding_Search_Item_Set);
  140. }
  141. public function testSearchItem()
  142. {
  143. $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
  144. $response = $this->_createResponseItems($xml);
  145. // general attributes
  146. $response->searchResult->item->seek(0);
  147. $object = $response->searchResult->item->current();
  148. $this->assertTrue($object instanceof Zend_Service_Ebay_Finding_Search_Item);
  149. $this->assertNotNull($object->autoPay);
  150. $this->assertNotNull($object->country);
  151. $this->assertTrue(is_array($object->galleryPlusPictureURL));
  152. $this->assertNotNull($object->galleryPlusPictureURL[0]);
  153. $this->assertNotNull($object->galleryURL);
  154. $this->assertNotNull($object->globalId);
  155. $this->assertNotNull($object->itemId);
  156. $this->assertTrue($object->listingInfo instanceof Zend_Service_Ebay_Finding_ListingInfo);
  157. $this->assertNotNull($object->location);
  158. $this->assertTrue(is_array($object->paymentMethod));
  159. $this->assertNotNull($object->paymentMethod[0]);
  160. $this->assertNotNull($object->postalCode);
  161. $this->assertTrue($object->primaryCategory instanceof Zend_Service_Ebay_Finding_Category);
  162. $this->assertTrue($object->sellerInfo instanceof Zend_Service_Ebay_Finding_SellerInfo);
  163. $this->assertTrue($object->sellingStatus instanceof Zend_Service_Ebay_Finding_SellingStatus);
  164. $this->assertTrue($object->shippingInfo instanceof Zend_Service_Ebay_Finding_ShippingInfo);
  165. $this->assertTrue($object->storeInfo instanceof Zend_Service_Ebay_Finding_Storefront);
  166. $this->assertNotNull($object->title);
  167. $this->assertNotNull($object->viewItemURL);
  168. // product id
  169. $response->searchResult->item->seek(3);
  170. $object = $response->searchResult->item->current();
  171. $this->assertNotNull($object->productId);
  172. $this->assertNotNull($object->attributes('productId', 'type'));
  173. // sub category
  174. $response->searchResult->item->seek(2);
  175. $object = $response->searchResult->item->current();
  176. $this->assertTrue($object->secondaryCategory instanceof Zend_Service_Ebay_Finding_Category);
  177. // missing attributes in XML
  178. //$this->assertNotNull($object->charityId);
  179. //$this->assertNotNull($object->distance);
  180. //$this->assertNotNull($object->attributes('distance', 'unit'));
  181. }
  182. public function testListingInfo()
  183. {
  184. $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
  185. $response = $this->_createResponseItems($xml);
  186. $response->searchResult->item->seek(4);
  187. $object = $response->searchResult->item->current()->listingInfo;
  188. $this->assertNotNull($object->bestOfferEnabled);
  189. $this->assertNotNull($object->buyItNowAvailable);
  190. $this->assertNotNull($object->buyItNowPrice);
  191. $this->assertNotNull($object->attributes('buyItNowPrice', 'currencyId'));
  192. $this->assertNotNull($object->convertedBuyItNowPrice);
  193. $this->assertNotNull($object->attributes('convertedBuyItNowPrice', 'currencyId'));
  194. $this->assertNotNull($object->endTime);
  195. $this->assertNotNull($object->gift);
  196. $this->assertNotNull($object->listingType);
  197. $this->assertNotNull($object->startTime);
  198. }
  199. public function testCategory()
  200. {
  201. $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
  202. $response = $this->_createResponseItems($xml);
  203. $response->searchResult->item->seek(0);
  204. $object = $response->searchResult->item->current()->primaryCategory;
  205. $this->assertNotNull($object->categoryId);
  206. $this->assertNotNull($object->categoryName);
  207. }
  208. public function testSellerInfo()
  209. {
  210. $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
  211. $response = $this->_createResponseItems($xml);
  212. $response->searchResult->item->seek(0);
  213. $object = $response->searchResult->item->current()->sellerInfo;
  214. $this->assertNotNull($object->feedbackRatingStar);
  215. $this->assertNotNull($object->feedbackScore);
  216. $this->assertNotNull($object->positiveFeedbackPercent);
  217. $this->assertNotNull($object->sellerUserName);
  218. $this->assertNotNull($object->topRatedSeller);
  219. }
  220. public function testSellingStatus()
  221. {
  222. $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
  223. $response = $this->_createResponseItems($xml);
  224. $response->searchResult->item->seek(1);
  225. $object = $response->searchResult->item->current()->sellingStatus;
  226. $this->assertNotNull($object->bidCount);
  227. $this->assertNotNull($object->convertedCurrentPrice);
  228. $this->assertNotNull($object->attributes('convertedCurrentPrice', 'currencyId'));
  229. $this->assertNotNull($object->currentPrice);
  230. $this->assertNotNull($object->attributes('currentPrice', 'currencyId'));
  231. $this->assertNotNull($object->sellingState);
  232. $this->assertNotNull($object->timeLeft);
  233. }
  234. public function testShippingInfo()
  235. {
  236. $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
  237. $response = $this->_createResponseItems($xml);
  238. $response->searchResult->item->seek(0);
  239. $object = $response->searchResult->item->current()->shippingInfo;
  240. $this->assertNotNull($object->shippingServiceCost);
  241. $this->assertNotNull($object->attributes('shippingServiceCost', 'currencyId'));
  242. $this->assertNotNull($object->shippingType);
  243. $this->assertTrue(is_array($object->shipToLocations));
  244. $this->assertNotNull($object->shipToLocations[0]);
  245. }
  246. public function testStorefront()
  247. {
  248. $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
  249. $response = $this->_createResponseItems($xml);
  250. $response->searchResult->item->seek(0);
  251. $object = $response->searchResult->item->current()->storeInfo;
  252. $this->assertNotNull($object->storeName);
  253. $this->assertNotNull($object->storeURL);
  254. }
  255. public function testResponseHistogramAspect()
  256. {
  257. // test histogram aspect
  258. $xml = file_get_contents(dirname(__FILE__) . '/_files/histogram-aspect.xml');
  259. $response = $this->_createResponseHistograms($xml);
  260. $this->assertNotNull($response->aspectHistogramContainer);
  261. $this->assertTrue($response->aspectHistogramContainer instanceof Zend_Service_Ebay_Finding_Aspect_Histogram_Container);
  262. $this->assertNull($response->categoryHistogramContainer);
  263. // Zend_Service_Ebay_Finding_Aspect_Set
  264. $object = $response->aspectHistogramContainer;
  265. $this->assertTrue($object->aspect instanceof Zend_Service_Ebay_Finding_Aspect_Set);
  266. // Zend_Service_Ebay_Finding_Aspect
  267. $object = $object->aspect->current();
  268. $this->assertTrue($object->valueHistogram instanceof Zend_Service_Ebay_Finding_Aspect_Histogram_Value_Set);
  269. $this->assertTrue(is_array($object->attributes('valueHistogram', 'valueName')));
  270. // Zend_Service_Ebay_Finding_Aspect_Histogram_Value
  271. $object = $object->valueHistogram->current();
  272. $this->assertNotNull($object->count);
  273. }
  274. public function testResponseHistogramCategory()
  275. {
  276. // test histogram aspect
  277. $xml = file_get_contents(dirname(__FILE__) . '/_files/histogram-category.xml');
  278. $response = $this->_createResponseHistograms($xml);
  279. $this->assertNotNull($response->categoryHistogramContainer);
  280. $this->assertTrue($response->categoryHistogramContainer instanceof Zend_Service_Ebay_Finding_Category_Histogram_Container);
  281. $this->assertNull($response->aspectHistogramContainer);
  282. // Zend_Service_Ebay_Finding_Category_Histogram_Container
  283. $object = $response->categoryHistogramContainer;
  284. $this->assertTrue($object->categoryHistogram instanceof Zend_Service_Ebay_Finding_Category_Histogram_Set);
  285. // Zend_Service_Ebay_Finding_Category_Histogram
  286. $object = $object->categoryHistogram->current();
  287. $this->assertTrue($object instanceof Zend_Service_Ebay_Finding_Category_Histogram);
  288. $this->assertTrue($object->childCategoryHistogram instanceof Zend_Service_Ebay_Finding_Category_Histogram_Set);
  289. $this->assertNotNull($object->count);
  290. }
  291. protected function _readXML($xml)
  292. {
  293. $dom = new DOMDocument();
  294. $dom->loadXML($xml);
  295. return $dom;
  296. }
  297. protected function _createResponseItems($xml)
  298. {
  299. return new Zend_Service_Ebay_Finding_Response_Items($this->_readXML($xml)->firstChild);
  300. }
  301. protected function _createResponseHistograms($xml)
  302. {
  303. return new Zend_Service_Ebay_Finding_Response_Histograms($this->_readXML($xml)->firstChild);
  304. }
  305. protected function _createResponseKeywords($xml)
  306. {
  307. return new Zend_Service_Ebay_Finding_Response_Keywords($this->_readXML($xml)->firstChild);
  308. }
  309. }