function HelperTest::testDataIemLabel

Tests the itemLabel() function.

@todo: Move into a unit test case once available.

File

tests/src/Kernel/HelperTest.php, line 40

Class

HelperTest
Tests the helper functions in tmgmt.module.

Namespace

Drupal\Tests\tmgmt\Kernel

Code

function testDataIemLabel() {
  $no_label = array(
    '#text' => 'No label',
  );
  $this
    ->assertEquals('No label', \Drupal::service('tmgmt.data')
    ->itemLabel($no_label));
  $this
    ->assertEquals('No la…', \Drupal::service('tmgmt.data')
    ->itemLabel($no_label, 6));
  $label = array(
    '#parent_label' => array(),
    '#label' => 'A label',
  );
  $this
    ->assertEquals('A label', \Drupal::service('tmgmt.data')
    ->itemLabel($label));
  $this
    ->assertEquals('A lab…', \Drupal::service('tmgmt.data')
    ->itemLabel($label, 6));
  $parent_label = array(
    '#parent_label' => array(
      'Parent label',
      'Sub label',
    ),
    '#label' => 'A label',
  );
  $this
    ->assertEquals('Parent label > Sub label', \Drupal::service('tmgmt.data')
    ->itemLabel($parent_label));
  $this
    ->assertEquals('Parent… > Sub la…', \Drupal::service('tmgmt.data')
    ->itemLabel($parent_label, 18));
  $nested = array(
    '#parent_label' => array(
      'Parent label',
      'Sub label',
      'Sub-sub label',
    ),
    '#label' => 'A label',
  );
  $this
    ->assertEquals('Parent label > Sub label > Sub-sub label', \Drupal::service('tmgmt.data')
    ->itemLabel($nested));
  $this
    ->assertEquals('Parent… > Sub la… > Sub-su…', \Drupal::service('tmgmt.data')
    ->itemLabel($nested, 28));
  $long_label = array(
    '#parent_label' => array(
      'Loooooooooooong label',
      'Short',
    ),
    '#label' => 'A label',
  );
  $this
    ->assertEquals('Loooooooooooong label > Short', \Drupal::service('tmgmt.data')
    ->itemLabel($long_label));
  $this
    ->assertEquals('Loooooooooooong label > Short', \Drupal::service('tmgmt.data')
    ->itemLabel($long_label, 30));
  $node_example = array(
    '#parent_label' => array(
      'This is a very loooong title, so looong',
      'Body',
      'Delta #0',
      'Body',
    ),
    '#label' => 'A label',
  );
  $this
    ->assertEquals('This is a very loooong title, so looong > Body > Delta #0 > Body', \Drupal::service('tmgmt.data')
    ->itemLabel($node_example));
  $this
    ->assertEquals('This is a very loooong title, … > Body > Delta #0 > Body', \Drupal::service('tmgmt.data')
    ->itemLabel($node_example, 56));
}