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 TMGMTCartTest

Verifies basic functionality of the user interface

@group tmgmt

Hierarchy

Expanded class hierarchy of TMGMTCartTest

File

tests/src/Functional/TMGMTCartTest.php, line 12

Namespace

Drupal\Tests\tmgmt\Functional
View source
class TMGMTCartTest extends TMGMTTestBase {
  protected static $modules = array(
    'tmgmt_content',
  );

  /**
   * {@inheritdoc}
   */
  function setUp() : void {
    parent::setUp();

    // Login as admin to be able to set environment variables.
    $this
      ->loginAsAdmin();
    $this
      ->addLanguage('es');
    $this
      ->addLanguage('sk');
    $this
      ->addLanguage('cs');

    // Login as translator only with limited permissions to run these tests.
    $this
      ->loginAsTranslator(array(
      'access administration pages',
      'create translation jobs',
      'submit translation jobs',
    ), TRUE);
  }

  /**
   * Test if the source is able to pull content in requested language.
   */
  function testCartEnforceSourceLanguage() {
    $content_type = $this
      ->drupalCreateContentType();
    $node_sk = $this
      ->drupalCreateNode(array(
      'title' => $this
        ->randomMachineName(),
      'langcode' => 'sk',
      'type' => $content_type
        ->id(),
    ));
    $node = $node_sk
      ->addTranslation('en');
    $node->title->value = $this
      ->randomMachineName();
    $node->body->value = $this
      ->randomMachineName();
    $node
      ->save();
    $node_cs = $this
      ->drupalCreateNode(array(
      'title' => $this
        ->randomMachineName(),
      'langcode' => 'cs',
      'type' => $content_type
        ->id(),
    ));
    $this
      ->loginAsTranslator();
    $job_item_sk = tmgmt_job_item_create('content', 'node', $node_sk
      ->id());
    $job_item_sk
      ->save();
    $this
      ->drupalGet('tmgmt-add-to-cart/' . $job_item_sk
      ->id());
    $job_items_data[$job_item_sk
      ->getItemId()] = $job_item_sk
      ->getItemType();
    $job_item_cs = tmgmt_job_item_create('content', 'node', $node_cs
      ->id());
    $job_item_cs
      ->save();
    $this
      ->drupalGet('tmgmt-add-to-cart/' . $job_item_cs
      ->id());
    $job_items_data[$job_item_cs
      ->getItemId()] = $job_item_cs
      ->getItemType();
    $this
      ->drupalGet('admin/tmgmt/cart');
    $this
      ->submitForm([
      'enforced_source_language' => TRUE,
      'source_language' => 'en',
      'target_language[]' => [
        'es',
      ],
    ], 'Request translation');
    $this
      ->assertSession()
      ->pageTextContains('One job needs to be checked out.');
    $this
      ->assertSession()
      ->responseContains(t('One item skipped as for the language @language it was not possible to retrieve a translation.', array(
      '@language' => 'English',
    )));
    $this
      ->assertSession()
      ->pageTextContains('You have enforced the job source language which most likely resulted in having a translation of your original content as the job source text. You should review the job translation received from the translator carefully to prevent the content quality loss.');
    $args = explode('/', $this
      ->getUrl());
    $tjid = array_pop($args);
    $this
      ->submitForm([], 'Submit to provider');

    // We cannot test for the item data as items without a job are not able to
    // get the data in case the source language is overridden. Therefore only
    // testing for item_id and item_type values.
    foreach (Job::load($tjid)
      ->getItems() as $job_item) {
      $this
        ->assertEquals($job_items_data[$job_item
        ->getItemId()], $job_item
        ->getItemType());
    }
    $this
      ->drupalGet('admin/tmgmt/cart');
    $this
      ->assertSession()
      ->pageTextContains($node_cs
      ->getTitle());
    $this
      ->assertSession()
      ->pageTextNotContains($node_sk
      ->getTitle());

    // Test that duplicate submission of an item is not allowed.
    $this
      ->drupalGet('admin/tmgmt/cart');
    $this
      ->submitForm([
      'target_language[]' => [
        'es',
      ],
    ], 'Request translation');
    $this
      ->submitForm([], 'Submit to provider');
    $this
      ->assertSession()
      ->pageTextContains('Test translation created.');
    $job_item_cs = tmgmt_job_item_create('content', 'node', $node_cs
      ->id());
    $job_item_cs
      ->save();
    $this
      ->drupalGet('tmgmt-add-to-cart/' . $job_item_cs
      ->id());
    $job_items_data[$job_item_cs
      ->getItemId()] = $job_item_cs
      ->getItemType();
    $this
      ->drupalGet('admin/tmgmt/cart');
    $this
      ->submitForm([
      'target_language[]' => [
        'es',
      ],
    ], 'Request translation');
    $this
      ->assertSession()
      ->pageTextContains('1 item conflicts with pending item and will be dropped on submission. Conflicting item: ' . $node_cs
      ->getTitle() . '.');
    $this
      ->submitForm([], 'Submit to provider');
    $this
      ->assertSession()
      ->pageTextContains('All job items are conflicting, the job can not be submitted.');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TMGMTCartTest::$modules protected static property Modules to enable. Overrides TMGMTTestBase::$modules
TMGMTCartTest::setUp function Overrides DrupalWebTestCase::setUp() Overrides TMGMTTestBase::setUp
TMGMTCartTest::testCartEnforceSourceLanguage function Test if the source is able to pull content in requested language.
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.