2
0

OfflineTest.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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_Amazon
  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$
  21. */
  22. /**
  23. * Test helper
  24. */
  25. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  26. /**
  27. * @see Zend_Service_Amazon
  28. */
  29. require_once 'Zend/Service/Amazon.php';
  30. /**
  31. * @see Zend_Service_Amazon_ResultSet
  32. */
  33. require_once 'Zend/Service/Amazon/ResultSet.php';
  34. /**
  35. * @see Zend_Service_Amazon_ResultSet
  36. */
  37. require_once 'Zend/Service/Amazon/SimilarProduct.php';
  38. /**
  39. * @see Zend_Http_Client_Adapter_Socket
  40. */
  41. require_once 'Zend/Http/Client/Adapter/Socket.php';
  42. /**
  43. * @see Zend_Http_Client_Adapter_Test
  44. */
  45. require_once 'Zend/Http/Client/Adapter/Test.php';
  46. /**
  47. * @category Zend
  48. * @package Zend_Service_Amazon
  49. * @subpackage UnitTests
  50. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  51. * @license http://framework.zend.com/license/new-bsd New BSD License
  52. * @group Zend_Service
  53. * @group Zend_Service_Amazon
  54. */
  55. class Zend_Service_Amazon_OfflineTest extends PHPUnit_Framework_TestCase
  56. {
  57. /**
  58. * Reference to Amazon service consumer object
  59. *
  60. * @var Zend_Service_Amazon
  61. */
  62. protected $_amazon;
  63. /**
  64. * HTTP client adapter for testing
  65. *
  66. * @var Zend_Http_Client_Adapter_Test
  67. */
  68. protected $_httpClientAdapterTest;
  69. /**
  70. * Sets up this test case
  71. *
  72. * @return void
  73. */
  74. public function setUp()
  75. {
  76. $this->_amazon = new Zend_Service_Amazon(constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID'));
  77. $this->_httpClientAdapterTest = new Zend_Http_Client_Adapter_Test();
  78. }
  79. /**
  80. * Ensures that __construct() throws an exception when given an invalid country code
  81. *
  82. * @return void
  83. */
  84. public function testConstructExceptionCountryCodeInvalid()
  85. {
  86. try {
  87. $amazon = new Zend_Service_Amazon(constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID'), 'oops');
  88. $this->fail('Expected Zend_Service_Exception not thrown');
  89. } catch (Zend_Service_Exception $e) {
  90. $this->assertContains('Unknown country code', $e->getMessage());
  91. }
  92. }
  93. /**
  94. * @group ZF-2056
  95. */
  96. public function testMozardSearchFromFile()
  97. {
  98. $xml = file_get_contents(dirname(__FILE__)."/_files/mozart_result.xml");
  99. $dom = new DOMDocument();
  100. $dom->loadXML($xml);
  101. $mozartTracks = array(
  102. 'B00005A8JZ' => '29',
  103. 'B0000058HV' => '25',
  104. 'B000BLI3K2' => '500',
  105. 'B00004X0QF' => '9',
  106. 'B000004194' => '19',
  107. 'B00000I9M0' => '9',
  108. 'B000004166' => '20',
  109. 'B00002DEH1' => '58',
  110. 'B0000041EV' => '12',
  111. 'B00004SA87' => '42',
  112. );
  113. $result = new Zend_Service_Amazon_ResultSet($dom);
  114. foreach($result AS $item) {
  115. $trackCount = $mozartTracks[$item->ASIN];
  116. $this->assertEquals($trackCount, count($item->Tracks));
  117. }
  118. }
  119. /**
  120. * @group ZF-2749
  121. */
  122. public function testSimilarProductConstructorMissingAttributeDoesNotThrowNotice()
  123. {
  124. $dom = new DOMDocument();
  125. $asin = $dom->createElement("ASIN", "TEST");
  126. $product = $dom->createElement("product");
  127. $product->appendChild($asin);
  128. $similarproduct = new Zend_Service_Amazon_SimilarProduct($product);
  129. }
  130. public function dataSignatureEncryption()
  131. {
  132. return array(
  133. array(
  134. 'http://webservices.amazon.com',
  135. array(
  136. 'Service' => 'AWSECommerceService',
  137. 'AWSAccessKeyId' => '00000000000000000000',
  138. 'Operation' => 'ItemLookup',
  139. 'ItemId' => '0679722769',
  140. 'ResponseGroup' => 'ItemAttributes,Offers,Images,Reviews',
  141. 'Version' => '2009-01-06',
  142. 'Timestamp' => '2009-01-01T12:00:00Z',
  143. ),
  144. "GET\n".
  145. "webservices.amazon.com\n".
  146. "/onca/xml\n".
  147. "AWSAccessKeyId=00000000000000000000&ItemId=0679722769&Operation=I".
  148. "temLookup&ResponseGroup=ItemAttributes%2COffers%2CImages%2CReview".
  149. "s&Service=AWSECommerceService&Timestamp=2009-01-01T12%3A00%3A00Z&".
  150. "Version=2009-01-06",
  151. 'Nace%2BU3Az4OhN7tISqgs1vdLBHBEijWcBeCqL5xN9xg%3D'
  152. ),
  153. array(
  154. 'http://ecs.amazonaws.co.uk',
  155. array(
  156. 'Service' => 'AWSECommerceService',
  157. 'AWSAccessKeyId' => '00000000000000000000',
  158. 'Operation' => 'ItemSearch',
  159. 'Actor' => 'Johnny Depp',
  160. 'ResponseGroup' => 'ItemAttributes,Offers,Images,Reviews,Variations',
  161. 'Version' => '2009-01-01',
  162. 'SearchIndex' => 'DVD',
  163. 'Sort' => 'salesrank',
  164. 'AssociateTag' => 'mytag-20',
  165. 'Timestamp' => '2009-01-01T12:00:00Z',
  166. ),
  167. "GET\n".
  168. "ecs.amazonaws.co.uk\n".
  169. "/onca/xml\n".
  170. "AWSAccessKeyId=00000000000000000000&Actor=Johnny%20Depp&Associate".
  171. "Tag=mytag-20&Operation=ItemSearch&ResponseGroup=ItemAttributes%2C".
  172. "Offers%2CImages%2CReviews%2CVariations&SearchIndex=DVD&Service=AW".
  173. "SECommerceService&Sort=salesrank&Timestamp=2009-01-01T12%3A00%3A0".
  174. "0Z&Version=2009-01-01",
  175. 'TuM6E5L9u%2FuNqOX09ET03BXVmHLVFfJIna5cxXuHxiU%3D',
  176. ),
  177. );
  178. }
  179. /**
  180. * Checking if signature Encryption due on August 15th for Amazon Webservice API is working correctly.
  181. *
  182. * @dataProvider dataSignatureEncryption
  183. * @group ZF-7033
  184. */
  185. public function testSignatureEncryption($baseUri, $params, $expectedStringToSign, $expectedSignature)
  186. {
  187. $this->assertEquals(
  188. $expectedStringToSign,
  189. Zend_Service_Amazon::buildRawSignature($baseUri, $params)
  190. );
  191. $this->assertEquals(
  192. $expectedSignature,
  193. rawurlencode(Zend_Service_Amazon::computeSignature(
  194. $baseUri, '1234567890', $params
  195. ))
  196. );
  197. }
  198. }