JsonFormatterTest.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Json;
  12. use Composer\Json\JsonFormatter;
  13. class JsonFormatterTest extends \PHPUnit_Framework_TestCase
  14. {
  15. /**
  16. * Test if \u0119 (196+153) will get correctly formatted
  17. * See ticket #2613
  18. */
  19. public function testUnicodeWithPrependedSlash()
  20. {
  21. $data = '"' . chr(92) . chr(92) . chr(92) . 'u0119"';
  22. $encodedData = JsonFormatter::format($data, true, true);
  23. $expected = '34+92+92+196+153+34';
  24. $this->assertEquals($expected, $this->getCharacterCodes($encodedData));
  25. }
  26. /**
  27. * Convert string to character codes split by a plus sign
  28. * @param string $string
  29. * @return string
  30. */
  31. protected function getCharacterCodes($string)
  32. {
  33. $codes = array();
  34. for ($i = 0; $i < strlen($string); $i++) {
  35. $codes[] = ord($string[$i]);
  36. }
  37. return implode('+', $codes);
  38. }
  39. }