function ContentTmgmtEntitySourceListTest::testTermBundleFilter

Tests that the term bundle filter works.

File

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

Class

ContentTmgmtEntitySourceListTest
Tests the user interface for entity translation lists.

Namespace

Drupal\Tests\tmgmt_content\Functional

Code

function testTermBundleFilter() {
  $vocabulary1 = Vocabulary::create([
    'vid' => 'vocab1',
    'name' => $this
      ->randomMachineName(),
  ]);
  $vocabulary1
    ->save();
  $term1 = Term::create([
    'name' => $this
      ->randomMachineName(),
    'vid' => $vocabulary1
      ->id(),
  ]);
  $term1
    ->save();
  $vocabulary2 = Vocabulary::create([
    'vid' => 'vocab2',
    'name' => $this
      ->randomMachineName(),
  ]);
  $vocabulary2
    ->save();
  $term2 = Term::create([
    'name' => $this
      ->randomMachineName(),
    'vid' => $vocabulary2
      ->id(),
  ]);
  $term2
    ->save();
  $content_translation_manager = \Drupal::service('content_translation.manager');
  $content_translation_manager
    ->setEnabled('taxonomy_term', $vocabulary1
    ->id(), TRUE);
  $content_translation_manager
    ->setEnabled('taxonomy_term', $vocabulary2
    ->id(), TRUE);
  $this
    ->drupalGet('admin/tmgmt/sources/content/taxonomy_term');

  // Both terms should be displayed with their bundle.
  $this
    ->assertSession()
    ->pageTextContains($term1
    ->label());
  $this
    ->assertSession()
    ->pageTextContains($term2
    ->label());
  $this
    ->assertNotEmpty($this
    ->xpath('//td[text()=@vocabulary]', array(
    '@vocabulary' => $vocabulary1
      ->label(),
  )));
  $this
    ->assertNotEmpty($this
    ->xpath('//td[text()=@vocabulary]', array(
    '@vocabulary' => $vocabulary2
      ->label(),
  )));

  // Limit to the first vocabulary.
  $edit = array();
  $edit['search[vid]'] = $vocabulary1
    ->id();
  $this
    ->submitForm($edit, 'Search');

  // Only term 1 should be displayed now.
  $this
    ->assertSession()
    ->pageTextContains($term1
    ->label());
  $this
    ->assertSession()
    ->pageTextNotContains($term2
    ->label());
  $this
    ->assertNotEmpty($this
    ->xpath('//td[text()=@vocabulary]', array(
    '@vocabulary' => $vocabulary1
      ->label(),
  )));
  $this
    ->assertEmpty($this
    ->xpath('//td[text()=@vocabulary]', array(
    '@vocabulary' => $vocabulary2
      ->label(),
  )));
}