function ContentTmgmtEntitySourceUiTest::testCart

Test the entity source specific cart functionality.

File

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

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
    ->drupalGet('admin/tmgmt/sources/content/node');
  $this
    ->submitForm([
    'items[' . $nodes[1]
      ->id() . ']' => TRUE,
    'items[' . $nodes[2]
      ->id() . ']' => TRUE,
  ], 'Add to cart');
  $this
    ->drupalGet('admin/tmgmt/cart');
  $this
    ->assertSession()
    ->pageTextContains($nodes[1]
    ->getTitle());
  $this
    ->assertSession()
    ->pageTextContains($nodes[2]
    ->getTitle());

  // Test the translate tab.
  $this
    ->drupalGet('node/' . $nodes[3]
    ->id() . '/translations');
  $this
    ->assertSession()
    ->responseContains(t('There are @count items in the <a href=":url">translation cart</a>.', array(
    '@count' => 2,
    ':url' => Url::fromRoute('tmgmt.cart')
      ->toString(),
  )));
  $this
    ->submitForm([], 'Add to cart');
  $this
    ->assertSession()
    ->responseContains(t('@count content source was added into the <a href=":url">cart</a>.', array(
    '@count' => 1,
    ':url' => Url::fromRoute('tmgmt.cart')
      ->toString(),
  )));
  $this
    ->assertSession()
    ->responseContains(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
    ->assertSession()
    ->responseContains('<ul class="pager__items js-pager__items">');
  $this
    ->assertCount(5, $this
    ->xpath('//nav[@class="pager"]/ul[@class="pager__items js-pager__items"]/li/a'));
}