View source
<?php
module_load_include('inc', 'pathauto_i18n', 'tests/pathauto_i18n.test');
define('PATHAUTO_I18N_TAG_VOCABULARU_MACHINE_NAME', 'tags');
class Pathautoi18nTaxonomyTest extends Pathautoi18nTest {
public static function getInfo() {
return array(
'name' => 'Pathauto i18n taxonomy',
'description' => 'Ensure that the Pathauto i18n taxonomy works.',
'group' => 'Pathauto i18n',
);
}
public function setUp() {
$modules[] = 'pathauto_i18n_taxonomy';
$this
->prepareTest($modules);
$edit = array(
'pathauto_taxonomy_term_pattern' => 'all/[term:name]',
'pathauto_taxonomy_term_tags_pattern' => 'neutral/[term:name]',
);
foreach ($this->availableLanguages as $language) {
$edit['pathauto_taxonomy_term_tags_' . $language . '_pattern'] = $language . '/[term:name]';
}
$this
->drupalPost('admin/config/search/path/patterns', $edit, t('Save configuration'));
}
public function testAutomaticAliasTaxonomy() {
$this
->createTaxonomyTerm(TRUE, TRUE);
$this
->drupalGet('admin/config/search/path');
foreach ($this->availableLanguages as $language) {
$alias = $language . '/' . $this->title;
$this
->assertText($alias, 0, "Exist alias '{$alias}' for language '{$language}'.");
}
}
public function testCustomAliasTaxonomy() {
$custom_alias = 'custom/' . $this->title;
$neutral_alias = 'neutral/' . $this->title;
$this
->createTaxonomyTerm(TRUE, TRUE, $custom_alias);
$this
->drupalGet('admin/config/search/path');
foreach ($this->availableLanguages as $language) {
$alias = $language . '/' . $this->title;
$this
->assertText($alias, 0, "Exist alias '{$alias}' for language '{$language}'.");
}
$this
->assertText($custom_alias, 0, "Exist custom alias '{$custom_alias}'.");
$this
->assertNoText($neutral_alias, 0, "Alias '{$neutral_alias}' for undefined language not exist.");
}
public function testCleanString() {
$initial_title = $this->title;
$this->title .= ' ' . implode(' ', $this->availableLanguages);
$this
->setCleanStringSettings();
$this
->createTaxonomyTerm(TRUE, TRUE);
$this
->drupalGet('admin/config/search/path');
foreach ($this->availableLanguages as $language) {
$suffix = $this
->getCleanStringSuffix($language);
$alias = $language . '/' . $initial_title . '/' . $suffix;
$this
->assertNoText($alias, 0, "Exist alias '{$alias}' for language '{$language}' with excluded string '{$language}'.");
}
}
public function createTaxonomyTerm($pathauto_i18n_status, $pathauto, $alias = FALSE) {
$vocabulary = taxonomy_vocabulary_machine_name_load(PATHAUTO_I18N_TAG_VOCABULARU_MACHINE_NAME);
$term = new stdClass();
$term->name = $this->title;
$term->description = $this->title;
$term->format = db_query_range('SELECT format FROM {filter_format}', 0, 1)
->fetchField();
$term->vid = $vocabulary->vid;
$term->path = array(
'pathauto_i18n_status' => $pathauto_i18n_status,
'pathauto' => $pathauto,
);
if (!empty($alias)) {
$term->path['alias'] = $alias;
}
taxonomy_term_save($term);
}
}