15 use \PHPUnit4And6Compat;
25 $this->assertSame( $expected, $truncator->getFirstSentences( $text, $sentences ) );
29 $longLine = str_repeat(
'word ', 1000000 );
32 'Foo is a bar. Such a smart boy. But completely useless.',
34 'Foo is a bar. Such a smart boy.',
37 'Foo is a bar. Such a smart boy. But completely useless.',
42 'Foo is a bar. Such a smart boy.',
44 'Foo is a bar. Such a smart boy.',
61 '0 sentences mean empty result' => [
62 'Foo is a bar. Such a smart boy.',
66 "Don't explode on negative input" => [
67 'Foo is a bar. Such a smart boy.',
71 'More sentences requested than is available' => [
72 'Foo is a bar. Such a smart boy.',
74 'Foo is a bar. Such a smart boy.',
78 'Foo is a bar! Such a smart boy! But completely useless!',
84 "Acid phosphatase (EC 3.1.3.2) is a chemical you don't want to mess with. " .
85 "Polyvinyl acetate, however, is another story.",
87 "Acid phosphatase (EC 3.1.3.2) is a chemical you don't want to mess with.",
97 'Foo was born in 1977. He enjoys listening to Siouxsie and the Banshees.',
99 'Foo was born in 1977.',
103 'P.J. Harvey is a singer. She is awesome!',
105 'P.J. Harvey is a singer.',
109 html_entity_decode(
'Pigeons (lat. Columbidae) are birds. ' .
110 'They primarily feed on seeds.' ),
112 html_entity_decode(
'Pigeons (lat. Columbidae) are birds.' ),
121 str_repeat(
'Sentence. ', 70000 ),
123 trim( str_repeat(
'Sentence. ', 65536 ) ),
126 'Preserve whitespace before end character' => [
142 $this->assertSame( $expected, $truncator->getFirstChars( $text,
$chars ) );
146 $text =
'Lullzy lulz are lullzy!';
147 $html =
'foo<tag>bar</tag>';
148 $longText = str_repeat(
'тест ', 50000 );
149 $longTextExpected = trim( str_repeat(
'тест ', 13108 ) );
154 [ $text, 100, $text ],
155 [ $text, 1,
'Lullzy' ],
156 [ $text, 6,
'Lullzy' ],
158 [ $text, 8,
'Lullzy lulz' ],
162 [ $html, 4,
'foo<tag>' ],
163 [ $html, 12,
'foo<tag>bar</tag>' ],
164 [ $html, 13,
'foo<tag>bar</tag>' ],
165 [ $html, 16,
'foo<tag>bar</tag>' ],
166 [ $html, 17,
'foo<tag>bar</tag>' ],
169 [ $longText, 65536, $longTextExpected ],
174 $tidy = $this->createMock( TidyDriverBase::class );
175 $tidy->method(
'tidy' )
176 ->willReturnCallback(
function ( $text ) {
177 return "<tidy>$text</tidy>";
182 $this->assertSame(
'<tidy>Aa.</tidy>', $truncator->getFirstSentences( $text, 1 ) );
183 $this->assertSame(
'<tidy>Aa</tidy>', $truncator->getFirstChars( $text, 1 ) );