You are here

function ConfigSourceUiTest::testViewTranslateTabSingleCheckout in Translation Management Tool 8

Test the node type for a single checkout.

File

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

Class

ConfigSourceUiTest
Content entity source UI tests.

Namespace

Drupal\Tests\tmgmt_config\Functional

Code

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
    ->assertText(t('Translations of Content view'));
  $this
    ->assertText(t('There are 0 items in the translation cart.'));

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

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

  // Submit.
  $this
    ->drupalPostForm(NULL, array(), t('Submit to provider'));

  // Make sure that we're back on the originally defined destination URL.
  $this
    ->assertUrl('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
    ->drupalPostForm(NULL, array(), t('Save'));

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

  // Verify that we are on the checkout page.
  $this
    ->assertText(t('One job needs to be checked out.'));
  $this
    ->assertText('Content view (English to Spanish, Unprocessed)');
  $this
    ->drupalPostForm(NULL, array(), t('Submit to provider'));

  // Make sure that we're back on the originally defined destination URL.
  $this
    ->assertUrl('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
    ->drupalPostForm(NULL, array(), t('Save as completed'));
  $this
    ->assertText(t('@id of type @type does not exist, the job can not be completed.', array(
    '@id' => $view_content
      ->id(),
    '@type' => $view_content
      ->getEntityTypeId(),
  )));
}