public function EntityWithoutBundleFormTest::testPathAliasFormElementAccess in URL Alias Permissions 8
Test if the path alias form elements is correctly hidden when no access.
File
- tests/
src/ Functional/ EntityWithoutBundleFormTest.php, line 71
Class
- EntityWithoutBundleFormTest
- Test url_alias_permissions with an entity without bundles.
Namespace
Drupal\Tests\url_alias_permissions\FunctionalCode
public function testPathAliasFormElementAccess() {
// Visit the entity_test add page and check that the path field is present.
$this
->drupalLogin($this->userWithUrlAliasPermissions);
$this
->drupalGet('/entity_test/add');
$this
->assertSession()
->fieldExists('url_alias[0][alias]');
// Create an entity_test.
$name = $this
->randomMachineName();
$this
->submitForm([
'name[0][value]' => $name,
'url_alias[0][alias]' => '/test-alias',
], 'Save');
// Check that the URL alias was successfully saved.
$entity = $this
->getEntityTestByName($name);
$this
->assertEquals('/test-alias', $entity
->get('url_alias')->alias);
// Visit the entity_test edit page and check that the path field is also
// present.
$this
->drupalGet('entity_test/manage/' . $entity
->id() . '/edit');
$this
->assertSession()
->fieldExists('url_alias[0][alias]');
// Log in as a user that doens't have access to edit the URL alias.
$this
->drupalLogin($this->userWithoutUrlAliasPermissions);
// Check that the field is not present.
$this
->drupalGet('/entity_test/add');
$this
->assertSession()
->fieldNotExists('url_alias[0][alias]');
// Check that the field on the entity_test edit form is not present.
$this
->drupalGet('entity_test/manage/' . $entity
->id() . '/edit');
$this
->assertSession()
->fieldNotExists('url_alias[0][alias]');
// Save the form and check that the URL alias still exists.
$this
->submitForm([], 'Save');
$entity = $this
->getEntityTestByName($name);
$this
->assertEquals('/test-alias', $entity
->get('url_alias')->alias);
}