View source
<?php
require_once 'drupal_i18n_test_case.php';
class i18n_API_Tests extends Drupali18nTestCase {
function getInfo() {
return array(
'name' => 'Internationalization API',
'group' => 'Internationalization',
'description' => 'Internationalization API functions',
);
}
function setUp() {
parent::setUp('i18n', 'locale');
$this
->addLanguage('es');
$this
->addLanguage('de');
$this
->addLanguage('pt-br');
$user = $this
->drupalCreateUser(array(
'access comments',
'access content',
));
$this
->drupalLogin($user);
}
function testBasicAPI() {
$language_count = count(language_list());
$this
->assertTrue($language_count > 1, 'Multiple languages created: ' . $language_count);
$this
->assertEqual(i18n_get_lang(), 'en', 'Default language (en) properly set.');
foreach (language_list() as $lang) {
i18n_variable_set('site_name', "Drupal-{$lang->name}", $lang->language);
}
variable_set('language_content_type_story', 1);
$neutral = $this
->drupalCreateNode(array(
'type' => 'story',
'promote' => 1,
));
$source = $this
->drupalCreateNode(array(
'type' => 'story',
'promote' => 1,
'language' => i18n_default_language(),
));
$translations = $this
->drupalCreateTranslations($source);
$this
->assertEqual(count($translations), $language_count, "Created {$language_count} {$source->type} translations.");
variable_set('i18n_selection_mode', 'simple');
foreach (language_list() as $lang) {
$this
->drupalGet('', array(
'language' => $lang,
));
$this
->assertText("Drupal-{$lang->name}", 'Checked translated site name: Drupal-' . $lang->name);
$display = array(
$translations[$lang->language],
$neutral,
);
$hide = $translations;
unset($hide[$lang->language]);
$this
->assertContent($display, $hide);
}
}
function assertContent($display, $hide = array()) {
$languages = language_list();
foreach ($display as $node) {
$name = $node->language ? $languages[$node->language]->name : 'Language neutral';
$this
->assertText($node->title, 'Content displayed for ' . $name);
}
foreach ($hide as $node) {
$name = $node->language ? $languages[$node->language]->name : 'Language neutral';
$this
->assertNoText($node->title, 'Content not displayed for ' . $name);
}
}
}