LanguageCustomLanguageConfigurationTest.php 3.46 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\language\Tests\LanguageCustomConfigurationTest.
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
 */

namespace Drupal\language\Tests;

use Drupal\simpletest\WebTestBase;
use Drupal\Core\Language\Language;

/**
 * Functional tests for language configuration.
 */
class LanguageCustomLanguageConfigurationTest extends WebTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array('language');

  public static function getInfo() {
    return array(
      'name' => 'Custom Language configuration',
      'description' => 'Adds and configures custom languages.',
      'group' => 'Language',
    );
  }

  /**
   * Functional tests for adding, editing and deleting languages.
   */
  public function testLanguageConfiguration() {

    // Create user with permissions to add and remove languages.
    $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
    $this->drupalLogin($admin_user);

    // Add custom language.
    $edit = array(
      'predefined_langcode' => 'custom',
    );
46
    $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
47 48
    // Test validation on missing values.
    $this->assertText(t('!name field is required.', array('!name' => t('Language code'))));
49
    $this->assertText(t('!name field is required.', array('!name' => t('Language name in English'))));
50 51 52 53 54 55 56 57 58
    $empty_language = new Language();
    $this->assertFieldChecked('edit-direction-' . $empty_language->direction, 'Consistent usage of language direction.');
    $this->assertEqual($this->getUrl(), url('admin/config/regional/language/add', array('absolute' => TRUE)), 'Correct page redirection.');

    // Test validation of invalid values.
    $edit = array(
      'predefined_langcode' => 'custom',
      'langcode' => 'white space',
      'name' => '<strong>evil markup</strong>',
59
      'direction' => Language::DIRECTION_LTR,
60
    );
61
    $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
62
    $this->assertRaw(t('%field may only contain characters a-z, underscores, or hyphens.', array('%field' => t('Language code'))));
63
    $this->assertRaw(t('%field cannot contain any markup.', array('%field' => t('Language name in English'))));
64 65 66 67 68 69 70
    $this->assertEqual($this->getUrl(), url('admin/config/regional/language/add', array('absolute' => TRUE)), 'Correct page redirection.');

    // Test validation of existing language values.
    $edit = array(
      'predefined_langcode' => 'custom',
      'langcode' => 'de',
      'name' => 'German',
71
      'direction' => Language::DIRECTION_LTR,
72 73 74
    );

    // Add the language the first time.
75
    $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
76 77 78 79 80 81 82
    $this->assertRaw(t(
      'The language %language has been created and can now be used.',
      array('%language' => $edit['name'])
    ));
    $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');

    // Add the language a second time and confirm that this is not allowed.
83
    $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
84 85 86 87 88 89 90
    $this->assertRaw(t(
      'The language %language (%langcode) already exists.',
      array('%language' => $edit['name'], '%langcode' => $edit['langcode'])
    ));
    $this->assertEqual($this->getUrl(), url('admin/config/regional/language/add', array('absolute' => TRUE)), 'Correct page redirection.');
  }
}