function TextSummaryTest::testLength
Same name in other branches
- 9 core/modules/text/tests/src/Kernel/TextSummaryTest.php \Drupal\Tests\text\Kernel\TextSummaryTest::testLength()
- 8.9.x core/modules/text/tests/src/Kernel/TextSummaryTest.php \Drupal\Tests\text\Kernel\TextSummaryTest::testLength()
- 10 core/modules/text/tests/src/Kernel/TextSummaryTest.php \Drupal\Tests\text\Kernel\TextSummaryTest::testLength()
Tests various summary length edge cases.
File
-
core/
modules/ text/ tests/ src/ Kernel/ TextSummaryTest.php, line 80
Class
- TextSummaryTest
- Tests text_summary() with different strings and lengths.
Namespace
Drupal\Tests\text\KernelCode
public function testLength() : void {
FilterFormat::create([
'format' => 'autop',
'name' => 'Autop',
'filters' => [
'filter_autop' => [
'status' => 1,
],
],
])->save();
FilterFormat::create([
'format' => 'autop_correct',
'name' => 'Autop correct',
'filters' => [
'filter_autop' => [
'status' => 1,
],
'filter_htmlcorrector' => [
'status' => 1,
],
],
])->save();
// This string tests a number of edge cases.
$text = "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>";
// The summaries we expect text_summary() to return when $size is the index
// of each array item.
// Using no text format:
$format = NULL;
$i = 0;
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
$this->assertTextSummary($text, "<", $format, $i++);
$this->assertTextSummary($text, "<p", $format, $i++);
$this->assertTextSummary($text, "<p>", $format, $i++);
$this->assertTextSummary($text, "<p>\n", $format, $i++);
$this->assertTextSummary($text, "<p>\nH", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n<", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
// Using a text format with filter_autop enabled.
$format = 'autop';
$i = 0;
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
$this->assertTextSummary($text, "<", $format, $i++);
$this->assertTextSummary($text, "<p", $format, $i++);
$this->assertTextSummary($text, "<p>", $format, $i++);
$this->assertTextSummary($text, "<p>", $format, $i++);
$this->assertTextSummary($text, "<p>", $format, $i++);
$this->assertTextSummary($text, "<p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
// Using a text format with filter_autop and filter_htmlcorrector enabled.
$format = 'autop_correct';
$i = 0;
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
$this->assertTextSummary($text, "", $format, $i++);
$this->assertTextSummary($text, "<p></p>", $format, $i++);
$this->assertTextSummary($text, "<p></p>", $format, $i++);
$this->assertTextSummary($text, "<p></p>", $format, $i++);
$this->assertTextSummary($text, "<p></p>", $format, $i++);
$this->assertTextSummary($text, "<p></p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.