You are here

function ContentTmgmtEntitySourceUiTest::testCart in Translation Management Tool 8

Test the entity source specific cart functionality.

File

sources/content/tests/src/Functional/ContentTmgmtEntitySourceUiTest.php, line 567

Class

ContentTmgmtEntitySourceUiTest
Content entity source UI tests.

Namespace

Drupal\Tests\tmgmt_content\Functional

Code

function testCart() {
  $this
    ->loginAsTranslator(array(
    'translate any entity',
    'create content translations',
  ));
  $nodes = array();
  for ($i = 0; $i < 4; $i++) {
    $nodes[$i] = $this
      ->createTranslatableNode('page');
  }

  // Test the source overview.
  $this
    ->drupalPostForm('admin/tmgmt/sources/content/node', array(
    'items[' . $nodes[1]
      ->id() . ']' => TRUE,
    'items[' . $nodes[2]
      ->id() . ']' => TRUE,
  ), t('Add to cart'));
  $this
    ->drupalGet('admin/tmgmt/cart');
  $this
    ->assertText($nodes[1]
    ->getTitle());
  $this
    ->assertText($nodes[2]
    ->getTitle());

  // Test the translate tab.
  $this
    ->drupalGet('node/' . $nodes[3]
    ->id() . '/translations');
  $this
    ->assertRaw(t('There are @count items in the <a href=":url">translation cart</a>.', array(
    '@count' => 2,
    ':url' => Url::fromRoute('tmgmt.cart')
      ->toString(),
  )));
  $this
    ->drupalPostForm(NULL, array(), t('Add to cart'));
  $this
    ->assertRaw(t('@count content source was added into the <a href=":url">cart</a>.', array(
    '@count' => 1,
    ':url' => Url::fromRoute('tmgmt.cart')
      ->toString(),
  )));
  $this
    ->assertRaw(t('There are @count items in the <a href=":url">translation cart</a> including the current item.', array(
    '@count' => 3,
    ':url' => Url::fromRoute('tmgmt.cart')
      ->toString(),
  )));

  // Add nodes and assert that page footer is being shown.
  $nodes = array();
  for ($i = 0; $i < 50; $i++) {
    $nodes[$i] = $this
      ->createTranslatableNode('page');
  }
  $this
    ->drupalGet('admin/tmgmt/sources/content/node');
  $this
    ->assertRaw('<ul class="pager__items js-pager__items">');
  $this
    ->assertEqual(count($this
    ->xpath('//nav[@class="pager"]/ul[@class="pager__items js-pager__items"]/li/a')), 5);
}