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).

class LocalTranslatorContinuousTest

Test Continuous jobs support in the local translator.

@group tmgmt

Hierarchy

Expanded class hierarchy of LocalTranslatorContinuousTest

File

translators/tmgmt_local/tests/src/Functional/LocalTranslatorContinuousTest.php, line 14

Namespace

Drupal\Tests\tmgmt_local\Functional
View source
class LocalTranslatorContinuousTest extends LocalTranslatorTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  protected static $modules = array(
    'tmgmt_content',
  );

  /**
   * Test continuous Jobs in TMGMT local.
   */
  public function testContinuousJobs() {
    $type = $this
      ->drupalCreateContentType();

    // Enable entity translations for nodes.
    $content_translation_manager = \Drupal::service('content_translation.manager');
    $content_translation_manager
      ->setEnabled('node', $type
      ->label(), TRUE);
    $this->assignee = $this
      ->drupalCreateUser($this->localTranslatorPermissions);
    $this
      ->drupalLogin($this->assignee);
    $this
      ->drupalGet($this->assignee
      ->toUrl('edit-form'));
    $edit = array(
      'tmgmt_translation_skills[0][language_from]' => 'en',
      'tmgmt_translation_skills[0][language_to]' => 'de',
    );
    $this
      ->submitForm($edit, 'Save');
    $this
      ->loginAsAdmin($this->localManagerPermissions);

    // Test continuous integration.
    $this
      ->config('tmgmt.settings')
      ->set('submit_job_item_on_cron', TRUE)
      ->save();

    // Continuous settings configuration.
    $continuous_settings = [
      'content' => [
        'node' => [
          'enabled' => 1,
          'bundles' => [
            $type
              ->id() => 1,
          ],
        ],
      ],
    ];
    $translator = $this
      ->createTranslator([
      'plugin' => 'local',
    ]);
    $continuous_job = $this
      ->createJob('en', 'de', 0, [
      'label' => 'Continuous job',
      'job_type' => Job::TYPE_CONTINUOUS,
      'translator' => $translator,
      'continuous_settings' => $continuous_settings,
    ]);
    $continuous_job
      ->save();

    // Create an english node.
    $node = Node::create([
      'title' => $this
        ->randomMachineName(),
      'uid' => 0,
      'type' => $type
        ->id(),
      'langcode' => 'en',
    ]);
    $node
      ->save();
    $continuous_job_items = $continuous_job
      ->getItems();
    $this
      ->assertCount(1, $continuous_job_items);
    $continuous_job_item = reset($continuous_job_items);
    $this
      ->assertTrue($continuous_job_item
      ->getState() == JobItemInterface::STATE_INACTIVE);
    tmgmt_cron();
    $this
      ->drupalGet('translate');
    $this
      ->clickLink('View');

    // Assign to user.
    $edit = array(
      'tuid' => $this->assignee
        ->id(),
    );
    $this
      ->submitForm($edit, 'Save task');
    $this
      ->drupalLogin($this->assignee);
    $this
      ->drupalGet('translate');
    $this
      ->clickLink('View');
    $this
      ->clickLink('Translate');
    $edit = array(
      'title|0|value[translation]' => 'Text für Job Element mit Typ-Knoten und ID 1.',
    );
    $this
      ->submitForm($edit, 'Save as completed');
    $items = $continuous_job
      ->getItems();
    $item = reset($items);

    // Check is set to need review.
    $data = $item
      ->getData();
    $this
      ->assertEquals('Text für Job Element mit Typ-Knoten und ID 1.', $data['title']['0']['value']['#translation']['#text']);
    $this
      ->assertTrue($continuous_job
      ->getState() == Job::STATE_CONTINUOUS);
    $this
      ->assertTrue($item
      ->getState() == JobItemInterface::STATE_REVIEW);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LocalTranslatorContinuousTest::$modules protected static property Modules to enable. Overrides LocalTranslatorTestBase::$modules
LocalTranslatorContinuousTest::testContinuousJobs public function Test continuous Jobs in TMGMT local.
LocalTranslatorTestBase::$assignee protected property Translator user.
LocalTranslatorTestBase::$localManagerPermissions protected property
LocalTranslatorTestBase::$localTranslatorPermissions protected property
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.