BigIntegerValueTest.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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_XmlRpc
  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: ValueTest.php 23550 2010-12-18 13:18:38Z ramon $
  21. */
  22. require_once 'Zend/XmlRpc/Value.php';
  23. require_once 'Zend/XmlRpc/Value/Scalar.php';
  24. require_once 'Zend/XmlRpc/Value/BigInteger.php';
  25. require_once 'Zend/XmlRpc/Value/Collection.php';
  26. require_once 'Zend/XmlRpc/Value/Array.php';
  27. require_once 'Zend/XmlRpc/Value/Base64.php';
  28. require_once 'Zend/XmlRpc/Value/Boolean.php';
  29. require_once 'Zend/XmlRpc/Value/DateTime.php';
  30. require_once 'Zend/XmlRpc/Value/Double.php';
  31. require_once 'Zend/XmlRpc/Value/Integer.php';
  32. require_once 'Zend/XmlRpc/Value/String.php';
  33. require_once 'Zend/XmlRpc/Value/Nil.php';
  34. require_once 'Zend/XmlRpc/Value/Struct.php';
  35. require_once 'Zend/Crypt/Math/BigInteger.php';
  36. require_once 'Zend/XmlRpc/TestProvider.php';
  37. require_once 'Zend/Date.php';
  38. /**
  39. * Test case for Zend_XmlRpc_Value
  40. *
  41. * @category Zend
  42. * @package Zend_XmlRpc
  43. * @subpackage UnitTests
  44. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  45. * @license http://framework.zend.com/license/new-bsd New BSD License
  46. * @group Zend_XmlRpc
  47. */
  48. class Zend_XmlRpc_BigIntegerValueTest extends PHPUnit_Framework_TestCase
  49. {
  50. public function setUp()
  51. {
  52. try {
  53. $XmlRpcBigInteger = new Zend_XmlRpc_Value_BigInteger(0);
  54. } catch (Zend_Crypt_Math_BigInteger_Exception $e) {
  55. $this->markTestSkipped($e->getMessage());
  56. }
  57. }
  58. // BigInteger
  59. /**
  60. * @group ZF-6445
  61. * @group ZF-8623
  62. */
  63. public function testBigIntegerGetValue()
  64. {
  65. $bigIntegerValue = (string)(PHP_INT_MAX + 42);
  66. $bigInteger = new Zend_XmlRpc_Value_BigInteger($bigIntegerValue);
  67. $this->assertSame($bigIntegerValue, $bigInteger->getValue());
  68. }
  69. /**
  70. * @group ZF-6445
  71. */
  72. public function testBigIntegerGetType()
  73. {
  74. $bigIntegerValue = (string)(PHP_INT_MAX + 42);
  75. $bigInteger = new Zend_XmlRpc_Value_BigInteger($bigIntegerValue);
  76. $this->assertSame(Zend_XmlRpc_Value::XMLRPC_TYPE_I8, $bigInteger->getType());
  77. }
  78. /**
  79. * @group ZF-6445
  80. */
  81. public function testBigIntegerGeneratedXml()
  82. {
  83. $bigIntegerValue = (string)(PHP_INT_MAX + 42);
  84. $bigInteger = new Zend_XmlRpc_Value_BigInteger($bigIntegerValue);
  85. $this->assertEquals(
  86. '<value><i8>' . $bigIntegerValue . '</i8></value>',
  87. $bigInteger->saveXml()
  88. );
  89. }
  90. /**
  91. * @group ZF-6445
  92. * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
  93. */
  94. public function testMarschalBigIntegerFromXmlRpc(Zend_XmlRpc_Generator_GeneratorAbstract $generator)
  95. {
  96. Zend_XmlRpc_Value::setGenerator($generator);
  97. $bigIntegerValue = (string)(PHP_INT_MAX + 42);
  98. $bigInteger = new Zend_XmlRpc_Value_BigInteger($bigIntegerValue);
  99. $bigIntegerXml = '<value><i8>' . $bigIntegerValue . '</i8></value>';
  100. $value = Zend_XmlRpc_Value::getXmlRpcValue(
  101. $bigIntegerXml,
  102. Zend_XmlRpc_Value::XML_STRING
  103. );
  104. $this->assertSame($bigIntegerValue, $value->getValue());
  105. $this->assertEquals(Zend_XmlRpc_Value::XMLRPC_TYPE_I8, $value->getType());
  106. $this->assertEquals($this->wrapXml($bigIntegerXml), $value->saveXml());
  107. }
  108. /**
  109. * @group ZF-6445
  110. * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
  111. */
  112. public function testMarschalBigIntegerFromApacheXmlRpc(Zend_XmlRpc_Generator_GeneratorAbstract $generator)
  113. {
  114. Zend_XmlRpc_Value::setGenerator($generator);
  115. $bigIntegerValue = (string)(PHP_INT_MAX + 42);
  116. $bigInteger = new Zend_XmlRpc_Value_BigInteger($bigIntegerValue);
  117. $bigIntegerXml = '<value><ex:i8 xmlns:ex="http://ws.apache.org/xmlrpc/namespaces/extensions">' . $bigIntegerValue . '</ex:i8></value>';
  118. $value = Zend_XmlRpc_Value::getXmlRpcValue(
  119. $bigIntegerXml,
  120. Zend_XmlRpc_Value::XML_STRING
  121. );
  122. $this->assertSame($bigIntegerValue, $value->getValue());
  123. $this->assertEquals(Zend_XmlRpc_Value::XMLRPC_TYPE_I8, $value->getType());
  124. $this->assertEquals($this->wrapXml($bigIntegerXml), $value->saveXml());
  125. }
  126. /**
  127. * @group ZF-6445
  128. */
  129. public function testMarshalBigIntegerFromNative()
  130. {
  131. $bigIntegerValue = (string)(PHP_INT_MAX + 42);
  132. $value = Zend_XmlRpc_Value::getXmlRpcValue(
  133. $bigIntegerValue,
  134. Zend_XmlRpc_Value::XMLRPC_TYPE_I8
  135. );
  136. $this->assertEquals(Zend_XmlRpc_Value::XMLRPC_TYPE_I8, $value->getType());
  137. $this->assertSame($bigIntegerValue, $value->getValue());
  138. }
  139. /**
  140. * @group ZF-6445
  141. */
  142. public function testMarschalBigIntegerFromCryptObjectThrowsException()
  143. {
  144. try {
  145. Zend_XmlRpc_Value::getXmlRpcValue(new Zend_Crypt_Math_BigInteger);
  146. $this->fail('expected Zend_XmlRpc_Value_Exception has not been thrown');
  147. } catch (Zend_XmlRpc_Value_Exception $exception) {
  148. if (strpos($exception->getMessage(), 'Zend_Crypt_Math_BigInteger') === false) {
  149. $this->fail('caught Zend_XmlRpc_Value_Exception does not contain expected text');
  150. }
  151. }
  152. }
  153. // Custom Assertions and Helper Methods
  154. public function wrapXml($xml)
  155. {
  156. return $xml . "\n";
  157. }
  158. }
  159. // Call Zend_XmlRpc_ValueTest::main() if this source file is executed directly.
  160. if (PHPUnit_MAIN_METHOD == "Zend_XmlRpc_BigIntegerValueTest::main") {
  161. Zend_XmlRpc_ValueTest::main();
  162. }