AbstractTest.php 6.9 KB

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