|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of PHP-Typography. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright 2017 Peter Putzer. |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software; you can redistribute it and/or |
|
8
|
|
|
* modify it under the terms of the GNU General Public License |
|
9
|
|
|
* as published by the Free Software Foundation; either version 2 |
|
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 |
|
18
|
|
|
* along with this program; if not, write to the Free Software |
|
19
|
|
|
* Foundation, Inc., 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\Tests\PHP_Typography_Testcase; |
|
28
|
|
|
use \PHP_Typography\Settings; |
|
29
|
|
|
use \PHP_Typography\Fixes\Node_Fix; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Abstract base class for \PHP_Typography\* unit tests. |
|
33
|
|
|
*/ |
|
34
|
|
|
abstract class Node_Fix_Testcase extends PHP_Typography_Testcase { |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Settings object. |
|
38
|
|
|
* |
|
39
|
|
|
* @var Ssttings |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $s; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Our test object. |
|
45
|
|
|
* |
|
46
|
|
|
* @var Node_Fix |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $fix; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Sets up the fixture, for example, opens a network connection. |
|
52
|
|
|
* This method is called before a test is executed. |
|
53
|
|
|
*/ |
|
54
|
|
|
protected function setUp() { // @codingStandardsIgnoreLine |
|
55
|
|
|
$this->s = new Settings( true ); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Create a normalilzed textnode. |
|
60
|
|
|
* |
|
61
|
|
|
* @param string $value Required. |
|
62
|
|
|
* |
|
63
|
|
|
* @return \DOMText |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function create_textnode( $value ) { |
|
66
|
|
|
// returns < > & to encoded HTML characters (< > and & respectively). |
|
67
|
|
|
return new \DOMText( htmlspecialchars( html_entity_decode( $value ), ENT_NOQUOTES, 'UTF-8', false ) ); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Assert that the output of the fix is the same as the expected result. |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $input Text node value. |
|
74
|
|
|
* @param string $result Expected result. |
|
75
|
|
|
* @param string|null $left_sibling Optional. Left sibling node value. Default null. |
|
76
|
|
|
* @param string|null $right_sibling Optional. Right sibling node value. Default null. |
|
77
|
|
|
* @param string $parent_tag Optional. Parent tag. Default 'p'. |
|
78
|
|
|
* @param bool $is_title Optional. Default false. |
|
79
|
|
|
*/ |
|
80
|
|
|
protected function assertFixResultSame( $input, $result, $left_sibling = null, $right_sibling = null, $parent_tag = 'p', $is_title = false ) { |
|
81
|
|
|
$node = $this->create_textnode( $input ); |
|
82
|
|
|
|
|
83
|
|
|
if ( ! empty( $left_sibling ) || ! empty( $right_sibling ) ) { |
|
84
|
|
|
$dom = new \DOMDocument(); |
|
85
|
|
|
$parent = new \DOMElement( $parent_tag ); |
|
86
|
|
|
$dom->appendChild( $parent ); |
|
87
|
|
|
|
|
88
|
|
|
if ( ! empty( $left_sibling ) ) { |
|
89
|
|
|
$parent->appendChild( $this->create_textnode( $left_sibling ) ); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$parent->appendChild( $node ); |
|
93
|
|
|
|
|
94
|
|
|
if ( ! empty( $right_sibling ) ) { |
|
95
|
|
|
$parent->appendChild( $this->create_textnode( $right_sibling ) ); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
$this->fix->apply( $node, $this->s, $is_title ); |
|
100
|
|
|
$this->assertSame( $this->clean_html( $result ), $this->clean_html( $node->data ) ); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..