You are here

function HelperTest::testDataIemLabel in Translation Management Tool 8

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