i18n_variable.test 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * @file
  4. * Test case for multilingual variables
  5. */
  6. class i18nVariableTestCase extends Drupali18nTestCase {
  7. public static function getInfo() {
  8. return array(
  9. 'name' => 'Variable translation',
  10. 'group' => 'Internationalization',
  11. 'description' => 'Variable translation functions'
  12. );
  13. }
  14. function setUp() {
  15. parent::setUp('i18n_variable', 'translation');
  16. parent::setUpLanguages(array('administer site configuration'));
  17. }
  18. /**
  19. * Set up translation for content type (page)
  20. */
  21. function setUpContentTranslation($settings = array()) {
  22. $this->translator = $this->drupalCreateUser(array('create page content', 'edit own page content', 'translate content'));
  23. $this->drupalLogin($this->admin_user);
  24. // Set "Basic page" content type to use multilingual support with
  25. // translation.
  26. $this->drupalGet('admin/structure/types/manage/page');
  27. $edit = array();
  28. $edit['language_content_type'] = 2;
  29. // Mark status and promoted
  30. $edit['node_options[status]'] = 1;
  31. $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
  32. $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), t('Basic page content type has been updated.'));
  33. // Enable the language switcher block.
  34. $language_type = LANGUAGE_TYPE_INTERFACE;
  35. $edit = array("blocks[locale_$language_type][region]" => 'sidebar_first');
  36. $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
  37. }
  38. function testVariableLocalize() {
  39. $this->setUpContentTranslation();
  40. // Create 2 nodes in different languages.
  41. $first_title = $this->randomName(10);
  42. $first_body = $this->randomString(50);
  43. $first_node = $this->createNode('page', $first_title, $first_body, $this->default_language);
  44. $secondary_title = $this->randomName(10);
  45. $secondary_body = $this->randomString(50);
  46. $secondary_node = $this->createNode('page', $secondary_title, $secondary_body, $this->secondary_language);
  47. $this->drupalGet('<front>', array('language' => i18n_language_object($this->default_language)));
  48. $this->assertText(t('No front page content has been created yet.'));
  49. $this->drupalGet('<front>', array('language' => i18n_language_object($this->secondary_language)));
  50. $this->assertText(t('No front page content has been created yet.'));
  51. $edit = array(
  52. 'variables[site_name]' => 1,
  53. 'variables[site_frontpage]' => 1,
  54. );
  55. $this->drupalPost('admin/config/regional/i18n/variable', $edit, t('Save configuration'));
  56. $edit_first = array(
  57. 'site_frontpage' => 'node/' . $first_node->nid,
  58. 'site_name' => $this->randomName(10),
  59. );
  60. $this->drupalPost('admin/config/system/site-information', $edit_first, t('Save configuration'), array('language' => i18n_language_object($this->default_language)));
  61. $edit_secondary = array(
  62. 'site_frontpage' => 'node/' . $secondary_node->nid,
  63. 'site_name' => $this->randomName(10),
  64. );
  65. $this->drupalPost('admin/config/system/site-information', $edit_secondary, t('Save configuration'), array('language' => i18n_language_object($this->secondary_language)));
  66. $this->drupalGet('<front>', array('language' => i18n_language_object($this->default_language)));
  67. $this->assertText($edit_first['site_name']);
  68. $this->assertNoText(t('No front page content has been created yet.'));
  69. $this->assertText($first_title);
  70. $this->drupalGet('<front>', array('language' => i18n_language_object($this->secondary_language)));
  71. $this->assertText($edit_secondary['site_name']);
  72. $this->assertNoText(t('No front page content has been created yet.'));
  73. $this->assertText($secondary_title);
  74. }
  75. }