Error message

  • Notice: Undefined property: stdClass::$preferred in _api_make_match_link() (line 1075 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).
  • Notice: Undefined property: stdClass::$preferred in _api_make_match_link() (line 1079 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).
  • 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 ConfigSourceUiTest

Content entity source UI tests.

@group tmgmt

Hierarchy

Expanded class hierarchy of ConfigSourceUiTest

File

sources/tmgmt_config/tests/src/Functional/ConfigSourceUiTest.php, line 16

Namespace

Drupal\Tests\tmgmt_config\Functional
View source
class ConfigSourceUiTest extends TMGMTTestBase {
  use TmgmtEntityTestTrait;

  /**
   * Modules to enable.
   *
   * @var array
   */
  protected static $modules = array(
    'tmgmt_config',
    'views',
    'views_ui',
    'field_ui',
    'config_translation',
  );

  /**
   * {@inheritdoc}
   */
  function setUp() : void {
    parent::setUp();
    $this
      ->loginAsAdmin(array(
      'create translation jobs',
      'submit translation jobs',
      'accept translation jobs',
    ));
    $this
      ->addLanguage('de');
    $this
      ->addLanguage('it');
    $this
      ->addLanguage('es');
    $this
      ->addLanguage('el');
    $this
      ->createNodeType('article', 'Article', TRUE);
  }

  /**
   * Test the node type for a single checkout.
   */
  function testNodeTypeTranslateTabSingleCheckout() {
    $this
      ->loginAsTranslator(array(
      'translate configuration',
    ));

    // Go to the translate tab.
    $this
      ->drupalGet('admin/structure/types/manage/article/translate');

    // Assert some basic strings on that page.
    $this
      ->assertSession()
      ->pageTextContains('Translations of Article content type');
    $this
      ->assertSession()
      ->pageTextContains('There are 0 items in the translation cart.');

    // Request a translation for german.
    $edit = array(
      'languages[de]' => TRUE,
    );
    $this
      ->submitForm($edit, 'Request translation');

    // Verify that we are on the translate tab.
    $this
      ->assertSession()
      ->pageTextContains('One job needs to be checked out.');
    $this
      ->assertSession()
      ->pageTextContains('Article content type (English to German, Unprocessed)');

    // Submit.
    $this
      ->submitForm([], 'Submit to provider');

    // Make sure that we're back on the originally defined destination URL.
    $this
      ->assertSession()
      ->addressEquals('admin/structure/types/manage/article/translate');

    // We are redirected back to the correct page.
    $this
      ->drupalGet('admin/structure/types/manage/article/translate');

    // Translated languages - german should now be listed as Needs review.
    $rows = $this
      ->xpath('//tbody/tr');
    $found = FALSE;
    foreach ($rows as $value) {
      $image = $value
        ->find('css', 'td:nth-child(3) a img');
      if ($image && $image
        ->getAttribute('title') == 'Needs review') {
        $found = TRUE;
        $this
          ->assertEquals('German', $value
          ->find('css', 'td:nth-child(2)')
          ->getText());
      }
    }
    $this
      ->assertTrue($found);

    // Assert that 'Source' label is displayed properly.
    $this
      ->assertSession()
      ->responseContains('<strong>Source</strong>');

    // Verify that the pending translation is shown.
    $this
      ->clickLinkWithImageTitle('Needs review');
    $this
      ->submitForm([], 'Save');

    // Request a spanish translation.
    $edit = array(
      'languages[es]' => TRUE,
    );
    $this
      ->submitForm($edit, 'Request translation');

    // Verify that we are on the checkout page.
    $this
      ->assertSession()
      ->pageTextContains('One job needs to be checked out.');
    $this
      ->assertSession()
      ->pageTextContains('Article content type (English to Spanish, Unprocessed)');
    $this
      ->submitForm([], 'Submit to provider');

    // Make sure that we're back on the originally defined destination URL.
    $this
      ->assertSession()
      ->addressEquals('admin/structure/types/manage/article/translate');

    // Translated languages should now be listed as Needs review.
    $rows = $this
      ->xpath('//tbody/tr');
    $counter = 0;
    foreach ($rows as $element) {
      $language = $element
        ->find('css', 'td:nth-child(2)')
        ->getText();
      if ('Spanish' == $language || 'German' == $language) {
        $this
          ->assertEquals('Needs review', $element
          ->find('css', 'td:nth-child(3) a img')
          ->getAttribute('title'));
        $counter++;
      }
    }
    $this
      ->assertEquals(2, $counter);

    // Test that a job can not be accepted if the translator does not exist.
    // Request an italian translation.
    $edit = array(
      'languages[it]' => TRUE,
    );
    $this
      ->submitForm($edit, 'Request translation');

    // Go back to the originally defined destination URL without submitting.
    $this
      ->drupalGet('admin/structure/types/manage/article/translate');

    // Verify that the pending translation is shown.
    $this
      ->clickLink('Inactive');

    // Try to save, should fail because the job has no translator assigned.
    $edit = array(
      'name[translation]' => $this
        ->randomMachineName(),
    );
    $this
      ->submitForm($edit, 'Save');

    // Verify that we are on the checkout page.
    $this
      ->assertSession()
      ->statusCodeEquals(200);
  }

