pathauto_i18n_taxonomy.test 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * @file
  4. * Tests for the pathauto_i18n taxonomy module.
  5. */
  6. module_load_include('inc', 'pathauto_i18n', 'tests/pathauto_i18n.test');
  7. define('PATHAUTO_I18N_TAG_VOCABULARU_MACHINE_NAME', 'tags');
  8. /**
  9. * Test functionality for taxonomy.
  10. */
  11. class Pathautoi18nTaxonomyTest extends Pathautoi18nTest {
  12. /**
  13. * GetInfo method.
  14. */
  15. public static function getInfo() {
  16. return array(
  17. 'name' => 'Pathauto i18n taxonomy',
  18. 'description' => 'Ensure that the Pathauto i18n taxonomy works.',
  19. 'group' => 'Pathauto i18n',
  20. );
  21. }
  22. /**
  23. * SetUp method.
  24. */
  25. public function setUp() {
  26. $modules[] = 'pathauto_i18n_taxonomy';
  27. $this->prepareTest($modules);
  28. // Configure patterns for all language for easy testing.
  29. $edit = array(
  30. 'pathauto_taxonomy_term_pattern' => 'all/[term:name]',
  31. 'pathauto_taxonomy_term_tags_pattern' => 'neutral/[term:name]',
  32. );
  33. foreach ($this->availableLanguages as $language) {
  34. $edit['pathauto_taxonomy_term_tags_' . $language . '_pattern'] = $language . '/[term:name]';
  35. }
  36. $this->drupalPost('admin/config/search/path/patterns', $edit, t('Save configuration'));
  37. }
  38. /**
  39. * Test taxonomy terms with automatic alias.
  40. */
  41. public function testAutomaticAliasTaxonomy() {
  42. $this->createTaxonomyTerm(TRUE, TRUE);
  43. // Check aliases.
  44. $this->drupalGet('admin/config/search/path');
  45. foreach ($this->availableLanguages as $language) {
  46. $alias = $language . '/' . $this->title;
  47. $this->assertText($alias, 0, "Exist alias '$alias' for language '$language'.");
  48. }
  49. }
  50. /**
  51. * Test taxonomy terms with custom alias for certain language.
  52. */
  53. public function testCustomAliasTaxonomy() {
  54. $custom_alias = 'custom/' . $this->title;
  55. $neutral_alias = 'neutral/' . $this->title;
  56. $this->createTaxonomyTerm(TRUE, TRUE, $custom_alias);
  57. // Check aliases and custom alias.
  58. $this->drupalGet('admin/config/search/path');
  59. foreach ($this->availableLanguages as $language) {
  60. $alias = $language . '/' . $this->title;
  61. $this->assertText($alias, 0, "Exist alias '$alias' for language '$language'.");
  62. }
  63. $this->assertText($custom_alias, 0, "Exist custom alias '$custom_alias'.");
  64. $this->assertNoText($neutral_alias, 0, "Alias '$neutral_alias' for undefined language not exist.");
  65. }
  66. /**
  67. * Test clearing of string.
  68. */
  69. public function testCleanString() {
  70. // Set appropriate title which will allow us remove parts of path.
  71. $initial_title = $this->title;
  72. $this->title .= ' ' . implode(' ', $this->availableLanguages);
  73. $this->setCleanStringSettings();
  74. $this->createTaxonomyTerm(TRUE, TRUE);
  75. // Check aliases.
  76. $this->drupalGet('admin/config/search/path');
  77. foreach ($this->availableLanguages as $language) {
  78. $suffix = $this->getCleanStringSuffix($language);
  79. $alias = $language . '/' . $initial_title . '/' . $suffix;
  80. $this->assertNoText($alias, 0, "Exist alias '$alias' for language '$language' with excluded string '$language'.");
  81. }
  82. }
  83. /**
  84. * Helper to create taxonomy term.
  85. */
  86. public function createTaxonomyTerm($pathauto_i18n_status, $pathauto, $alias = FALSE) {
  87. $vocabulary = taxonomy_vocabulary_machine_name_load(PATHAUTO_I18N_TAG_VOCABULARU_MACHINE_NAME);
  88. $term = new stdClass();
  89. $term->name = $this->title;
  90. $term->description = $this->title;
  91. // Use the first available text format.
  92. $term->format = db_query_range('SELECT format FROM {filter_format}', 0, 1)->fetchField();
  93. $term->vid = $vocabulary->vid;
  94. $term->path = array(
  95. 'pathauto_i18n_status' => $pathauto_i18n_status,
  96. 'pathauto' => $pathauto,
  97. );
  98. if (!empty($alias)) {
  99. $term->path['alias'] = $alias;
  100. }
  101. taxonomy_term_save($term);
  102. }
  103. }