View source
<?php
namespace Drupal\Tests\pathauto\Functional;
use Drupal\Tests\BrowserTestBase;
class PathautoTaxonomyWebTest extends BrowserTestBase {
use PathautoTestHelperTrait;
protected $defaultTheme = 'stable';
public static $modules = [
'taxonomy',
'pathauto',
'views',
];
protected $adminUser;
protected function setUp() {
parent::setUp();
$permissions = [
'administer pathauto',
'administer url aliases',
'create url aliases',
'administer taxonomy',
];
$this->adminUser = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($this->adminUser);
$this
->createPattern('taxonomy_term', '/[term:vocabulary]/[term:name]');
}
public function testTermEditing() {
$this
->drupalGet('admin/structure');
$this
->drupalGet('admin/structure/taxonomy');
$this
->addVocabulary([
'name' => 'tags',
'vid' => 'tags',
]);
$name = 'Testing: term name [';
$automatic_alias = '/tags/testing-term-name';
$this
->drupalPostForm('admin/structure/taxonomy/manage/tags/add', [
'name[0][value]' => $name,
], 'Save');
$name = trim($name);
$this
->assertSession()
->pageTextContains("Created new term {$name}.");
$term = $this
->drupalGetTermByName($name);
$this
->drupalGet("taxonomy/term/{$term->id()}/edit");
$this
->assertFieldChecked('edit-path-0-pathauto');
$this
->assertFieldByName('path[0][alias]', $automatic_alias, 'Generated alias visible in the path alias field.');
$this
->drupalGet($automatic_alias);
$this
->assertText($name, 'Term accessible through automatic alias.');
$manual_alias = '/tags/' . $term
->id();
$edit = [
'path[0][pathauto]' => FALSE,
'path[0][alias]' => $manual_alias,
];
$this
->drupalPostForm("taxonomy/term/{$term->id()}/edit", $edit, t('Save'));
$this
->assertText("Updated term {$name}.");
$this
->drupalGet("taxonomy/term/{$term->id()}/edit");
$this
->assertNoFieldChecked('edit-path-0-pathauto');
$this
->assertFieldByName('path[0][alias]', $manual_alias);
$this
->drupalPostForm(NULL, [
'path[0][pathauto]' => FALSE,
], t('Save'));
$this
->assertText("Updated term {$name}.");
$this
->drupalGet($automatic_alias);
$this
->assertResponse(404, 'Term not accessible through automatic alias.');
$this
->drupalGet($manual_alias);
$this
->assertText($name, 'Term accessible through manual alias.');
}
}