  /**
   * Test the node type for a single checkout.
   */
  function testNodeTypeTranslateTabMultipeCheckout() {
    $this
      ->loginAsTranslator(array(
      'translate configuration',
    ));

    // Go to the translate tab.
    $this
      ->drupalGet('admin/structure/types/manage/article/translate');

    // Assert some basic strings on that page.
    $this
      ->assertSession()
      ->pageTextContains('Translations of Article content type');
    $this
      ->assertSession()
      ->pageTextContains('There are 0 items in the translation cart.');

    // Request a translation for german and spanish.
    $edit = array(
      'languages[de]' => TRUE,
      'languages[es]' => TRUE,
    );
    $this
      ->submitForm($edit, 'Request translation');

    // Verify that we are on the translate tab.
    $this
      ->assertSession()
      ->pageTextContains('2 jobs need to be checked out.');

    // Submit all jobs.
    $this
      ->assertSession()
      ->pageTextContains('Article content type (English to German, Unprocessed)');
    $this
      ->submitForm([], 'Submit to provider and continue');
    $this
      ->assertSession()
      ->pageTextContains('Article content type (English to Spanish, Unprocessed)');
    $this
      ->submitForm([], 'Submit to provider');

    // Make sure that we're back on the translate tab.
    $this
      ->assertSession()
      ->addressEquals('admin/structure/types/manage/article/translate');
    $this
      ->assertSession()
      ->pageTextContains('Test translation created.');
    $this
      ->assertSession()
      ->pageTextNotContains(t('The translation of @title to @language is finished and can now be reviewed.', array(
      '@title' => 'Article',
      '@language' => t('Spanish'),
    )));

    // Translated languages should now be listed as Needs review.
    $rows = $this
      ->xpath('//tbody/tr');
    $counter = 0;
    foreach ($rows as $element) {
      $language = $element
        ->find('css', 'td:nth-child(2)')
        ->getText();
      if ('Spanish' == $language || 'German' == $language) {
        $this
          ->assertEquals('Needs review', $element
          ->find('css', 'td:nth-child(3) a img')
          ->getAttribute('title'));
        $counter++;
      }
    }
    $this
      ->assertEquals(2, $counter);
  }

  /**
   * Test the node type for a single checkout.
   */
  function testViewTranslateTabSingleCheckout() {
    $this
      ->loginAsTranslator(array(
      'translate configuration',
    ));

    // Go to the translate tab.
    $this
      ->drupalGet('admin/structure/views/view/content/translate');

    // Assert some basic strings on that page.
    $this
      ->assertSession()
      ->pageTextContains('Translations of Content view');
    $this
      ->assertSession()
      ->pageTextContains('There are 0 items in the translation cart.');

    // Request a translation for german.
    $edit = array(
      'languages[de]' => TRUE,
    );
    $this
      ->submitForm($edit, 'Request translation');

    // Verify that we are on the translate tab.
    $this
      ->assertSession()
      ->pageTextContains('One job needs to be checked out.');
    $this
      ->assertSession()
      ->pageTextContains('Content view (English to German, Unprocessed)');

    // Submit.
    $this
      ->submitForm([], 'Submit to provider');

    // Make sure that we're back on the originally defined destination URL.
    $this
      ->assertSession()
      ->addressEquals('admin/structure/views/view/content/translate');

    // We are redirected back to the correct page.
    $this
      ->drupalGet('admin/structure/views/view/content/translate');

    // Translated languages should now be listed as Needs review.
    $rows = $this
      ->xpath('//tbody/tr');
    foreach ($rows as $element) {
      if ($element
        ->find('css', 'td:nth-child(2)')
        ->getText() == 'German') {
        $this
          ->assertEquals('Needs review', $element
          ->find('css', 'td:nth-child(3) a img')
          ->getAttribute('title'));
      }
    }

    // Verify that the pending translation is shown.
    $this
      ->clickLinkWithImageTitle('Needs review');
    $this
      ->submitForm([], 'Save');

    // Request a spanish translation.
    $edit = array(
      'languages[es]' => TRUE,
    );
    $this
      ->submitForm($edit, 'Request translation');

    // Verify that we are on the checkout page.
    $this
      ->assertSession()
      ->pageTextContains('One job needs to be checked out.');
    $this
      ->assertSession()
      ->pageTextContains('Content view (English to Spanish, Unprocessed)');
    $this
      ->submitForm([], 'Submit to provider');

    // Make sure that we're back on the originally defined destination URL.
    $this
      ->assertSession()
      ->addressEquals('admin/structure/views/view/content/translate');

    // Translated languages should now be listed as Needs review.
    $rows = $this
      ->xpath('//tbody/tr');
    $counter = 0;
    foreach ($rows as $element) {
      $language = $element
        ->find('css', 'td:nth-child(2)')
        ->getText();
      if ('Spanish' == $language || 'German' == $language) {
        $this
          ->assertEquals('Needs review', $element
          ->find('css', 'td:nth-child(3) a img')
          ->getAttribute('title'));
        $counter++;
      }
    }
    $this
      ->assertEquals(2, $counter);

    // Test that a job can not be accepted if the entity does not exist.
    $this
      ->clickLinkWithImageTitle('Needs review');

    // Delete the view  and assert that the job can not be accepted.
    $view_content = View::load('content');
    $view_content
      ->delete();
    $this
      ->submitForm([], 'Save as completed');
    $this
      ->assertSession()
      ->pageTextContains(t('@id of type @type does not exist, the job can not be completed.', array(
      '@id' => $view_content
        ->id(),
      '@type' => $view_content
        ->getEntityTypeId(),
    )));
  }

