VocabularyLanguageTest.php 5 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

/**
 * @file
 * Definition of Drupal\taxonomy\Tests\VocabularyLanguageTest.
 */

namespace Drupal\taxonomy\Tests;

10 11
use Drupal\Core\Language\Language;

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/**
 * Tests for the language feature on vocabularies.
 */
class VocabularyLanguageTest extends TaxonomyTestBase {

  public static $modules = array('language');

  public static function getInfo() {
    return array(
      'name' => 'Vocabulary language',
      'description' => 'Tests the language functionality for vocabularies.',
      'group' => 'Taxonomy',
    );
  }

  function setUp() {
    parent::setUp();

    // Create an administrative user.
    $this->admin_user = $this->drupalCreateUser(array('administer taxonomy'));
    $this->drupalLogin($this->admin_user);

34
    // Add some custom languages.
35
    $language = new Language(array(
36 37
      'langcode' => 'aa',
      'name' => $this->randomName(),
38
    ));
39 40
    language_save($language);

41
    $language = new Language(array(
42 43
      'langcode' => 'bb',
      'name' => $this->randomName(),
44
    ));
45
    language_save($language);
46
  }
47

48 49 50 51
  /**
   * Tests language settings for vocabularies.
   */
  function testVocabularyLanguage() {
52
    $this->drupalGet('admin/structure/taxonomy/add');
53

54
    // Check that we have the language selector available.
55
    $this->assertField('edit-langcode', 'The language selector field was found on the page');
56 57

    // Create the vocabulary.
58
    $vid = drupal_strtolower($this->randomName());
59 60 61
    $edit['name'] = $this->randomName();
    $edit['description'] = $this->randomName();
    $edit['langcode'] = 'aa';
62
    $edit['vid'] = $vid;
63 64 65
    $this->drupalPost(NULL, $edit, t('Save'));

    // Check the language on the edit page.
66 67
    $this->drupalGet('admin/structure/taxonomy/' . $vid . '/edit');
    $this->assertOptionSelected('edit-langcode', $edit['langcode'], 'The vocabulary language was correctly selected.');
68 69 70

    // Change the language and save again.
    $edit['langcode'] = 'bb';
71
    unset($edit['vid']);
72 73 74
    $this->drupalPost(NULL, $edit, t('Save'));

    // Check again the language on the edit page.
75 76
    $this->drupalGet('admin/structure/taxonomy/' . $vid . '/edit');
    $this->assertOptionSelected('edit-langcode', $edit['langcode'], 'The vocabulary language was correctly selected.');
77
  }
78 79 80 81 82 83 84 85 86

  /**
   * Tests term language settings for vocabulary terms are saved and updated.
   */
  function testVocabularyDefaultLanguageForTerms() {
    // Add a new vocabulary and check that the default language settings are for
    // the terms are saved.
    $edit = array(
      'name' => $this->randomName(),
87
      'vid' => drupal_strtolower($this->randomName()),
88
      'default_language[langcode]' => 'bb',
89
      'default_language[language_show]' => TRUE,
90
    );
91
    $vid = $edit['vid'];
92 93 94
    $this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));

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

    // Check that the language settings were saved.
99
    $language_settings = language_get_default_configuration('taxonomy_term', $edit['vid']);
100
    $this->assertEqual($language_settings['langcode'], 'bb');
101
    $this->assertEqual($language_settings['language_show'], TRUE);
102 103 104

    // 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.');
105
    $this->assertFieldChecked('edit-default-language-language-show', 'Show language selection option is checked.');
106 107 108 109

    // Edit the vocabulary and check that the new settings are updated.
    $edit = array(
      'default_language[langcode]' => 'aa',
110
      'default_language[language_show]' => FALSE,
111
    );
112
    $this->drupalPost('admin/structure/taxonomy/' . $vid . '/edit', $edit, t('Save'));
113 114

    // And check again the settings and also the interface.
115
    $language_settings = language_get_default_configuration('taxonomy_term', $vid);
116
    $this->assertEqual($language_settings['langcode'], 'aa');
117
    $this->assertEqual($language_settings['language_show'], FALSE);
118

119
    $this->drupalGet('admin/structure/taxonomy/' . $vid . '/edit');
120
    $this->assertOptionSelected('edit-default-language-langcode', 'aa', 'The correct default language for the terms of this vocabulary is selected.');
121
    $this->assertNoFieldChecked('edit-default-language-language-show', 'Show language selection option is not checked.');
122

123 124 125
    // Check that language settings are changed after editing vocabulary.
    $edit = array(
      'name' => $this->randomName(),
126
      'default_language[langcode]' => 'authors_default',
127
      'default_language[language_show]' => FALSE,
128
    );
129
    $this->drupalPost('admin/structure/taxonomy/' . $vid . '/edit', $edit, t('Save'));
130 131

    // Check that we have the new settings.
132
    $new_settings = language_get_default_configuration('taxonomy_term', $vid);
133
    $this->assertEqual($new_settings['langcode'], 'authors_default');
134
    $this->assertEqual($new_settings['language_show'], FALSE);
135
  }
136
}