|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * This file is part of PHP-Typography. |
| 4 | + * |
| 5 | + * Copyright 2024 Peter Putzer. |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 2 of the License, or |
| 10 | + * of the License, or ( at your option ) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License along |
| 18 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | + * |
| 21 | + * @package mundschenk-at/php-typography/tests |
| 22 | + * @license http://www.gnu.org/licenses/gpl-2.0.html |
| 23 | + */ |
| 24 | + |
| 25 | +namespace PHP_Typography\Tests\Fixes\Node_Fixes; |
| 26 | + |
| 27 | +use PHP_Typography\Fixes\Node_Fixes; |
| 28 | +use PHP_Typography\Settings; |
| 29 | + |
| 30 | +/** |
| 31 | + * Unicode_Remapping_Fix unit test. |
| 32 | + * |
| 33 | + * @coversDefaultClass \PHP_Typography\Fixes\Node_Fixes\Unicode_Remapping_Fix |
| 34 | + * @usesDefaultClass \PHP_Typography\Fixes\Node_Fixes\Unicode_Remapping_Fix |
| 35 | + * |
| 36 | + * @uses ::__construct |
| 37 | + * @uses PHP_Typography\Fixes\Node_Fixes\Abstract_Node_Fix::__construct |
| 38 | + * @uses PHP_Typography\DOM |
| 39 | + * @uses PHP_Typography\Settings |
| 40 | + * @uses PHP_Typography\Settings\Dash_Style |
| 41 | + * @uses PHP_Typography\Settings\Quote_Style |
| 42 | + * @uses PHP_Typography\Settings\Simple_Dashes |
| 43 | + * @uses PHP_Typography\Settings\Simple_Quotes |
| 44 | + * @uses PHP_Typography\Strings |
| 45 | + */ |
| 46 | +class Unicode_Remapping_Fix_Test extends Node_Fix_Testcase { |
| 47 | + |
| 48 | + /** |
| 49 | + * Sets up the fixture, for example, opens a network connection. |
| 50 | + * This method is called before a test is executed. |
| 51 | + */ |
| 52 | + protected function set_up() { |
| 53 | + parent::set_up(); |
| 54 | + |
| 55 | + $this->fix = new Node_Fixes\Unicode_Remapping_Fix(); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Provides data for testing apply. |
| 60 | + * |
| 61 | + * @return array |
| 62 | + */ |
| 63 | + public function provide_character_mapping_data() { |
| 64 | + return [ |
| 65 | + [ |
| 66 | + 'foobar', |
| 67 | + [ |
| 68 | + 'a' => 'A', |
| 69 | + 'r' => 'z', |
| 70 | + ], |
| 71 | + 'foobAz', |
| 72 | + ], |
| 73 | + [ |
| 74 | + '', |
| 75 | + [ |
| 76 | + 'a' => 'A', |
| 77 | + 'r' => 'z', |
| 78 | + ], |
| 79 | + '', |
| 80 | + ], |
| 81 | + ]; |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Test apply. |
| 86 | + * |
| 87 | + * @covers ::apply |
| 88 | + * @covers ::__construct |
| 89 | + * |
| 90 | + * @uses PHP_Typography\Fixes\Node_Fixes\Simple_Regex_Replacement_Fix::apply |
| 91 | + * |
| 92 | + * @dataProvider provide_character_mapping_data |
| 93 | + * |
| 94 | + * @param string $input HTML input. |
| 95 | + * @param string[] $mapping The character remapping to apply. |
| 96 | + * @param string $result Expected result. |
| 97 | + */ |
| 98 | + public function test_apply( $input, array $mapping, $result ) { |
| 99 | + $this->s = new Settings( false, $mapping ); |
| 100 | + |
| 101 | + $this->assertFixResultSame( $input, $result ); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * Test apply. |
| 106 | + * |
| 107 | + * @covers ::apply |
| 108 | + * @covers ::__construct |
| 109 | + * |
| 110 | + * @uses PHP_Typography\Fixes\Node_Fixes\Simple_Regex_Replacement_Fix::apply |
| 111 | + * |
| 112 | + * @dataProvider provide_character_mapping_data |
| 113 | + * |
| 114 | + * @param string $input HTML input. |
| 115 | + */ |
| 116 | + public function test_apply_off( $input ) { |
| 117 | + $this->s = new Settings( false, [] ); |
| 118 | + |
| 119 | + $this->assertFixResultSame( $input, $input ); |
| 120 | + } |
| 121 | +} |
0 commit comments