You are here

protected function LocalTranslatorTestBase::assertTaskItemProgress in Translation Management Tool 8

Asserts the task item progress bar.

Parameters

string $row: Identifier for the row.

int $untranslated: The amount of untranslated items.

int $translated: The amount of translated items.

int $completed: The amount of completed items.

1 call to LocalTranslatorTestBase::assertTaskItemProgress()
LocalTranslatorTest::testLocalProgress in translators/tmgmt_local/tests/src/Functional/LocalTranslatorTest.php
Tests of the task progress.

File

translators/tmgmt_local/tests/src/Functional/LocalTranslatorTestBase.php, line 143

Class

LocalTranslatorTestBase
Base class for local translator tests.

Namespace

Drupal\Tests\tmgmt_local\Functional

Code

protected function assertTaskItemProgress($row, $untranslated, $translated, $completed) {
  $result = $this
    ->xpath('//*[@id="edit-items"]/div/div/table/tbody/tr[td//text()[contains(., :row)]]/td[2]', [
    ':row' => $row,
  ])[0];
  $div_number = 1;
  if ($untranslated > 0) {
    $this
      ->assertEquals('tmgmt-local-progress-untranslated', $result
      ->find('css', "div > div:nth-child({$div_number})")
      ->getAttribute('class'));
    $div_number++;
  }
  else {
    $this
      ->assertNotEquals('tmgmt-local-progress-untranslated', $result
      ->find('css', "div > div:nth-child({$div_number})")
      ->getAttribute('class'));
  }
  if ($translated > 0) {
    $this
      ->assertEquals('tmgmt-local-progress-translated', $result
      ->find('css', "div > div:nth-child({$div_number})")
      ->getAttribute('class'));
    $div_number++;
  }
  else {
    $child = $result
      ->find('css', "div > div:nth-child({$div_number})");
    $this
      ->assertTrue(!$child || $child
      ->getAttribute('class'), 'tmgmt-local-progress-translated');
  }
  if ($completed > 0) {
    $this
      ->assertEquals('tmgmt-local-progress-completed', $result
      ->find('css', "div > div:nth-child({$div_number})")
      ->getAttribute('class'));
  }
  else {
    $child = $result
      ->find('css', "div > div:nth-child({$div_number})");
    $this
      ->assertTrue(!$child || $child
      ->getAttribute('class'), 'tmgmt-local-progress-completed');
  }
  $title = t('Untranslated: @untranslated, translated: @translated, completed: @completed.', array(
    '@untranslated' => $untranslated,
    '@translated' => $translated,
    '@completed' => $completed,
  ));
  $this
    ->assertEquals($title, $result
    ->find('css', 'div')
    ->getAttribute('title'));
}