OfflineTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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-2008 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-2008 Zend Technologies USA Inc. (http://www.zend.com)
  51. * @license http://framework.zend.com/license/new-bsd New BSD License
  52. */
  53. class Zend_Service_Amazon_OfflineTest extends PHPUnit_Framework_TestCase
  54. {
  55. /**
  56. * Reference to Amazon service consumer object
  57. *
  58. * @var Zend_Service_Amazon
  59. */
  60. protected $_amazon;
  61. /**
  62. * HTTP client adapter for testing
  63. *
  64. * @var Zend_Http_Client_Adapter_Test
  65. */
  66. protected $_httpClientAdapterTest;
  67. /**
  68. * Sets up this test case
  69. *
  70. * @return void
  71. */
  72. public function setUp()
  73. {
  74. $this->_amazon = new Zend_Service_Amazon(constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID'));
  75. $this->_httpClientAdapterTest = new Zend_Http_Client_Adapter_Test();
  76. }
  77. /**
  78. * Ensures that __construct() throws an exception when given an invalid country code
  79. *
  80. * @return void
  81. */
  82. public function testConstructExceptionCountryCodeInvalid()
  83. {
  84. try {
  85. $amazon = new Zend_Service_Amazon(constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID'), 'oops');
  86. $this->fail('Expected Zend_Service_Exception not thrown');
  87. } catch (Zend_Service_Exception $e) {
  88. $this->assertContains('Unknown country code', $e->getMessage());
  89. }
  90. }
  91. /**
  92. * @group ZF-2056
  93. */
  94. public function testMozardSearchFromFile()
  95. {
  96. $xml = file_get_contents(dirname(__FILE__)."/_files/mozart_result.xml");
  97. $dom = new DOMDocument();
  98. $dom->loadXML($xml);
  99. $mozartTracks = array(
  100. 'B00005A8JZ' => '29',
  101. 'B0000058HV' => '25',
  102. 'B000BLI3K2' => '500',
  103. 'B00004X0QF' => '9',
  104. 'B000004194' => '19',
  105. 'B00000I9M0' => '9',
  106. 'B000004166' => '20',
  107. 'B00002DEH1' => '58',
  108. 'B0000041EV' => '12',
  109. 'B00004SA87' => '42',
  110. );
  111. $result = new Zend_Service_Amazon_ResultSet($dom);
  112. foreach($result AS $item) {
  113. $trackCount = $mozartTracks[$item->ASIN];
  114. $this->assertEquals($trackCount, count($item->Tracks));
  115. }
  116. }
  117. /**
  118. * @group ZF-2749
  119. */
  120. public function testSimilarProductConstructorMissingAttributeDoesNotThrowNotice()
  121. {
  122. $dom = new DOMDocument();
  123. $asin = $dom->createElement("ASIN", "TEST");
  124. $product = $dom->createElement("product");
  125. $product->appendChild($asin);
  126. $similarproduct = new Zend_Service_Amazon_SimilarProduct($product);
  127. }
  128. }