You are here

public function UnicodeTest::providerTruncate in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php \Drupal\Tests\Component\Utility\UnicodeTest::providerTruncate()
  2. 10 core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php \Drupal\Tests\Component\Utility\UnicodeTest::providerTruncate()

Data provider for testTruncate().

Return value

array An array containing:

  • The string to test.
  • The max length to truncate this string to.
  • The expected string result.
  • (optional) Boolean for the $wordsafe flag. Defaults to FALSE.
  • (optional) Boolean for the $add_ellipsis flag. Defaults to FALSE.

See also

testTruncate()

File

core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php, line 341

Class

UnicodeTest
Test unicode handling features implemented in Unicode component.

Namespace

Drupal\Tests\Component\Utility

Code

public function providerTruncate() {
  $tests = [
    [
      'frànçAIS is über-åwesome',
      24,
      'frànçAIS is über-åwesome',
    ],
    [
      'frànçAIS is über-åwesome',
      23,
      'frànçAIS is über-åwesom',
    ],
    [
      'frànçAIS is über-åwesome',
      17,
      'frànçAIS is über-',
    ],
    [
      '以呂波耳・ほへとち。リヌルヲ。',
      6,
      '以呂波耳・ほ',
    ],
    [
      'frànçAIS is über-åwesome',
      24,
      'frànçAIS is über-åwesome',
      FALSE,
      TRUE,
    ],
    [
      'frànçAIS is über-åwesome',
      23,
      'frànçAIS is über-åweso…',
      FALSE,
      TRUE,
    ],
    [
      'frànçAIS is über-åwesome',
      17,
      'frànçAIS is über…',
      FALSE,
      TRUE,
    ],
    [
      '123',
      1,
      '…',
      TRUE,
      TRUE,
    ],
    [
      '123',
      2,
      '1…',
      TRUE,
      TRUE,
    ],
    [
      '123',
      3,
      '123',
      TRUE,
      TRUE,
    ],
    [
      '1234',
      3,
      '12…',
      TRUE,
      TRUE,
    ],
    [
      '1234567890',
      10,
      '1234567890',
      TRUE,
      TRUE,
    ],
    [
      '12345678901',
      10,
      '123456789…',
      TRUE,
      TRUE,
    ],
    [
      '12345678901',
      11,
      '12345678901',
      TRUE,
      TRUE,
    ],
    [
      '123456789012',
      11,
      '1234567890…',
      TRUE,
      TRUE,
    ],
    [
      '12345 7890',
      10,
      '12345 7890',
      TRUE,
      TRUE,
    ],
    [
      '12345 7890',
      9,
      '12345…',
      TRUE,
      TRUE,
    ],
    [
      '123 567 90',
      10,
      '123 567 90',
      TRUE,
      TRUE,
    ],
    [
      '123 567 901',
      10,
      '123 567…',
      TRUE,
      TRUE,
    ],
    [
      'Stop. Hammertime.',
      17,
      'Stop. Hammertime.',
      TRUE,
      TRUE,
    ],
    [
      'Stop. Hammertime.',
      16,
      'Stop…',
      TRUE,
      TRUE,
    ],
    [
      'frànçAIS is über-åwesome',
      24,
      'frànçAIS is über-åwesome',
      TRUE,
      TRUE,
    ],
    [
      'frànçAIS is über-åwesome',
      23,
      'frànçAIS is über…',
      TRUE,
      TRUE,
    ],
    [
      'frànçAIS is über-åwesome',
      17,
      'frànçAIS is über…',
      TRUE,
      TRUE,
    ],
    [
      '¿Dónde está el niño?',
      20,
      '¿Dónde está el niño?',
      TRUE,
      TRUE,
    ],
    [
      '¿Dónde está el niño?',
      19,
      '¿Dónde está el…',
      TRUE,
      TRUE,
    ],
    [
      '¿Dónde está el niño?',
      13,
      '¿Dónde está…',
      TRUE,
      TRUE,
    ],
    [
      '¿Dónde está el niño?',
      10,
      '¿Dónde…',
      TRUE,
      TRUE,
    ],
    [
      'Help! Help! Help!',
      17,
      'Help! Help! Help!',
      TRUE,
      TRUE,
    ],
    [
      'Help! Help! Help!',
      16,
      'Help! Help!…',
      TRUE,
      TRUE,
    ],
    [
      'Help! Help! Help!',
      15,
      'Help! Help!…',
      TRUE,
      TRUE,
    ],
    [
      'Help! Help! Help!',
      14,
      'Help! Help!…',
      TRUE,
      TRUE,
    ],
    [
      'Help! Help! Help!',
      13,
      'Help! Help!…',
      TRUE,
      TRUE,
    ],
    [
      'Help! Help! Help!',
      12,
      'Help! Help!…',
      TRUE,
      TRUE,
    ],
    [
      'Help! Help! Help!',
      11,
      'Help! Help…',
      TRUE,
      TRUE,
    ],
    [
      'Help! Help! Help!',
      10,
      'Help!…',
      TRUE,
      TRUE,
    ],
    [
      'Help! Help! Help!',
      9,
      'Help!…',
      TRUE,
      TRUE,
    ],
    [
      'Help! Help! Help!',
      8,
      'Help!…',
      TRUE,
      TRUE,
    ],
    [
      'Help! Help! Help!',
      7,
      'Help!…',
      TRUE,
      TRUE,
    ],
    [
      'Help! Help! Help!',
      6,
      'Help!…',
      TRUE,
      TRUE,
    ],
    [
      'Help! Help! Help!',
      5,
      'Help…',
      TRUE,
      TRUE,
    ],
    [
      'Help! Help! Help!',
      4,
      'Hel…',
      TRUE,
      TRUE,
    ],
    [
      'Help! Help! Help!',
      3,
      'He…',
      TRUE,
      TRUE,
    ],
    [
      'Help! Help! Help!',
      2,
      'H…',
      TRUE,
      TRUE,
    ],
  ];

  // Test truncate on text with multiple lines.
  $multi_line = <<<EOF
This is a text that spans multiple lines.
Line 2 goes here.
EOF;
  $multi_line_wordsafe = <<<EOF
This is a text that spans multiple lines.
Line 2
EOF;
  $multi_line_non_wordsafe = <<<EOF
This is a text that spans multiple lines.
Line 2 go
EOF;
  $tests[] = [
    $multi_line,
    51,
    $multi_line_wordsafe,
    TRUE,
  ];
  $tests[] = [
    $multi_line,
    51,
    $multi_line_non_wordsafe,
    FALSE,
  ];
  return $tests;
}