i18n_menu_hierarchy.test in Language Hierarchy 7
Tests for Menu Translation Hierarchy module.
File
modules/i18n_menu_hierarchy/tests/i18n_menu_hierarchy.testView source
<?php
/**
* @file
* Tests for Menu Translation Hierarchy module.
*/
/**
* Base class for Menu Translation Hierarchy module tests.
*/
abstract class MenuTranslationHierarchyBaseTestCase extends LanguageHierarchyBaseTestCase {
protected $admin_user_permissions = array(
'bypass node access',
'administer nodes',
'administer languages',
'administer content types',
'administer blocks',
'access administration pages',
'administer site configuration',
'administer menu',
);
protected $translator_user_permissions = array(
'translate interface',
'translate user-defined strings',
);
/**
* Helper function to create a menu.
*/
function createMenu($edit = array()) {
$edit += array(
'title' => $this
->randomName(),
'menu_name' => substr(hash('sha256', $this
->randomName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI),
'language' => LANGUAGE_NONE,
);
$this
->drupalPost('admin/structure/menu/add', $edit, t('Save'));
return menu_load('menu-' . $edit['menu_name']);
}
/**
* Helper function to create a menu link.
*/
function createMenuLink($item = array()) {
// Set defaults.
// Note: default language is 'und'.
$item += array(
'link_title' => $this
->randomName(),
'link_path' => '<front>',
'customized' => TRUE,
);
return menu_link_load(menu_link_save($item));
}
/**
* Helper function to create a translation set.
*/
function createMenuLinkTranslationSet($edit = array()) {
$edit += array(
'title' => $this
->randomName(16),
);
$this
->drupalPost('admin/structure/menu/manage/translation/add', $edit, t('Save'));
// Load translation set entity.
$entity = entity_load('i18n_translation', FALSE, array(
'title' => $edit['title'],
), TRUE);
if (empty($entity)) {
$this
->fail('Could not create a translation set.', 'i18n_translation');
return FALSE;
}
return reset($entity);
}
}
/**
* Functional tests for entity translation.
*/
class MenuTranslationHierarchyWebTestCase extends MenuTranslationHierarchyBaseTestCase {
public static function getInfo() {
return array(
'name' => 'Menu Translation Hierarchy',
'description' => 'Test entity translations inheritance when viewing entity.',
'group' => 'Language Hierarchy',
);
}
function setUp() {
parent::setUp(array(
'i18n_menu_hierarchy',
));
$this
->loginAdminUser();
$this
->addLanguages();
$this
->enableUrlLanguageDetection(LANGUAGE_TYPE_INTERFACE);
}
function testMenuTranslateLocalize() {
// Test filtering for menu blocks.
$menu = $this
->createMenu(array(
'i18n_mode' => I18N_MODE_MULTIPLE,
));
$neutral_item = $this
->createMenuLink(array(
'menu_name' => $menu['menu_name'],
));
$en_item = $this
->createMenuLink(array(
'menu_name' => $menu['menu_name'],
'language' => 'en',
));
$pt_item = $this
->createMenuLink(array(
'menu_name' => $menu['menu_name'],
'language' => 'pt',
));
$pt_pt_item = $this
->createMenuLink(array(
'menu_name' => $menu['menu_name'],
'language' => 'pt-br',
));
$block['title'] = $menu['title'];
$block['module'] = 'menu';
$block['delta'] = $menu['menu_name'];
$this
->moveBlockToRegion($block, 'sidebar_first');
// Test if languages are filtered.
$this
->get('en', '<front>');
$this
->assertText($neutral_item['link_title'], 'Neutral menu item found on English language.');
$this
->assertText($en_item['link_title'], 'English menu item found on English language.');
$this
->assertNoText($pt_item['link_title'], 'No Portuguese, International menu item found on English language.');
$this
->assertNoText($pt_pt_item['link_title'], 'No Portuguese, Brazil menu item found on English language.');
// Test if links are displayed when translation exists.
$this
->get('pt-br', '<front>');
$this
->assertText($neutral_item['link_title'], 'Neutral menu item found on Portuguese, Brazil language.');
$this
->assertNoText($en_item['link_title'], 'No English menu item found on English language.');
$this
->assertNoText($pt_item['link_title'], 'No Portuguese, International menu item found on Portuguese, Brazil language.');
$this
->assertText($pt_pt_item['link_title'], 'Portuguese, Brazil menu item found on Portuguese, Brazil language.');
// Test if links will be inherited from parent language since there is no links
// for Portuguese, Portugal language but they exists for parent Portuguese, International.
$this
->get('pt-pt', '<front>');
$this
->assertText($neutral_item['link_title'], 'Neutral menu item found on Portuguese, Portugal language.');
$this
->assertNoText($en_item['link_title'], 'No English menu item found on Portuguese, Portugal language.');
$this
->assertText($pt_item['link_title'], 'Portuguese, International menu item found on Portuguese, Portugal language.');
$this
->assertNoText($pt_pt_item['link_title'], 'No Portuguese, Brazil menu item found on Portuguese, Portugal language.');
}
}
Classes
Name | Description |
---|---|
MenuTranslationHierarchyBaseTestCase | Base class for Menu Translation Hierarchy module tests. |
MenuTranslationHierarchyWebTestCase | Functional tests for entity translation. |