| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Service_Ebay
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id: OfflineTest.php 22824 2010-08-09 18:59:54Z renanbr $
- */
- /**
- * @see Zend_Service_Ebay_Finding
- */
- require_once 'Zend/Service/Ebay/Finding.php';
- /**
- * @see Zend_Service_Ebay_Finding_Response_Keywords
- */
- require_once 'Zend/Service/Ebay/Finding/Response/Keywords.php';
- /**
- * @see Zend_Service_Ebay_Finding_Response_Items
- */
- require_once 'Zend/Service/Ebay/Finding/Response/Items.php';
- /**
- * @category Zend
- * @package Zend_Service_Ebay
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- class Zend_Service_Ebay_OfflineTest extends PHPUnit_Framework_TestCase
- {
- /**
- * @var Zend_Service_Ebay_Finding
- */
- protected $_finding;
- protected function setUp()
- {
- $this->_finding = new Zend_Service_Ebay_Finding('foo');
- }
- public function testClient()
- {
- $this->assertTrue($this->_finding->getClient() instanceof Zend_Rest_Client);
- require_once dirname(__FILE__) . '/_files/ClientCustom.php';
- $this->assertTrue($this->_finding->setClient(new ClientCustom()) instanceof Zend_Service_Ebay_Finding);
- $this->assertTrue($this->_finding->getClient() instanceof ClientCustom);
- $this->setExpectedException('Zend_Service_Ebay_Finding_Exception');
- $this->_finding->setClient(new stdClass());
- }
- public function testConstructor()
- {
- $this->assertEquals('EBAY-US', $this->_finding->getOption(Zend_Service_Ebay_Finding::OPTION_GLOBAL_ID));
- $this->assertEquals('foo', $this->_finding->getOption(Zend_Service_Ebay_Finding::OPTION_APP_ID));
- $options = array(
- Zend_Service_Ebay_Finding::OPTION_APP_ID => 'app-id',
- Zend_Service_Ebay_Finding::OPTION_GLOBAL_ID => 'EBAY-GB',
- 'foo' => 'bar'
- );
- $finding = new Zend_Service_Ebay_Finding($options);
- $this->assertEquals('EBAY-GB', $finding->getOption(Zend_Service_Ebay_Finding::OPTION_GLOBAL_ID));
- $this->assertEquals('app-id', $finding->getOption(Zend_Service_Ebay_Finding::OPTION_APP_ID));
- $this->assertEquals('bar', $finding->getOption('foo'));
- $this->setExpectedException('Zend_Service_Ebay_Finding_Exception');
- $finding = new Zend_Service_Ebay_Finding(array('foo' => 'bar'));
- }
- public function testResponseAbstract()
- {
- $xml = file_get_contents(dirname(__FILE__) . '/_files/get-search-keywords-recomendation.xml');
- // no error xml
- $response = $this->_createResponseKeywords($xml);
- $this->assertNotNull($response->ack);
- $this->assertNotNull($response->timestamp);
- $this->assertNotNull($response->version);
- }
- public function testErrorMessage()
- {
- $xml = file_get_contents(dirname(__FILE__) . '/_files/error.xml');
- // xml with error inside
- $response = $this->_createResponseKeywords($xml);
- $this->assertNotNull($response->ack);
- $this->assertNotNull($response->timestamp);
- $this->assertNotNull($response->version);
- $this->assertTrue($response->errorMessage instanceof Zend_Service_Ebay_Finding_Error_Message);
- // Zend_Service_Ebay_Finding_Error_Message
- $object = $response->errorMessage;
- $this->assertTrue($object->error instanceof Zend_Service_Ebay_Finding_Error_Data_Set);
- // Zend_Service_Ebay_Finding_Error_Data
- $object = $object->error->current();
- $this->assertNotNull($object->category);
- $this->assertNotNull($object->domain);
- $this->assertNotNull($object->errorId);
- $this->assertNotNull($object->message);
- $this->assertTrue(is_array($object->parameter));
- $this->assertTrue(is_array($object->attributes('parameter', 'name')));
- $this->assertNotNull($object->severity);
- $this->assertNotNull($object->subdomain);
- // missing attributes in XML
- //$this->assertNotNull($object->exceptionId);
- }
- public function testResponseKeywords()
- {
- $xml = file_get_contents(dirname(__FILE__) . '/_files/get-search-keywords-recomendation.xml');
- $response = $this->_createResponseKeywords($xml);
- $this->assertNotNull($response->keywords);
- }
- public function testResponseItems()
- {
- $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
- $response = $this->_createResponseItems($xml);
- $this->assertTrue($response->paginationOutput instanceof Zend_Service_Ebay_Finding_PaginationOutput);
- $this->assertTrue($response->searchResult instanceof Zend_Service_Ebay_Finding_Search_Result);
- $this->assertNotNull($response->attributes('searchResult', 'count'));
- }
- public function testPaginationOutput()
- {
- $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
- $response = $this->_createResponseItems($xml);
- $object = $response->paginationOutput;
- $this->assertNotNull($object->entriesPerPage);
- $this->assertNotNull($object->pageNumber);
- $this->assertNotNull($object->totalEntries);
- $this->assertNotNull($object->totalPages);
- }
- public function testSearchResult()
- {
- $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
- $response = $this->_createResponseItems($xml);
- $object = $response->searchResult;
- $this->assertTrue($object->item instanceof Zend_Service_Ebay_Finding_Search_Item_Set);
- }
- public function testSearchItem()
- {
- $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
- $response = $this->_createResponseItems($xml);
- // general attributes
- $response->searchResult->item->seek(0);
- $object = $response->searchResult->item->current();
- $this->assertTrue($object instanceof Zend_Service_Ebay_Finding_Search_Item);
- $this->assertNotNull($object->autoPay);
- $this->assertNotNull($object->country);
- $this->assertTrue(is_array($object->galleryPlusPictureURL));
- $this->assertNotNull($object->galleryPlusPictureURL[0]);
- $this->assertNotNull($object->galleryURL);
- $this->assertNotNull($object->globalId);
- $this->assertNotNull($object->itemId);
- $this->assertTrue($object->listingInfo instanceof Zend_Service_Ebay_Finding_ListingInfo);
- $this->assertNotNull($object->location);
- $this->assertTrue(is_array($object->paymentMethod));
- $this->assertNotNull($object->paymentMethod[0]);
- $this->assertNotNull($object->postalCode);
- $this->assertTrue($object->primaryCategory instanceof Zend_Service_Ebay_Finding_Category);
- $this->assertTrue($object->sellerInfo instanceof Zend_Service_Ebay_Finding_SellerInfo);
- $this->assertTrue($object->sellingStatus instanceof Zend_Service_Ebay_Finding_SellingStatus);
- $this->assertTrue($object->shippingInfo instanceof Zend_Service_Ebay_Finding_ShippingInfo);
- $this->assertTrue($object->storeInfo instanceof Zend_Service_Ebay_Finding_Storefront);
- $this->assertNotNull($object->title);
- $this->assertNotNull($object->viewItemURL);
- // product id
- $response->searchResult->item->seek(3);
- $object = $response->searchResult->item->current();
- $this->assertNotNull($object->productId);
- $this->assertNotNull($object->attributes('productId', 'type'));
- // sub category
- $response->searchResult->item->seek(2);
- $object = $response->searchResult->item->current();
- $this->assertTrue($object->secondaryCategory instanceof Zend_Service_Ebay_Finding_Category);
- // missing attributes in XML
- //$this->assertNotNull($object->charityId);
- //$this->assertNotNull($object->distance);
- //$this->assertNotNull($object->attributes('distance', 'unit'));
- }
- public function testListingInfo()
- {
- $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
- $response = $this->_createResponseItems($xml);
- $response->searchResult->item->seek(4);
- $object = $response->searchResult->item->current()->listingInfo;
- $this->assertNotNull($object->bestOfferEnabled);
- $this->assertNotNull($object->buyItNowAvailable);
- $this->assertNotNull($object->buyItNowPrice);
- $this->assertNotNull($object->attributes('buyItNowPrice', 'currencyId'));
- $this->assertNotNull($object->convertedBuyItNowPrice);
- $this->assertNotNull($object->attributes('convertedBuyItNowPrice', 'currencyId'));
- $this->assertNotNull($object->endTime);
- $this->assertNotNull($object->gift);
- $this->assertNotNull($object->listingType);
- $this->assertNotNull($object->startTime);
- }
- public function testCategory()
- {
- $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
- $response = $this->_createResponseItems($xml);
- $response->searchResult->item->seek(0);
- $object = $response->searchResult->item->current()->primaryCategory;
- $this->assertNotNull($object->categoryId);
- $this->assertNotNull($object->categoryName);
- }
- public function testSellerInfo()
- {
- $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
- $response = $this->_createResponseItems($xml);
- $response->searchResult->item->seek(0);
- $object = $response->searchResult->item->current()->sellerInfo;
- $this->assertNotNull($object->feedbackRatingStar);
- $this->assertNotNull($object->feedbackScore);
- $this->assertNotNull($object->positiveFeedbackPercent);
- $this->assertNotNull($object->sellerUserName);
- $this->assertNotNull($object->topRatedSeller);
- }
- public function testSellingStatus()
- {
- $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
- $response = $this->_createResponseItems($xml);
- $response->searchResult->item->seek(1);
- $object = $response->searchResult->item->current()->sellingStatus;
- $this->assertNotNull($object->bidCount);
- $this->assertNotNull($object->convertedCurrentPrice);
- $this->assertNotNull($object->attributes('convertedCurrentPrice', 'currencyId'));
- $this->assertNotNull($object->currentPrice);
- $this->assertNotNull($object->attributes('currentPrice', 'currencyId'));
- $this->assertNotNull($object->sellingState);
- $this->assertNotNull($object->timeLeft);
- }
- public function testShippingInfo()
- {
- $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
- $response = $this->_createResponseItems($xml);
- $response->searchResult->item->seek(0);
- $object = $response->searchResult->item->current()->shippingInfo;
- $this->assertNotNull($object->shippingServiceCost);
- $this->assertNotNull($object->attributes('shippingServiceCost', 'currencyId'));
- $this->assertNotNull($object->shippingType);
- $this->assertTrue(is_array($object->shipToLocations));
- $this->assertNotNull($object->shipToLocations[0]);
- }
- public function testStorefront()
- {
- $xml = file_get_contents(dirname(__FILE__) . '/_files/find-items-advanced.xml');
- $response = $this->_createResponseItems($xml);
- $response->searchResult->item->seek(0);
- $object = $response->searchResult->item->current()->storeInfo;
- $this->assertNotNull($object->storeName);
- $this->assertNotNull($object->storeURL);
- }
- public function testResponseHistogramAspect()
- {
- // test histogram aspect
- $xml = file_get_contents(dirname(__FILE__) . '/_files/histogram-aspect.xml');
- $response = $this->_createResponseHistograms($xml);
- $this->assertNotNull($response->aspectHistogramContainer);
- $this->assertTrue($response->aspectHistogramContainer instanceof Zend_Service_Ebay_Finding_Aspect_Histogram_Container);
- $this->assertNull($response->categoryHistogramContainer);
- // Zend_Service_Ebay_Finding_Aspect_Set
- $object = $response->aspectHistogramContainer;
- $this->assertTrue($object->aspect instanceof Zend_Service_Ebay_Finding_Aspect_Set);
- // Zend_Service_Ebay_Finding_Aspect
- $object = $object->aspect->current();
- $this->assertTrue($object->valueHistogram instanceof Zend_Service_Ebay_Finding_Aspect_Histogram_Value_Set);
- $this->assertTrue(is_array($object->attributes('valueHistogram', 'valueName')));
- // Zend_Service_Ebay_Finding_Aspect_Histogram_Value
- $object = $object->valueHistogram->current();
- $this->assertNotNull($object->count);
- }
- public function testResponseHistogramCategory()
- {
- // test histogram aspect
- $xml = file_get_contents(dirname(__FILE__) . '/_files/histogram-category.xml');
- $response = $this->_createResponseHistograms($xml);
- $this->assertNotNull($response->categoryHistogramContainer);
- $this->assertTrue($response->categoryHistogramContainer instanceof Zend_Service_Ebay_Finding_Category_Histogram_Container);
- $this->assertNull($response->aspectHistogramContainer);
- // Zend_Service_Ebay_Finding_Category_Histogram_Container
- $object = $response->categoryHistogramContainer;
- $this->assertTrue($object->categoryHistogram instanceof Zend_Service_Ebay_Finding_Category_Histogram_Set);
- // Zend_Service_Ebay_Finding_Category_Histogram
- $object = $object->categoryHistogram->current();
- $this->assertTrue($object instanceof Zend_Service_Ebay_Finding_Category_Histogram);
- $this->assertTrue($object->childCategoryHistogram instanceof Zend_Service_Ebay_Finding_Category_Histogram_Set);
- $this->assertNotNull($object->count);
- }
- protected function _readXML($xml)
- {
- $dom = new DOMDocument();
- $dom->loadXML($xml);
- return $dom;
- }
- protected function _createResponseItems($xml)
- {
- return new Zend_Service_Ebay_Finding_Response_Items($this->_readXML($xml)->firstChild);
- }
- protected function _createResponseHistograms($xml)
- {
- return new Zend_Service_Ebay_Finding_Response_Histograms($this->_readXML($xml)->firstChild);
- }
- protected function _createResponseKeywords($xml)
- {
- return new Zend_Service_Ebay_Finding_Response_Keywords($this->_readXML($xml)->firstChild);
- }
- }
|