Commit cd15c2a7 authored by webchick's avatar webchick
Browse files

Missing tests. I bet it'll work better now.

parent e6a4819e
<?php
/**
* @file
* Definition of Drupal\language\Tests\LanguageCustomConfigurationTest.
*/
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() {
global $base_url;
// 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',
);
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
// Test validation on missing values.
$this->assertText(t('!name field is required.', array('!name' => t('Language code'))));
$this->assertText(t('!name field is required.', array('!name' => t('Language name'))));
$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>',
'direction' => LANGUAGE_LTR,
);
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
$this->assertRaw(t('%field may only contain characters a-z, underscores, or hyphens.', array('%field' => t('Language code'))));
$this->assertRaw(t('%field cannot contain any markup.', array('%field' => t('Language name'))));
$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',
'direction' => LANGUAGE_LTR,
);
// Add the language the first time.
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
$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.
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
$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.');
}
}
<?php
/**
* @file
* Definition of Drupal\locale\TranslationStream.
*/
namespace Drupal\locale;
use Drupal\Core\StreamWrapper\LocalStream;
/**
* Defines a Drupal translations (translations://) stream wrapper class.
*
* Provides support for storing translation files.
*/
class TranslationsStream extends LocalStream {
/**
* Implements Drupal\Core\StreamWrapper\LocalStream::getDirectoryPath()
*/
function getDirectoryPath() {
return variable_get('locale_translate_file_directory',
conf_path() . '/files/translations');
}
/**
* Implements Drupal\Core\StreamWrapper\StreamWrapperInterface::getExternalUrl().
* @throws \LogicException PO files URL should not be public.
*/
function getExternalUrl() {
throw new \LogicException('PO files URL should not be public.');
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment