You are here

function VocabularyLanguageTest::testVocabularyDefaultLanguageForTerms in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/taxonomy/src/Tests/VocabularyLanguageTest.php \Drupal\taxonomy\Tests\VocabularyLanguageTest::testVocabularyDefaultLanguageForTerms()

Tests term language settings for vocabulary terms are saved and updated.

File

core/modules/taxonomy/src/Tests/VocabularyLanguageTest.php, line 75
Contains \Drupal\taxonomy\Tests\VocabularyLanguageTest.

Class

VocabularyLanguageTest
Tests the language functionality for vocabularies.

Namespace

Drupal\taxonomy\Tests

Code

function testVocabularyDefaultLanguageForTerms() {

  // Add a new vocabulary and check that the default language settings are for
  // the terms are saved.
  $edit = array(
    'name' => $this
      ->randomMachineName(),
    'vid' => Unicode::strtolower($this
      ->randomMachineName()),
    'default_language[langcode]' => 'bb',
    'default_language[language_alterable]' => TRUE,
  );
  $vid = $edit['vid'];
  $this
    ->drupalPostForm('admin/structure/taxonomy/add', $edit, t('Save'));

  // Check that the vocabulary was actually created.
  $this
    ->drupalGet('admin/structure/taxonomy/manage/' . $edit['vid']);
  $this
    ->assertResponse(200, 'The vocabulary has been created.');

  // Check that the language settings were saved.
  $language_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $edit['vid']);
  $this
    ->assertEqual($language_settings
    ->getDefaultLangcode(), 'bb', 'The langcode was saved.');
  $this
    ->assertTrue($language_settings
    ->isLanguageAlterable(), 'The visibility setting was saved.');

  // Check that the correct options are selected in the interface.
  $this
    ->assertOptionSelected('edit-default-language-langcode', 'bb', 'The correct default language for the terms of this vocabulary is selected.');
  $this
    ->assertFieldChecked('edit-default-language-language-alterable', 'Show language selection option is checked.');

  // Edit the vocabulary and check that the new settings are updated.
  $edit = array(
    'default_language[langcode]' => 'aa',
    'default_language[language_alterable]' => FALSE,
  );
  $this
    ->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save'));

  // And check again the settings and also the interface.
  $language_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vid);
  $this
    ->assertEqual($language_settings
    ->getDefaultLangcode(), 'aa', 'The langcode was saved.');
  $this
    ->assertFalse($language_settings
    ->isLanguageAlterable(), 'The visibility setting was saved.');
  $this
    ->drupalGet('admin/structure/taxonomy/manage/' . $vid);
  $this
    ->assertOptionSelected('edit-default-language-langcode', 'aa', 'The correct default language for the terms of this vocabulary is selected.');
  $this
    ->assertNoFieldChecked('edit-default-language-language-alterable', 'Show language selection option is not checked.');

  // Check that language settings are changed after editing vocabulary.
  $edit = array(
    'name' => $this
      ->randomMachineName(),
    'default_language[langcode]' => 'authors_default',
    'default_language[language_alterable]' => FALSE,
  );
  $this
    ->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save'));

  // Check that we have the new settings.
  $new_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vid);
  $this
    ->assertEqual($new_settings
    ->getDefaultLangcode(), 'authors_default', 'The langcode was saved.');
  $this
    ->assertFalse($new_settings
    ->isLanguageAlterable(), 'The new visibility setting was saved.');
}