You are here

public function TermTranslationUITest::testTranslateLinkVocabularyAdminPage in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/taxonomy/tests/src/Functional/TermTranslationUITest.php \Drupal\Tests\taxonomy\Functional\TermTranslationUITest::testTranslateLinkVocabularyAdminPage()
  2. 10 core/modules/taxonomy/tests/src/Functional/TermTranslationUITest.php \Drupal\Tests\taxonomy\Functional\TermTranslationUITest::testTranslateLinkVocabularyAdminPage()

Tests translate link on vocabulary term list.

File

core/modules/taxonomy/tests/src/Functional/TermTranslationUITest.php, line 109

Class

TermTranslationUITest
Tests the Term Translation UI.

Namespace

Drupal\Tests\taxonomy\Functional

Code

public function testTranslateLinkVocabularyAdminPage() {
  $this
    ->drupalLogin($this
    ->drupalCreateUser(array_merge(parent::getTranslatorPermissions(), [
    'access administration pages',
    'administer taxonomy',
  ])));
  $values = [
    'name' => $this
      ->randomMachineName(),
  ];
  $translatable_tid = $this
    ->createEntity($values, $this->langcodes[0], $this->vocabulary
    ->id());

  // Create an untranslatable vocabulary.
  $untranslatable_vocabulary = Vocabulary::create([
    'name' => 'untranslatable_voc',
    'description' => $this
      ->randomMachineName(),
    'vid' => 'untranslatable_voc',
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    'weight' => mt_rand(0, 10),
  ]);
  $untranslatable_vocabulary
    ->save();
  $values = [
    'name' => $this
      ->randomMachineName(),
  ];
  $untranslatable_tid = $this
    ->createEntity($values, $this->langcodes[0], $untranslatable_vocabulary
    ->id());

  // Verify translation links.
  $this
    ->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id() . '/overview');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertLinkByHref('term/' . $translatable_tid . '/translations', 0, 'The translations link exists for a translatable vocabulary.');
  $this
    ->assertLinkByHref('term/' . $translatable_tid . '/edit', 0, 'The edit link exists for a translatable vocabulary.');
  $this
    ->drupalGet('admin/structure/taxonomy/manage/' . $untranslatable_vocabulary
    ->id() . '/overview');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertLinkByHref('term/' . $untranslatable_tid . '/edit');
  $this
    ->assertNoLinkByHref('term/' . $untranslatable_tid . '/translations');
}