public function ModuleTest::test_views_trim_text

File

drupal/core/modules/views/lib/Drupal/views/Tests/ModuleTest.php, line 30
Definition of Drupal\views\Tests\ModuleTest.

Class

ModuleTest
Tests basic functions from the Views module.

Namespace

Drupal\views\Tests

Code

public function test_views_trim_text() {

  // 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 = views_trim_text($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 = views_trim_text($alter, $line);
    $this
      ->assertEqual($result_text, $expect[$key]);
  }
}