19 declare(strict_types=1);
23 require_once
'vendor/composer/vendor/autoload.php';
34 private const TEXT = <<<EOT
35 Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
37 private const HTML = <<<EOT
38 <div>Lorem ipsum dolor <span style=
"color: red;">sit amet</span>, <img src=
"#" /> consetetur sadipscing elitr, sed diam nonumy eirmod <img src=
"#" /> tempor invidunt <img src=
"#" /> ut labore et dolore <img src=
"#" /> magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor <img src=
"#" /> sit amet. <img src=
"#" /> Lorem ipsum dolor <img src=
"#" /> sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, <img src=
"#" /> sed diam voluptua. <img src=
"#" /> At vero eos et accusam et justo duo dolores et ea rebum. Stet <img src=
"#" /> clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</div>
41 private const HTML_WITH_NON_XHTML_URLS = <<<EOT
42 <a href=
"http://www.ilias.de=foo=1&bar=2">
ILIAS</a>
47 protected function setUp(): void
50 $this->createMock(DataFactory::class),
51 $this->createMock(Language::class)
60 public static function inputProvider(): array
69 [
static function ():
void {
77 public static function unsupportedButKnownEntitiesProvider(): array
79 return array_map(
static function (
string $entity): array {
81 '<div>Lorem ipsum dolor <' . $entity .
'></' . $entity .
'></div>' 100 public function testExceptionIsRaisedIfInputIsNotAString($from):
void 102 $this->expectException(InvalidArgumentException::class);
103 $readingTimeTrafo = $this->
refinery->string()->estimatedReadingTime(
true);
105 $readingTimeTrafo->transform($from);
108 public function testReadingTimeForPlainTextCanBeDetermined():
void 110 $readingTimeTrafo = $this->
refinery->string()->estimatedReadingTime(
true);
113 $readingTimeTrafo->transform(self::TEXT)
117 public function testReadingTimeForHtmlFragmentCanBeDetermined():
void 121 $readingTimeTrafo = $this->
refinery->string()->estimatedReadingTime(
true);
124 $readingTimeTrafo->transform($text)
127 $onlyTextReadingTimeInfo = $this->
refinery->string()->estimatedReadingTime();
130 $onlyTextReadingTimeInfo->transform($text)
134 public function testSolitaryPunctuationCharactersMustNotAffectReadingTime():
void 136 $textSegmentWithPunctuation =
'Lorem ipsum <img src="#" />, and some other text... ';
139 $readingTimeTrafo = $this->
refinery->string()->estimatedReadingTime(
true);
141 $text = str_repeat($textSegmentWithPunctuation, $repetitions);
143 $timeInMinutes = $readingTimeTrafo->transform($text);
144 $this->assertEquals(23, $timeInMinutes);
146 $textSegmentWithoutPunctuation =
'Lorem ipsum <img src="#" /> and some other text... ';
147 $text = str_repeat($textSegmentWithoutPunctuation, $repetitions);
149 $timeInMinutes = $readingTimeTrafo->transform($text);
150 $this->assertEquals(23, $timeInMinutes);
153 public function testXTHMLCommentsMustNotAffectReadingTime():
void 157 $comment =
'<script><!--a comment--></script>';
159 $text .= str_repeat(
$comment, $repetitions);
161 $onlyTextReadingTimeInfo = $this->
refinery->string()->estimatedReadingTime();
164 $onlyTextReadingTimeInfo->transform($text)
172 public function testNoExceptionIsRaisedIfHtmlContainsUnsupportedEntities(
string $text):
void 174 $reading_time_trafo = $this->
refinery->string()->estimatedReadingTime(
true);
176 $reading_time = $reading_time_trafo->transform($text);
178 $this->assertIsInt($reading_time);
179 $this->assertGreaterThan(0, $reading_time);
182 public function testNoExceptionIsRaisedIfHtmlContainsAmpersandInUrls():
void 184 $reading_time_trafo = $this->
refinery->string()->estimatedReadingTime(
true);
186 $reading_time = $reading_time_trafo->transform(self::HTML_WITH_NON_XHTML_URLS);
188 $this->assertIsInt($reading_time);
189 $this->assertGreaterThan(0, $reading_time);
Interface Observer Contains several chained tasks and infos about them.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...