You are here

function TextSummaryTest::testLength in Zircon Profile 8

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

Test various summary length edge cases.

File

core/modules/text/src/Tests/TextSummaryTest.php, line 57
Contains \Drupal\text\Tests\TextSummaryTest.

Class

TextSummaryTest
Tests text_summary() with different strings and lengths.

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++);
}