View source
<?php
namespace Drupal\Tests\url_alias_permissions\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
use Drupal\url_alias_permissions\UrlAliasPermPermissions;
class UrlAliasPermissionsTest extends KernelTestBase {
use ContentTypeCreationTrait;
use TaxonomyTestTrait;
protected static $modules = [
'url_alias_permissions',
'url_alias_permissions_test',
'node',
'entity_test',
'field',
'text',
'filter',
'user',
'path',
'taxonomy',
'system',
];
protected $entityFieldManager;
protected $entityTypeManager;
protected $entityTypeBundleInfo;
protected $nodeTypeStorage;
protected $urlAliasPermPermissions;
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('node');
$this
->installEntitySchema('user');
$this
->installEntitySchema('entity_test');
$this
->installSchema('node', 'node_access');
$this
->installConfig('node');
$this
->installConfig('filter');
$this->entityFieldManager = $this->container
->get('entity_field.manager');
$this->entityTypeBundleInfo = $this->container
->get('entity_type.bundle.info');
$this->entityTypeManager = $this->container
->get('entity_type.manager');
$this->urlAliasPermPermissions = new UrlAliasPermPermissions($this->entityFieldManager, $this->entityTypeBundleInfo, $this->entityTypeManager);
$this->nodeTypeStorage = $this->entityTypeManager
->getStorage('node_type');
}
public function testPermissions() {
$this
->createContentType([
'type' => 'bar',
]);
$this
->createContentType([
'type' => 'foo',
]);
$this
->assertEquals([
'edit bar node url alias',
'edit foo node url alias',
'edit entity_test url alias',
], array_keys($this->urlAliasPermPermissions
->urlAliasPermissions()));
$this
->createContentType([
'type' => 'test',
]);
$this
->assertEquals([
'edit bar node url alias',
'edit foo node url alias',
'edit test node url alias',
'edit entity_test url alias',
], array_keys($this->urlAliasPermPermissions
->urlAliasPermissions()));
$node_type = $this->nodeTypeStorage
->load('test');
$node_type
->delete();
$this
->assertEquals([
'edit bar node url alias',
'edit foo node url alias',
'edit entity_test url alias',
], array_keys($this->urlAliasPermPermissions
->urlAliasPermissions()));
$vocabulary = $this
->createVocabulary();
$this
->assertEquals([
'edit bar node url alias',
'edit foo node url alias',
'edit entity_test url alias',
'edit ' . $vocabulary
->id() . ' taxonomy_term url alias',
], array_keys($this->urlAliasPermPermissions
->urlAliasPermissions()));
}
}