  /**
   * Test the field config entity type for a single checkout.
   */
  function testFieldConfigTranslateTabSingleCheckout() {
    $this
      ->loginAsAdmin(array(
      'translate configuration',
    ));

    // Add a continuous job.
    $job = $this
      ->createJob('en', 'de', 1, [
      'job_type' => Job::TYPE_CONTINUOUS,
    ]);
    $job
      ->save();

    // Go to sources, field configuration list.
    $this
      ->drupalGet('admin/tmgmt/sources/config/field_config');
    $this
      ->assertSession()
      ->pageTextContains('Configuration ID');
    $this
      ->assertSession()
      ->pageTextContains('field.field.node.article.body');
    $edit = [
      'items[field.field.node.article.body]' => TRUE,
    ];
    $this
      ->submitForm($edit, 'Add to cart');
    $this
      ->clickLink('cart');
    $this
      ->assertSession()
      ->pageTextContains('Body');
    $edit = [
      'target_language[]' => 'de',
    ];
    $this
      ->submitForm($edit, 'Request translation');

    // Assert that we cannot add config entities into continuous jobs.
    $this
      ->assertSession()
      ->pageTextNotContains('Check for continuous jobs');
    $this
      ->assertSession()
      ->fieldNotExists('add_all_to_continuous_jobs');

    // Go to the translate tab.
    $this
      ->drupalGet('admin/structure/types/manage/article/fields/node.article.body/translate');

    // Request a german translation.
    $this
      ->submitForm([
      'languages[de]' => TRUE,
    ], 'Request translation');

    // Verify that we are on the checkout page.
    $this
      ->assertSession()
      ->statusCodeEquals(200);
    $this
      ->assertSession()
      ->pageTextContains('One job needs to be checked out.');
    $this
      ->submitForm([], 'Submit to provider');

    // Verify that the pending translation is shown.
    $this
      ->clickLinkWithImageTitle('Needs review');
    $this
      ->submitForm([], 'Save as completed');
  }

  /**
   * Test the entity source specific cart functionality.
   */
  function testCart() {
    $this
      ->loginAsTranslator(array(
      'translate configuration',
    ));

    // Test the source overview.
    $this
      ->drupalGet('admin/structure/views/view/content/translate');
    $this
      ->submitForm([], 'Add to cart');
    $this
      ->drupalGet('admin/structure/types/manage/article/translate');
    $this
      ->submitForm([], 'Add to cart');

    // Test if the content and article are in the cart.
    $this
      ->drupalGet('admin/tmgmt/cart');
    $this
      ->assertSession()
      ->linkExists('Content view');
    $this
      ->assertSession()
      ->linkExists('Article content type');

    // Test the label on the source overivew.
    $this
      ->drupalGet('admin/structure/views/view/content/translate');
    $this
      ->assertSession()
      ->responseContains(t('There are @count items in the <a href=":url">translation cart</a> including the current item.', array(
      '@count' => 2,
      ':url' => Url::fromRoute('tmgmt.cart')
        ->toString(),
    )));
  }

