public function FieldUnitTest::testTrimText

Tests the trimText method.

File

drupal/core/modules/views/lib/Drupal/views/Tests/Handler/FieldUnitTest.php, line 549
Contains \Drupal\views\Tests\Handler\FieldUnitTest.

Class

FieldUnitTest
Tests the generic field handler.

Namespace

Drupal\views\Tests\Handler

Code

public function testTrimText() {

  // Test unicode, @see http://drupal.org/node/513396#comment-2839416
  $text = array(
    'Tuy nhiên, những hi vọng',
    'Giả sử chúng tôi có 3 Apple',
    'siêu nhỏ này là bộ xử lý',
    'Di động của nhà sản xuất Phần Lan',
    'khoảng cách từ đại lí đến',
    'của hãng bao gồm ba dòng',
    'сд асд асд ас',
    'асд асд асд ас',
  );

  // Just test maxlength without word boundry.
  $alter = array(
    'max_length' => 10,
  );
  $expect = array(
    'Tuy nhiên,',
    'Giả sử chú',
    'siêu nhỏ n',
    'Di động củ',
    'khoảng các',
    'của hãng b',
    'сд асд асд',
    'асд асд ас',
  );
  foreach ($text as $key => $line) {
    $result_text = FieldPluginBase::trimText($alter, $line);
    $this
      ->assertEqual($result_text, $expect[$key]);
  }

  // Test also word_boundary
  $alter['word_boundary'] = TRUE;
  $expect = array(
    'Tuy nhiên',
    'Giả sử',
    'siêu nhỏ',
    'Di động',
    'khoảng',
    'của hãng',
    'сд асд',
    'асд асд',
  );
  foreach ($text as $key => $line) {
    $result_text = FieldPluginBase::trimText($alter, $line);
    $this
      ->assertEqual($result_text, $expect[$key]);
  }
}