You are here

public function TextSummaryTest::testLength in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/text/tests/src/Kernel/TextSummaryTest.php \Drupal\Tests\text\Kernel\TextSummaryTest::testLength()

Test various summary length edge cases.

File

core/modules/text/tests/src/Kernel/TextSummaryTest.php, line 72

Class

TextSummaryTest
Tests text_summary() with different strings and lengths.

Namespace

Drupal\Tests\text\Kernel

Code

public function testLength() {
  FilterFormat::create([
    'format' => 'autop',
    'filters' => [
      'filter_autop' => [
        'status' => 1,
      ],
    ],
  ])
    ->save();
  FilterFormat::create([
    'format' => '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++);
}