  /**
   * Test the node type for a single checkout.
   */
  function testSimpleConfiguration() {
    $this
      ->loginAsTranslator(array(
      'translate configuration',
    ));

    // Go to the translate tab.
    $this
      ->drupalGet('admin/config/system/site-information/translate');

    // Assert some basic strings on that page.
    $this
      ->assertSession()
      ->pageTextContains('Translations of System information');

    // Request a translation for german.
    $edit = array(
      'languages[de]' => TRUE,
    );
    $this
      ->submitForm($edit, 'Request translation');

    // Verify that we are on the translate tab.
    $this
      ->assertSession()
      ->pageTextContains('One job needs to be checked out.');
    $this
      ->assertSession()
      ->pageTextContains('System information (English to German, Unprocessed)');

    // Submit.
    $this
      ->submitForm([], 'Submit to provider');

    // Make sure that we're back on the originally defined destination URL.
    $this
      ->assertSession()
      ->addressEquals('admin/config/system/site-information/translate');

    // We are redirected back to the correct page.
    $this
      ->drupalGet('admin/config/system/site-information/translate');

    // Translated languages should now be listed as Needs review.
    $rows = $this
      ->xpath('//tbody/tr');
    $found = FALSE;
    foreach ($rows as $value) {
      $image = $value
        ->find('css', 'td:nth-child(3) a img');
      if ($image && $image
        ->getAttribute('title') == 'Needs review') {
        $found = TRUE;
        $this
          ->assertEquals('German', $value
          ->find('css', 'td:nth-child(2)')
          ->getText());
      }
    }
    $this
      ->assertTrue($found);

    // Verify that the pending translation is shown.
    $this
      ->clickLinkWithImageTitle('Needs review');
    $this
      ->submitForm([
      'name[translation]' => 'de_Druplicon',
    ], 'Save');
    $this
      ->clickLinkWithImageTitle('Needs review');
    $this
      ->assertSession()
      ->pageTextContains('de_Druplicon');
    $this
      ->submitForm([], 'Save');

    // Request a spanish translation.
    $edit = array(
      'languages[es]' => TRUE,
    );
    $this
      ->submitForm($edit, 'Request translation');

    // Verify that we are on the checkout page.
    $this
      ->assertSession()
      ->pageTextContains('One job needs to be checked out.');
    $this
      ->assertSession()
      ->pageTextContains('System information (English to Spanish, Unprocessed)');
    $this
      ->submitForm([], 'Submit to provider');

    // Make sure that we're back on the originally defined destination URL.
    $this
      ->assertSession()
      ->addressEquals('admin/config/system/site-information/translate');

    // Translated languages should now be listed as Needs review.
    $rows = $this
      ->xpath('//tbody/tr');
    $counter = 0;
    foreach ($rows as $value) {
      $image = $value
        ->find('css', 'td:nth-child(3) a img');
      if ($image && $image
        ->getAttribute('title') == 'Needs review') {
        $this
          ->assertTrue(in_array($value
          ->find('css', 'td:nth-child(2)')
          ->getText(), [
          'Spanish',
          'German',
        ]));
        $counter++;
      }
    }
    $this
      ->assertEquals(2, $counter);

    // Test translation and validation tags of account settings.
    $this
      ->drupalGet('admin/config/people/accounts/translate');
    $this
      ->submitForm([
      'languages[de]' => TRUE,
    ], 'Request translation');

    // Submit.
    $this
      ->submitForm([], 'Submit to provider');
    $this
      ->clickLinkWithImageTitle('Needs review');
    $this
      ->submitForm([
      'user__settings|anonymous[translation]' => 'de_Druplicon',
    ], 'Validate HTML tags');
    $this
      ->assertSession()
      ->pageTextContains('de_Druplicon');
    $this
      ->submitForm([], 'Save');
    $this
      ->clickLinkWithImageTitle('Needs review');
    $this
      ->assertSession()
      ->pageTextContains('de_Druplicon');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigSourceUiTest::$modules protected static property Modules to enable. Overrides TMGMTTestBase::$modules
ConfigSourceUiTest::setUp function Overrides DrupalWebTestCase::setUp() Overrides TMGMTTestBase::setUp
ConfigSourceUiTest::testCart function Test the entity source specific cart functionality.
ConfigSourceUiTest::testFieldConfigTranslateTabSingleCheckout function Test the field config entity type for a single checkout.
ConfigSourceUiTest::testNodeTypeTranslateTabMultipeCheckout function Test the node type for a single checkout.
ConfigSourceUiTest::testNodeTypeTranslateTabSingleCheckout function Test the node type for a single checkout.
ConfigSourceUiTest::testSimpleConfiguration function Test the node type for a single checkout.
ConfigSourceUiTest::testViewTranslateTabSingleCheckout function Test the node type for a single checkout.
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.