PathAdminTest.php in Drupal 10
File
core/modules/path/tests/src/Functional/PathAdminTest.php
View source
<?php
namespace Drupal\Tests\path\Functional;
class PathAdminTest extends PathTestBase {
protected static $modules = [
'path',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$web_user = $this
->drupalCreateUser([
'create page content',
'edit own page content',
'administer url aliases',
'create url aliases',
]);
$this
->drupalLogin($web_user);
}
public function testPathFiltering() {
$node1 = $this
->drupalCreateNode();
$node2 = $this
->drupalCreateNode();
$node3 = $this
->drupalCreateNode();
$alias1 = '/' . $this
->randomMachineName(8);
$edit = [
'path[0][value]' => '/node/' . $node1
->id(),
'alias[0][value]' => $alias1,
];
$this
->drupalGet('admin/config/search/path/add');
$this
->submitForm($edit, 'Save');
$alias2 = '/' . $this
->randomMachineName(8);
$edit = [
'path[0][value]' => '/node/' . $node2
->id(),
'alias[0][value]' => $alias2,
];
$this
->drupalGet('admin/config/search/path/add');
$this
->submitForm($edit, 'Save');
$alias3 = '/' . $this
->randomMachineName(4) . '/' . $this
->randomMachineName(4);
$edit = [
'path[0][value]' => '/node/' . $node3
->id(),
'alias[0][value]' => $alias3,
];
$this
->drupalGet('admin/config/search/path/add');
$this
->submitForm($edit, 'Save');
$edit = [
'filter' => $alias1,
];
$this
->submitForm($edit, 'Filter');
$this
->assertSession()
->linkByHrefExists($alias1);
$this
->assertSession()
->linkByHrefNotExists($alias2);
$this
->assertSession()
->linkByHrefNotExists($alias3);
$edit = [
'filter' => $alias2,
];
$this
->submitForm($edit, 'Filter');
$this
->assertSession()
->linkByHrefNotExists($alias1);
$this
->assertSession()
->linkByHrefExists($alias2);
$this
->assertSession()
->linkByHrefNotExists($alias3);
$edit = [
'filter' => $alias3,
];
$this
->submitForm($edit, 'Filter');
$this
->assertSession()
->linkByHrefNotExists($alias1);
$this
->assertSession()
->linkByHrefNotExists($alias2);
$this
->assertSession()
->linkByHrefExists($alias3);
$edit = [
'filter' => $this
->randomMachineName(10),
];
$this
->submitForm($edit, 'Filter');
$this
->assertSession()
->linkByHrefNotExists($alias1);
$this
->assertSession()
->linkByHrefNotExists($alias2);
$edit = [];
$this
->submitForm($edit, 'Reset');
$this
->assertSession()
->linkByHrefExists($alias1);
$this
->assertSession()
->linkByHrefExists($alias2);
}
}