pathauto_i18n_node.test 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * @file
  4. * Tests for the pathauto_i18n node module.
  5. */
  6. module_load_include('inc', 'pathauto_i18n', 'tests/pathauto_i18n.test');
  7. /**
  8. * Test functionality for nodes.
  9. */
  10. class Pathautoi18nNodeTest extends Pathautoi18nTest {
  11. /**
  12. * GetInfo method.
  13. */
  14. public static function getInfo() {
  15. return array(
  16. 'name' => 'Pathauto i18n node',
  17. 'description' => 'Ensure that the Pathauto i18n node works.',
  18. 'group' => 'Pathauto i18n',
  19. );
  20. }
  21. /**
  22. * SetUp method.
  23. */
  24. public function setUp() {
  25. $modules[] = 'pathauto_i18n_node';
  26. $this->prepareTest($modules);
  27. // Configure patterns for all language for easy testing.
  28. $edit = array(
  29. 'pathauto_node_article_pattern' => 'all/[node:title]',
  30. 'pathauto_node_article_und_pattern' => 'neutral/[node:title]',
  31. );
  32. foreach ($this->availableLanguages as $language) {
  33. $edit['pathauto_node_article_' . $language . '_pattern'] = $language . '/[node:title]';
  34. }
  35. $this->drupalPost('admin/config/search/path/patterns', $edit, t('Save configuration'));
  36. }
  37. /**
  38. * Test nodes with automatic alias for certain language.
  39. */
  40. public function testAutomaticAliasLanguageSelected() {
  41. $this->createNode($this->contentLanguage, TRUE, TRUE);
  42. // Check aliases.
  43. $this->drupalGet('admin/config/search/path');
  44. foreach ($this->availableLanguages as $language) {
  45. $alias = $language . '/' . $this->title;
  46. $this->assertText($alias, 0, "Exist alias '$alias' for language '$language'.");
  47. }
  48. }
  49. /**
  50. * Test nodes with custom alias for certain language.
  51. */
  52. public function testCustomAliasLanguageSelected() {
  53. $custom_alias = 'custom/' . $this->title;
  54. $this->createNode($this->contentLanguage, TRUE, FALSE, $custom_alias);
  55. // Check aliases and custom alias.
  56. $this->drupalGet('admin/config/search/path');
  57. foreach ($this->availableLanguages as $language) {
  58. if ($language == 'en') {
  59. $alias = $language . '/' . $this->title;
  60. $this->assertText($custom_alias, 0, "Exist custom alias '$custom_alias'.");
  61. $this->assertNoText($alias, 0, "Alias '$alias' for language '$language' not exist.");
  62. }
  63. else {
  64. $alias = $language . '/' . $this->title;
  65. $this->assertText($alias, 0, "Exist alias '$alias' for language '$language'.");
  66. }
  67. }
  68. }
  69. /**
  70. * Test nodes with automatic alias for undefined language.
  71. */
  72. public function testAutomaticAliasUndefinedLanguage() {
  73. $this->contentLanguage = LANGUAGE_NONE;
  74. $this->testAutomaticAliasLanguageSelected();
  75. $neutral_alias = 'neutral/' . $this->title;
  76. $this->assertNoText($neutral_alias, 0, "Alias '$neutral_alias' for undefined language not exist.");
  77. }
  78. /**
  79. * Test nodes with custom alias for undefined language.
  80. */
  81. public function testCustomAliasUndefinedLanguage() {
  82. $custom_alias = 'custom/' . $this->title;
  83. $neutral_alias = 'neutral/' . $this->title;
  84. $this->createNode(LANGUAGE_NONE, TRUE, FALSE, $custom_alias);
  85. // Check aliases and custom alias.
  86. $this->drupalGet('admin/config/search/path');
  87. foreach ($this->availableLanguages as $language) {
  88. $alias = $language . '/' . $this->title;
  89. $this->assertText($alias, 0, "Exist alias '$alias' for language '$language'.");
  90. }
  91. $this->assertText($custom_alias, 0, "Exist custom alias '$custom_alias'.");
  92. $this->assertNoText($neutral_alias, 0, "Alias '$neutral_alias' for undefined language not exist.");
  93. }
  94. /**
  95. * Test clearing of string.
  96. */
  97. public function testCleanString() {
  98. // Set appropriate title which will allow us remove parts of path.
  99. $initial_title = $this->title;
  100. $this->title .= ' ' . implode(' ', $this->availableLanguages);
  101. $this->setCleanStringSettings();
  102. $this->createNode($this->contentLanguage, TRUE, TRUE);
  103. // Check aliases.
  104. $this->drupalGet('admin/config/search/path');
  105. foreach ($this->availableLanguages as $language) {
  106. $suffix = $this->getCleanStringSuffix($language);
  107. $alias = $language . '/' . $initial_title . '/' . $suffix;
  108. $this->assertNoText($alias, 0, "Exist alias '$alias' for language '$language' with excluded string '$language'.");
  109. }
  110. }
  111. /**
  112. * Helper to create node.
  113. */
  114. public function createNode($language, $pathauto_i18n_status, $pathauto, $alias = FALSE) {
  115. $settings = array(
  116. 'type' => 'article',
  117. 'title' => $this->title,
  118. 'body' => array(
  119. $language => array(
  120. array(
  121. $this->randomName(64),
  122. ),
  123. ),
  124. ),
  125. 'language' => $language,
  126. 'path' => array(
  127. 'pathauto_i18n_status' => $pathauto_i18n_status,
  128. 'pathauto' => $pathauto,
  129. ),
  130. );
  131. if (!empty($alias)) {
  132. $settings['path']['alias'] = $alias;
  133. }
  134. $node = $this->drupalCreateNode($settings);
  135. }
  136. }