function TextSummaryTest::testLength

Test various summary length edge cases.

File

drupal/core/modules/text/lib/Drupal/text/Tests/TextSummaryTest.php, line 64
Definition of Drupal\text\TextSummaryTest.

Class

TextSummaryTest
Tests the text field summary.

Namespace

Drupal\text\Tests

Code

function testLength() {
  entity_create('filter_format', array(
    'format' => 'autop',
    'filters' => array(
      'filter_autop' => array(
        'status' => 1,
      ),
    ),
  ))
    ->save();
  entity_create('filter_format', array(
    'format' => 'autop_correct',
    'filters' => array(
      'filter_autop' => array(
        'status' => 1,
      ),
      'filter_htmlcorrector' => array(
        '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++);
}