| @@ 67-88 (lines=22) @@ | ||
| 64 | /** |
|
| 65 | * @return array |
|
| 66 | */ |
|
| 67 | public function providerLimitCharactersToClosestWord() |
|
| 68 | { |
|
| 69 | // HTML is converted safely to plain text |
|
| 70 | return [ |
|
| 71 | // Standard words limited, ellipsis added if truncated |
|
| 72 | ['<p>Lorem ipsum dolor sit amet</p>', 24, 'Lorem ipsum dolor sit...'], |
|
| 73 | ||
| 74 | // Complete words less than the character limit don't get truncated, ellipsis not added |
|
| 75 | ['<p>Lorem ipsum</p>', 24, 'Lorem ipsum'], |
|
| 76 | ['<p>Lorem</p>', 24, 'Lorem'], |
|
| 77 | ['', 24, ''], // No words produces nothing! |
|
| 78 | ||
| 79 | // Special characters are encoded safely |
|
| 80 | ['Nice & Easy', 24, 'Nice & Easy'], |
|
| 81 | ||
| 82 | // HTML is safely converted to plain text |
|
| 83 | ['<p>Lorem ipsum dolor sit amet</p>', 24, 'Lorem ipsum dolor sit...'], |
|
| 84 | ['<p><span>Lorem ipsum dolor sit amet</span></p>', 24, 'Lorem ipsum dolor sit...'], |
|
| 85 | ['<p>Lorem ipsum</p>', 24, 'Lorem ipsum'], |
|
| 86 | ['Lorem & ipsum dolor sit amet', 24, 'Lorem & ipsum dolor sit...'] |
|
| 87 | ]; |
|
| 88 | } |
|
| 89 | ||
| 90 | /** |
|
| 91 | * Test {@link DBHTMLText->LimitCharactersToClosestWord()} |
|
| @@ 104-157 (lines=54) @@ | ||
| 101 | $this->assertEquals($expectedValue, $result); |
|
| 102 | } |
|
| 103 | ||
| 104 | public function providerSummary() |
|
| 105 | { |
|
| 106 | return [ |
|
| 107 | [ |
|
| 108 | '<p>Should strip <b>tags, but leave</b> text</p>', |
|
| 109 | 50, |
|
| 110 | 'Should strip tags, but leave text', |
|
| 111 | ], |
|
| 112 | [ |
|
| 113 | // Line breaks are preserved |
|
| 114 | '<p>Unclosed tags <br>should not phase it</p>', |
|
| 115 | 50, |
|
| 116 | "Unclosed tags <br />\nshould not phase it", |
|
| 117 | ], |
|
| 118 | [ |
|
| 119 | // Paragraphs converted to linebreak |
|
| 120 | '<p>Second paragraph</p><p>should not cause errors or appear in output</p>', |
|
| 121 | 50, |
|
| 122 | "Second paragraph<br />\n<br />\nshould not cause errors or appear in output", |
|
| 123 | ], |
|
| 124 | [ |
|
| 125 | '<img src="hello" /><p>Second paragraph</p><p>should not cause errors or appear in output</p>', |
|
| 126 | 50, |
|
| 127 | "Second paragraph<br />\n<br />\nshould not cause errors or appear in output", |
|
| 128 | ], |
|
| 129 | [ |
|
| 130 | ' <img src="hello" /><p>Second paragraph</p><p>should not cause errors or appear in output</p>', |
|
| 131 | 50, |
|
| 132 | "Second paragraph<br />\n<br />\nshould not cause errors or appear in output", |
|
| 133 | ], |
|
| 134 | [ |
|
| 135 | '<p><img src="remove me">example <img src="include me">text words hello<img src="hello"></p>', |
|
| 136 | 50, |
|
| 137 | 'example text words hello', |
|
| 138 | ], |
|
| 139 | ||
| 140 | // Shorter limits |
|
| 141 | [ |
|
| 142 | '<p>A long paragraph should be cut off if limit is set</p>', |
|
| 143 | 5, |
|
| 144 | 'A long paragraph should be...', |
|
| 145 | ], |
|
| 146 | [ |
|
| 147 | '<p>No matter <i>how many <b>tags</b></i> are in it</p>', |
|
| 148 | 5, |
|
| 149 | 'No matter how many tags...', |
|
| 150 | ], |
|
| 151 | [ |
|
| 152 | '<p>A sentence is. nicer than hard limits</p>', |
|
| 153 | 5, |
|
| 154 | 'A sentence is.', |
|
| 155 | ], |
|
| 156 | ]; |
|
| 157 | } |
|
| 158 | ||
| 159 | /** |
|
| 160 | * @dataProvider providerSummary |
|