You are here

function TextSummaryTestCase::testLength in Drupal 7

Test various summary length edge cases.

File

modules/field/modules/text/text.test, line 283
Tests for text.module.

Class

TextSummaryTestCase

Code

function testLength() {

  // 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:
  $expected = array(
    "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>",
    "<",
    "<p",
    "<p>",
    "<p>\n",
    "<p>\nH",
    "<p>\nHi",
    "<p>\nHi\n",
    "<p>\nHi\n<",
    "<p>\nHi\n</",
    "<p>\nHi\n</p",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>",
    "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>",
    "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>",
  );

  // And using a text format WITH the line-break and htmlcorrector filters.
  $expected_lb = array(
    "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>",
    "",
    "<p></p>",
    "<p></p>",
    "<p></p>",
    "<p></p>",
    "<p></p>",
    "<p>\nHi</p>",
    "<p>\nHi</p>",
    "<p>\nHi</p>",
    "<p>\nHi</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>",
    "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>",
    "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>",
    "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>",
  );

  // Test text_summary() for different sizes.
  for ($i = 0; $i <= 37; $i++) {
    $this
      ->callTextSummary($text, $expected[$i], NULL, $i);
    $this
      ->callTextSummary($text, $expected_lb[$i], 'plain_text', $i);
    $this
      ->callTextSummary($text, $expected_lb[$i], 'filtered_html', $i);
  }
}