function TMGMTI18nStringSourceTestCase::testI18nStringSourceMenu in Translation Management Tool 7
File
- sources/
i18n_string/ tmgmt_i18n_string.test, line 144
Class
- TMGMTI18nStringSourceTestCase
- Basic i18n String Source tests.
Code
function testI18nStringSourceMenu() {
drupal_static_reset('_tmgmt_plugin_info');
drupal_static_reset('_tmgmt_plugin_controller');
// Test translation of a menu.
/////////////////////////////////////
$config = array(
'menu_name' => $this
->randomName(),
'title' => $this
->randomName(),
'description' => $this
->randomName(),
'i18n_mode' => I18N_MODE_MULTIPLE,
);
menu_save($config);
$menu = menu_load($config['menu_name']);
$source_text = $menu['title'];
$string_name = 'menu:menu:' . $menu['menu_name'];
// Create the new job and job item.
$job = $this
->createJob();
$job->translator = $this->translator->name;
$job->settings = array();
$item1 = $job
->addItem('i18n_string', 'menu', $string_name);
$this
->assertEqual(t('Menu'), $item1
->getSourceType());
$job
->requestTranslation();
/* @var $item TMGMTJobItem */
foreach ($job
->getItems() as $item) {
$this
->assertJobItemLangCodes($item, 'en', array(
'en',
));
$item
->acceptTranslation();
$this
->assertJobItemLangCodes($item, 'en', array(
'de',
'en',
));
}
$data = $item1
->getData();
$this
->assertEqual($data['menu:menu:' . $menu['menu_name'] . ':title']['#text'], $config['title']);
$this
->assertEqual($data['menu:menu:' . $menu['menu_name'] . ':description']['#text'], $config['description']);
// Check the structure of the imported data.
$this
->assertEqual($item1->item_id, $string_name, 'String is correctly saved');
// Check string translation.
$this
->assertEqual(i18n_string_translate($string_name . ':title', $source_text, array(
'langcode' => $job->target_language,
)), $job->target_language . '_' . $source_text);
// Test translation of a menu item.
/////////////////////////////////////
$source_text = $this
->randomName();
$menu_link = array(
'link_path' => '<front>',
'link_title' => $source_text,
// i18n_menu_link::get_title() uses the title, set that too.
'title' => $source_text,
'menu_name' => $menu['menu_name'],
'customized' => TRUE,
);
menu_link_save($menu_link);
$string_name = 'menu:item:' . $menu_link['mlid'];
// Create the new job and job item.
$job = $this
->createJob();
$job->translator = $this->translator->name;
$job->settings = array();
$item1 = $job
->addItem('i18n_string', 'menu_link', $string_name);
$this
->assertEqual(t('Menu link'), $item1
->getSourceType());
$job
->requestTranslation();
/* @var $item TMGMTJobItem */
foreach ($job
->getItems() as $item) {
$this
->assertJobItemLangCodes($item, 'en', array(
'en',
));
$item
->acceptTranslation();
$this
->assertJobItemLangCodes($item, 'en', array(
'de',
'en',
));
}
$data = $item1
->getData();
$this
->assertEqual($data[$string_name . ':title']['#text'], $source_text);
// Check the structure of the imported data.
$this
->assertEqual($item1->item_id, $string_name);
// Check string translation.
$this
->assertEqual(i18n_string_translate($string_name . ':title', $source_text, array(
'langcode' => $job->target_language,
)), $job->target_language . '_' . $source_text);
}