function ContentTmgmtEntitySourceListTest::testNodeEntityListings

File

sources/content/tests/src/Functional/ContentTmgmtEntitySourceListTest.php, line 298

Class

ContentTmgmtEntitySourceListTest
Tests the user interface for entity translation lists.

Namespace

Drupal\Tests\tmgmt_content\Functional

Code

function testNodeEntityListings() {

  // Turn off the entity translation.
  $content_translation_manager = \Drupal::service('content_translation.manager');
  $content_translation_manager
    ->setEnabled('node', 'article', FALSE);
  $content_translation_manager
    ->setEnabled('node', 'page', FALSE);

  // Check if we have appropriate message in case there are no entity
  // translatable content types.
  $this
    ->drupalGet('admin/tmgmt/sources/content/node');
  $this
    ->assertSession()
    ->pageTextContains('Entity translation is not enabled for any of existing content types. To use this functionality go to Content types administration and enable entity translation for desired content types.');

  // Turn on the entity translation for both - article and page - to test
  // search form.
  $content_translation_manager
    ->setEnabled('node', 'article', TRUE);
  $content_translation_manager
    ->setEnabled('node', 'page', TRUE);

  // Create page node after entity translation is enabled.
  $page_node_translatable = $this
    ->createTranslatableNode('page');
  $this
    ->drupalGet('admin/tmgmt/sources/content/node');

  // We have both listed - one of articles and page.
  $this
    ->assertSession()
    ->pageTextContains($this->nodes['article']['en'][0]
    ->label());
  $this
    ->assertSession()
    ->pageTextContains($page_node_translatable
    ->label());

  // Try the search by content type.
  $edit = array();
  $edit['search[type]'] = 'article';
  $this
    ->submitForm($edit, 'Search');

  // There should be article present.
  $this
    ->assertSession()
    ->pageTextContains($this->nodes['article']['en'][0]
    ->label());

  // The page node should not be listed.
  $this
    ->assertSession()
    ->pageTextNotContains($page_node_translatable
    ->label());

  // Try cancel button - despite we do post content type search value
  // we should get nodes of botch content types.
  $this
    ->drupalGet('admin/tmgmt/sources/content/node');
  $this
    ->submitForm($edit, 'Cancel');
  $this
    ->assertSession()
    ->pageTextContains($this->nodes['article']['en'][0]
    ->label());
  $this
    ->assertSession()
    ->pageTextContains($page_node_translatable
    ->label());

  // Ensure that the pager limit works as expected if there are translations
  // and revisions.
  $this
    ->config('tmgmt.settings')
    ->set('source_list_limit', 8)
    ->save();
  $translation = $this->nodes['article']['de'][0]
    ->addTranslation('en', $this->nodes['article']['de'][0]
    ->toArray());
  $translation
    ->setNewRevision(TRUE);
  $translation
    ->save();
  $this
    ->drupalGet('admin/tmgmt/sources/content/node');
  $this
    ->assertSession()
    ->linkNotExists('Next');
  $this
    ->config('tmgmt.settings')
    ->set('source_list_limit', 4)
    ->save();
  $this
    ->drupalGet('admin/tmgmt/sources/content/node');
  $this
    ->assertSession()
    ->linkExists('Next');
  $this
    ->assertSession()
    ->linkExists('Go to page 2');
  $this
    ->assertSession()
    ->linkNotExists('Go to page 3');
}