Error message

  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).
  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).

abstract class LocalTranslatorTestBase

Base class for local translator tests.

Hierarchy

Expanded class hierarchy of LocalTranslatorTestBase

File

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

Namespace

Drupal\Tests\tmgmt_local\Functional
View source
abstract class LocalTranslatorTestBase extends TMGMTTestBase {
  use TmgmtEntityTestTrait;

  /**
   * Translator user.
   *
   * @var object
   */
  protected $assignee;
  protected $localTranslatorPermissions = array(
    'provide translation services',
  );
  protected $localManagerPermissions = [
    'administer translation tasks',
    'provide translation services',
    'view the administration theme',
    'administer themes',
  ];

  /**
   * Modules to enable.
   *
   * @var array
   */
  protected static $modules = [
    'user',
    'tmgmt',
    'tmgmt_language_combination',
    'tmgmt_local',
  ];

  /**
   * {@inheritdoc}
   */
  public function setUp() : void {
    parent::setUp();
    $this
      ->loginAsAdmin();
    $this
      ->addLanguage('de');
    $this
      ->drupalPlaceBlock('system_breadcrumb_block');
  }

  /**
   * Asserts task status icon.
   *
   * @param int $row
   *   The row of the item you want to check.
   * @param string $view
   *   The view where we want to assert.
   * @param string $overview
   *   The overview table to check.
   * @param int $state
   *   The expected state.
   */
  protected function assertTaskStatusIcon($row, $view, $overview, $state) {
    $result = $this
      ->xpath('//*[@id="views-form-tmgmt-local-' . $view . '-' . $overview . '"]/table/tbody/tr[' . $row . ']/td[2]/img')[0];
    $this
      ->assertEquals($state, $result
      ->getAttribute('title'));
  }

  /**
   * Asserts task item status icon.
   *
   * @param string $row
   *   Identifier for the row.
   * @param int $state
   *   The expected state.
   */
  protected function assertTaskItemStatusIcon($row, $state) {
    $result = $this
      ->xpath('//*[@id="edit-items"]/div/div/table/tbody/tr[td//text()[contains(., :row)]]/td[1]/img', [
      ':row' => $row,
    ])[0];
    $this
      ->assertEquals($state, $result
      ->getAttribute('title'));
  }

  /**
   * Asserts the task progress bar.
   *
   * @param int $row
   *   The row of the item you want to check.
   * @param string $overview
   *   The overview to be checked.
   * @param int $untranslated
   *   The amount of untranslated items.
   * @param int $translated
   *   The amount of translated items.
   * @param int $completed
   *   The amount of completed items.
   */
  protected function assertTaskProgress($row, $overview, $untranslated, $translated, $completed) {
    $result = $this
      ->xpath('//*[@id="views-form-tmgmt-local-task-overview-' . $overview . '"]/table/tbody/tr[' . $row . ']/td[3]')[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'));
  }

  /**
   * Asserts the task item progress bar.
   *
   * @param string $row
   *   Identifier for the row.
   * @param int $untranslated
   *   The amount of untranslated items.
   * @param int $translated
   *   The amount of translated items.
   * @param int $completed
   *   The amount of completed items.
   */
  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'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LocalTranslatorTestBase::$assignee protected property Translator user.
LocalTranslatorTestBase::$localManagerPermissions protected property
LocalTranslatorTestBase::$localTranslatorPermissions protected property
LocalTranslatorTestBase::$modules protected static property Modules to enable. Overrides TMGMTTestBase::$modules 2
LocalTranslatorTestBase::assertTaskItemProgress protected function Asserts the task item progress bar.
LocalTranslatorTestBase::assertTaskItemStatusIcon protected function Asserts task item status icon.
LocalTranslatorTestBase::assertTaskProgress protected function Asserts the task progress bar.
LocalTranslatorTestBase::assertTaskStatusIcon protected function Asserts task status icon.
LocalTranslatorTestBase::setUp public function Overrides DrupalWebTestCase::setUp() Overrides TMGMTTestBase::setUp
TmgmtEntityTestTrait::$field_names public property
TmgmtEntityTestTrait::attachFields function Creates fields of type text and text_with_summary of different cardinality.
TmgmtEntityTestTrait::createNodeType function Creates node type with several text fields with different cardinality.
TmgmtEntityTestTrait::createTaxonomyTerm function Creates a taxonomy term of a given vocabulary.
TmgmtEntityTestTrait::createTaxonomyVocab function Creates taxonomy vocabulary with custom fields.
TmgmtEntityTestTrait::createTranslatableNode protected function Creates a node of a given bundle.
TMGMTTestBase::$defaultTheme protected property
TMGMTTestBase::$default_translator protected property A default translator using the test translator.
TmgmtTestTrait::$admin_permissions protected property List of permissions used by loginAsAdmin().
TmgmtTestTrait::$admin_user protected property Drupal user object created by loginAsAdmin().
TmgmtTestTrait::$languageWeight protected property The language weight for new languages.
TmgmtTestTrait::$translator_permissions protected property List of permissions used by loginAsTranslator().
TmgmtTestTrait::$translator_user protected property Drupal user object created by loginAsTranslator().
TmgmtTestTrait::addLanguage function Sets the proper environment.
TmgmtTestTrait::assertJobItemLangCodes function Asserts job item language codes.
TmgmtTestTrait::assertTextByXpath protected function Asserts text in the page with an xpath expression.
TmgmtTestTrait::clickLinkWithImageTitle function Clicks on an image link with the provided title attribute.
TmgmtTestTrait::createJob function Creates, saves and returns a translation job.
TmgmtTestTrait::createTranslator function Creates, saves and returns a translator.
TmgmtTestTrait::loginAsAdmin function Will create a user with admin permissions and log it in.
TmgmtTestTrait::loginAsTranslator function Will create a user with translator permissions and log it in.