|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * This file is part of PHPOffice Common |
| 4 | + * |
| 5 | + * PHPOffice Common is free software distributed under the terms of the GNU Lesser |
| 6 | + * General Public License version 3 as published by the Free Software Foundation. |
| 7 | + * |
| 8 | + * For the full copyright and license information, please read the LICENSE |
| 9 | + * file that was distributed with this source code. For the full list of |
| 10 | + * contributors, visit https://github.com/PHPOffice/Common/contributors. |
| 11 | + * |
| 12 | + * @link https://github.com/PHPOffice/Common |
| 13 | + * @copyright 2009-2014 PHPOffice Common contributors |
| 14 | + * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
| 15 | + */ |
| 16 | + |
| 17 | +namespace PhpOffice\Common\Tests; |
| 18 | + |
| 19 | +use PhpOffice\Common\Text; |
| 20 | + |
| 21 | +/** |
| 22 | + * Test class for Text |
| 23 | + * |
| 24 | + * @coversDefaultClass PhpOffice\Common\Text |
| 25 | + */ |
| 26 | +class TextTest extends \PHPUnit_Framework_TestCase |
| 27 | +{ |
| 28 | + /** |
| 29 | + */ |
| 30 | + public function testControlCharacters() |
| 31 | + { |
| 32 | + $this->assertEquals('', Text::controlCharacterPHP2OOXML()); |
| 33 | + $this->assertEquals('aeiou', Text::controlCharacterPHP2OOXML('aeiou')); |
| 34 | + $this->assertEquals('àéîöù', Text::controlCharacterPHP2OOXML('àéîöù')); |
| 35 | + |
| 36 | + $value = rand(0, 8); |
| 37 | + $this->assertEquals('_x'.sprintf('%04s', strtoupper(dechex($value))).'_', Text::controlCharacterPHP2OOXML(chr($value))); |
| 38 | + } |
| 39 | + |
| 40 | + public function testNumberFormat() |
| 41 | + { |
| 42 | + $this->assertEquals('2.1', Text::numberFormat('2.06', 1)); |
| 43 | + $this->assertEquals('2.1', Text::numberFormat('2.12', 1)); |
| 44 | + $this->assertEquals('1234', Text::numberFormat(1234, 1)); |
| 45 | + } |
| 46 | + |
| 47 | + public function testChr() |
| 48 | + { |
| 49 | + $this->assertEquals('A', Text::chr(65)); |
| 50 | + $this->assertEquals('A', Text::chr(0x41)); |
| 51 | + $this->assertEquals('é', Text::chr(233)); |
| 52 | + $this->assertEquals('é', Text::chr(0xE9)); |
| 53 | + $this->assertEquals('⼳', Text::chr(12083)); |
| 54 | + $this->assertEquals('⼳', Text::chr(0x2F33)); |
| 55 | + $this->assertEquals('🌃', Text::chr(127747)); |
| 56 | + $this->assertEquals('🌃', Text::chr(0x1F303)); |
| 57 | + $this->assertEquals('', Text::chr(2097152)); |
| 58 | + } |
| 59 | +} |
0 commit comments