AbstractTest.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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: AbstractTest.php 22824 2010-08-09 18:59:54Z renanbr $
  21. */
  22. /**
  23. * @see Zend_Service_Ebay_Abstract
  24. */
  25. require_once dirname(__FILE__) . '/_files/Concrete.php';
  26. /**
  27. * @see Zend_Config
  28. */
  29. require_once 'Zend/Config.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Service_Ebay
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2015 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_AbstractTest extends PHPUnit_Framework_TestCase
  38. {
  39. /**
  40. * @var Zend_Service_Ebay_AbstractConcrete
  41. */
  42. protected $_concrete;
  43. protected function setUp()
  44. {
  45. $this->_concrete = new Zend_Service_Ebay_AbstractConcrete(array());
  46. }
  47. public function testConstructor()
  48. {
  49. $array = array('foo' => 'bar',
  50. 'some' => 'value');
  51. $config = new Zend_Config($array);
  52. $concreteArray = new Zend_Service_Ebay_AbstractConcrete($array);
  53. $concreteConfig = new Zend_Service_Ebay_AbstractConcrete($config);
  54. foreach (array_keys($array) as $option) {
  55. $this->assertEquals($concreteArray->getOption($option), $concreteConfig->getOption($option));
  56. }
  57. }
  58. public function testSetOptions()
  59. {
  60. $array = array('foo' => 'bar',
  61. 'some' => 'value');
  62. $config = new Zend_Config($array);
  63. $concreteArray = new Zend_Service_Ebay_AbstractConcrete();
  64. $concreteArray->setOption($array);
  65. $concreteConfig = new Zend_Service_Ebay_AbstractConcrete();
  66. $concreteConfig->setOption($config);
  67. foreach (array_keys($array) as $option) {
  68. $this->assertEquals($concreteArray->getOption($option), $concreteConfig->getOption($option));
  69. }
  70. $this->assertNull($concreteArray->getOption('bar'));
  71. $this->assertNull($concreteConfig->getOption('bar'));
  72. }
  73. public function testOptionsToArrayInvalid()
  74. {
  75. $this->setExpectedException('Zend_Service_Ebay_Exception');
  76. Zend_Service_Ebay_Abstract::optionsToArray('invalid');
  77. }
  78. public function testGetOption()
  79. {
  80. $expected = array(
  81. 'foo' => 1,
  82. 'bar' => 2
  83. );
  84. $this->_concrete->setOption('foo', 1)
  85. ->setOption(array('bar' => 2));
  86. $this->assertEquals(1, $this->_concrete->getOption('foo'));
  87. $this->assertEquals(2, $this->_concrete->getOption('bar'));
  88. $this->assertEquals($expected, $this->_concrete->getOption());
  89. $this->_concrete->setOption(
  90. array('foo' => 3,
  91. 'bar' => 4
  92. )
  93. );
  94. $this->assertEquals(3, $this->_concrete->getOption('foo'));
  95. $this->assertEquals(4, $this->_concrete->getOption('bar'));
  96. }
  97. public function testHasOption()
  98. {
  99. $this->_concrete->setOption('foo', 1);
  100. $this->assertTrue($this->_concrete->hasOption('foo'));
  101. $this->assertFalse($this->_concrete->hasOption('bar'));
  102. }
  103. public function testToEbayValue()
  104. {
  105. $this->assertSame('1', Zend_Service_Ebay_AbstractConcrete::toEbayValue(true));
  106. $this->assertSame('0', Zend_Service_Ebay_AbstractConcrete::toEbayValue(false));
  107. require_once 'Zend/Date.php';
  108. $date = new Zend_Date();
  109. $this->assertSame($date->getIso(), Zend_Service_Ebay_AbstractConcrete::toEbayValue($date));
  110. $date = new DateTime();
  111. $this->assertSame($date->format(DateTime::ISO8601), Zend_Service_Ebay_AbstractConcrete::toEbayValue($date));
  112. $this->assertSame('10', Zend_Service_Ebay_AbstractConcrete::toEbayValue(10));
  113. }
  114. public function testToPhpValue()
  115. {
  116. $this->assertSame('10', Zend_Service_Ebay_Abstract::toPhpValue(10, 'integer'));
  117. $this->assertSame('foo', Zend_Service_Ebay_Abstract::toPhpValue('foo', 'string'));
  118. $this->assertSame(10.5, Zend_Service_Ebay_Abstract::toPhpValue(10.5, 'float'));
  119. $this->assertTrue(true, Zend_Service_Ebay_Abstract::toPhpValue('true', 'boolean'));
  120. }
  121. public function testToPhpValueInvalidType()
  122. {
  123. $this->setExpectedException('Zend_Service_Ebay_Exception');
  124. Zend_Service_Ebay_Abstract::toPhpValue('value', 'invalid-type');
  125. }
  126. public function testOptionsToNameValueSyntax()
  127. {
  128. $options = array(
  129. 'paginationInput' => array(
  130. 'entriesPerPage' => 5,
  131. 'pageNumber' => 2
  132. ),
  133. 'itemFilter' => array(
  134. array(
  135. 'name' => 'MaxPrice',
  136. 'value' => 25,
  137. 'paramName' => 'Currency',
  138. 'paramValue' => 'USD'
  139. ),
  140. array(
  141. 'name' => 'FreeShippingOnly',
  142. 'value' => true
  143. ),
  144. array(
  145. 'name' => 'ListingType',
  146. 'value' => array(
  147. 'AuctionWithBIN',
  148. 'FixedPrice',
  149. 'StoreInventory'
  150. )
  151. )
  152. ),
  153. 'productId' => array(
  154. '' => 123,
  155. 'type' => 'UPC'
  156. )
  157. );
  158. $expected = array(
  159. 'paginationInput.entriesPerPage' => '5',
  160. 'paginationInput.pageNumber' => '2',
  161. 'itemFilter(0).name' => 'MaxPrice',
  162. 'itemFilter(0).value' => '25',
  163. 'itemFilter(0).paramName' => 'Currency',
  164. 'itemFilter(0).paramValue' => 'USD',
  165. 'itemFilter(1).name' => 'FreeShippingOnly',
  166. 'itemFilter(1).value' => '1',
  167. 'itemFilter(2).name' => 'ListingType',
  168. 'itemFilter(2).value(0)' => 'AuctionWithBIN',
  169. 'itemFilter(2).value(1)' => 'FixedPrice',
  170. 'itemFilter(2).value(2)' => 'StoreInventory',
  171. 'productId' => '123',
  172. 'productId.@type' => 'UPC'
  173. );
  174. $this->assertEquals($expected, $this->_concrete->optionsToNameValueSyntax($options));
  175. }
  176. }