i18n_path.test 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * @file
  4. * Test case for multilingual menus.
  5. */
  6. class i18nPathTestCase extends Drupali18nTestCase {
  7. public static function getInfo() {
  8. return array(
  9. 'name' => 'Path translation',
  10. 'group' => 'Internationalization',
  11. 'description' => 'Path translation functions',
  12. );
  13. }
  14. function setUp() {
  15. parent::setUp('translation', 'i18n_path');
  16. parent::setUpLanguages(array('administer site configuration'));
  17. }
  18. function checkTranslationLink($path, $language, $method = 'assertRaw') {
  19. $this->{$method}($path, t('Found translation link. :language - :path', array(':language' => $language, ':path' => $path)));
  20. }
  21. function testPathTranslation() {
  22. $this->setUpContentType(array('type' => 'page', 'mode' => TRANSLATION_ENABLED));
  23. // Create 2 nodes in different languages.
  24. $first_title = $this->randomName(10);
  25. $first_body = $this->randomString(50);
  26. $first_node = $this->createNode('page', $first_title, $first_body, $this->default_language);
  27. $secondary_title = $this->randomName(10);
  28. $secondary_body = $this->randomString(50);
  29. $secondary_node = $this->createNode('page', $secondary_title, $secondary_body, $this->secondary_language);
  30. $this->drupalGet('node/' . $first_node->nid);
  31. $this->checkTranslationLink('node/' . $first_node->nid, $first_node->language);
  32. $this->checkTranslationLink($this->secondary_language . '/node/' . $first_node->nid, $this->secondary_language, 'assertNoRaw');
  33. $this->drupalGet('node/' . $secondary_node->nid);
  34. $this->checkTranslationLink('node/' . $secondary_node->nid, $secondary_node->language);
  35. $this->checkTranslationLink($this->secondary_language . '/node/' . $secondary_node->nid, $this->secondary_language);
  36. $this->drupalGet('admin/config/regional/i18n_translation/path');
  37. $this->clickLink(t('Add path translation'));
  38. // create new translation set with two node links
  39. $edit = array(
  40. 'title' => $this->randomName(10),
  41. 'translations[' . $this->default_language . ']' => 'node/' . $first_node->nid,
  42. 'translations[' . $this->secondary_language . ']' => 'node/' . $secondary_node->nid,
  43. );
  44. $this->drupalPost('admin/config/regional/i18n_translation/path/add', $edit, t('Save'));
  45. $this->drupalGet('node/' . $first_node->nid);
  46. $this->checkTranslationLink('node/' . $first_node->nid, $first_node->language);
  47. $this->checkTranslationLink($this->secondary_language . '/node/' . $secondary_node->nid, $this->secondary_language);
  48. $this->drupalGet('node/' . $secondary_node->nid);
  49. $this->checkTranslationLink('node/' . $first_node->nid, $first_node->language);
  50. $this->checkTranslationLink('node/' . $secondary_node->nid, $this->secondary_language);
  51. // create new translation set with one node and one menu "token"
  52. $edit = array(
  53. 'translations[' . $this->default_language . ']' => 'node/' . $first_node->nid,
  54. 'translations[' . $this->secondary_language . ']' => '<front>',
  55. );
  56. $this->drupalPost('admin/config/regional/i18n_translation/path/edit/1', $edit, t('Save'));
  57. $this->drupalGet('node/' . $first_node->nid);
  58. $this->checkTranslationLink('node/' . $first_node->nid, $first_node->language);
  59. $this->checkTranslationLink('node/' . $secondary_node->nid, $this->secondary_language, 'assertNoLinkByHref');
  60. $this->checkTranslationLink($this->secondary_language, $this->secondary_language);
  61. // create new translation set with one node and an external menu link.
  62. $url = 'http://' . $this->randomName(10) . '.' . $this->randomName(2);
  63. $edit = array(
  64. 'translations[' . $this->default_language . ']' => 'node/' . $first_node->nid,
  65. 'translations[' . $this->secondary_language . ']' => $url,
  66. );
  67. $this->drupalPost('admin/config/regional/i18n_translation/path/edit/1', $edit, t('Save'));
  68. $this->drupalGet('node/' . $first_node->nid);
  69. $this->checkTranslationLink('node/' . $first_node->nid, $first_node->language);
  70. $this->checkTranslationLink($url, $this->secondary_language);
  71. }
  72. }