VocabularyLanguageTest.php 2.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
<?php

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

namespace Drupal\taxonomy\Tests;

/**
 * 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);
  }

  function testVocabularyLanguage() {
    // Add first some custom languages.
    $language = (object) array(
      'langcode' => 'aa',
      'name' => $this->randomName(),
    );
    language_save($language);

    $language = (object) array(
      'langcode' => 'bb',
      'name' => $this->randomName(),
    );
    language_save($language);

    $this->drupalGet('admin/structure/taxonomy/add');
    // Check that we have the language selector available.
    $this->assertField('edit-langcode', t('The language selector field was found on the page'));

    // Create the vocabulary.
    $machine_name = drupal_strtolower($this->randomName());
    $edit['name'] = $this->randomName();
    $edit['description'] = $this->randomName();
    $edit['langcode'] = 'aa';
    $edit['machine_name'] = $machine_name;
    $this->drupalPost(NULL, $edit, t('Save'));

    // Check the language on the edit page.
    $this->drupalGet('admin/structure/taxonomy/' . $machine_name . '/edit');
    $this->assertOptionSelected('edit-langcode', $edit['langcode'], t('The vocabulary language was correctly selected.'));

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

    // Check again the language on the edit page.
    $this->drupalGet('admin/structure/taxonomy/' . $machine_name . '/edit');
    $this->assertOptionSelected('edit-langcode', $edit['langcode'], t('The vocabulary language was correctly selected.'));
  }
}