IcuVersionTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Intl\Tests\Util;
  11. use Symfony\Component\Intl\Util\IcuVersion;
  12. /**
  13. * @author Bernhard Schussek <bschussek@gmail.com>
  14. */
  15. class IcuVersionTest extends \PHPUnit_Framework_TestCase
  16. {
  17. public function normalizeProvider()
  18. {
  19. return array(
  20. array(null, '1', '10'),
  21. array(null, '1.2', '12'),
  22. array(null, '1.2.3', '12.3'),
  23. array(null, '1.2.3.4', '12.3.4'),
  24. array(1, '1', '10'),
  25. array(1, '1.2', '12'),
  26. array(1, '1.2.3', '12'),
  27. array(1, '1.2.3.4', '12'),
  28. array(2, '1', '10'),
  29. array(2, '1.2', '12'),
  30. array(2, '1.2.3', '12.3'),
  31. array(2, '1.2.3.4', '12.3'),
  32. array(3, '1', '10'),
  33. array(3, '1.2', '12'),
  34. array(3, '1.2.3', '12.3'),
  35. array(3, '1.2.3.4', '12.3.4'),
  36. );
  37. }
  38. /**
  39. * @dataProvider normalizeProvider
  40. */
  41. public function testNormalize($precision, $version, $result)
  42. {
  43. $this->assertSame($result, IcuVersion::normalize($version, $precision));
  44. }
  45. public function compareProvider()
  46. {
  47. return array(
  48. array(null, '1', '==', '1', true),
  49. array(null, '1.0', '==', '1.1', false),
  50. array(null, '1.0.0', '==', '1.0.1', false),
  51. array(null, '1.0.0.0', '==', '1.0.0.1', false),
  52. array(null, '1.0.0.0.0', '==', '1.0.0.0.1', false),
  53. array(null, '1', '==', '10', true),
  54. array(null, '1.0', '==', '11', false),
  55. array(null, '1.0.0', '==', '10.1', false),
  56. array(null, '1.0.0.0', '==', '10.0.1', false),
  57. array(null, '1.0.0.0.0', '==', '10.0.0.1', false),
  58. array(1, '1', '==', '1', true),
  59. array(1, '1.0', '==', '1.1', false),
  60. array(1, '1.0.0', '==', '1.0.1', true),
  61. array(1, '1.0.0.0', '==', '1.0.0.1', true),
  62. array(1, '1.0.0.0.0', '==', '1.0.0.0.1', true),
  63. array(1, '1', '==', '10', true),
  64. array(1, '1.0', '==', '11', false),
  65. array(1, '1.0.0', '==', '10.1', true),
  66. array(1, '1.0.0.0', '==', '10.0.1', true),
  67. array(1, '1.0.0.0.0', '==', '10.0.0.1', true),
  68. array(2, '1', '==', '1', true),
  69. array(2, '1.0', '==', '1.1', false),
  70. array(2, '1.0.0', '==', '1.0.1', false),
  71. array(2, '1.0.0.0', '==', '1.0.0.1', true),
  72. array(2, '1.0.0.0.0', '==', '1.0.0.0.1', true),
  73. array(2, '1', '==', '10', true),
  74. array(2, '1.0', '==', '11', false),
  75. array(2, '1.0.0', '==', '10.1', false),
  76. array(2, '1.0.0.0', '==', '10.0.1', true),
  77. array(2, '1.0.0.0.0', '==', '10.0.0.1', true),
  78. array(3, '1', '==', '1', true),
  79. array(3, '1.0', '==', '1.1', false),
  80. array(3, '1.0.0', '==', '1.0.1', false),
  81. array(3, '1.0.0.0', '==', '1.0.0.1', false),
  82. array(3, '1.0.0.0.0', '==', '1.0.0.0.1', true),
  83. array(3, '1', '==', '10', true),
  84. array(3, '1.0', '==', '11', false),
  85. array(3, '1.0.0', '==', '10.1', false),
  86. array(3, '1.0.0.0', '==', '10.0.1', false),
  87. array(3, '1.0.0.0.0', '==', '10.0.0.1', true),
  88. );
  89. }
  90. /**
  91. * @dataProvider compareProvider
  92. */
  93. public function testCompare($precision, $version1, $operator, $version2, $result)
  94. {
  95. $this->assertSame($result, IcuVersion::compare($version1, $version2, $operator, $precision));
  96. }
  97. }