1
0
Fork 0
composer/tests/Composer/Test/Json/JsonFormatterTest.php

51 lines
1.3 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Test\Json;
use Composer\Json\JsonFormatter;
use PHPUnit\Framework\TestCase;
class JsonFormatterTest extends TestCase
{
/**
* Test if \u0119 (196+153) will get correctly formatted
* See ticket #2613
*/
public function testUnicodeWithPrependedSlash()
{
2014-03-06 09:26:16 +00:00
if (!extension_loaded('mbstring')) {
$this->markTestSkipped('Test requires the mbstring extension');
}
$data = '"' . chr(92) . chr(92) . chr(92) . 'u0119"';
$encodedData = JsonFormatter::format($data, true, true);
$expected = '34+92+92+196+153+34';
$this->assertEquals($expected, $this->getCharacterCodes($encodedData));
}
/**
* Convert string to character codes split by a plus sign
2014-06-10 14:02:44 +00:00
* @param string $string
* @return string
*/
protected function getCharacterCodes($string)
{
$codes = array();
for ($i = 0; $i < strlen($string); $i++) {
$codes[] = ord($string[$i]);
}
2014-06-10 14:02:44 +00:00
return implode('+', $codes);
}
}