EntityPathAliasCollectorTest.php in Dependency Calculation 8
File
tests/src/Kernel/EventSubscriber/DependencyCollector/EntityPathAliasCollectorTest.php
View source
<?php
namespace Drupal\Tests\depcalc\Kernel\EventSubscriber\DependencyCollector;
use Drupal\Core\Entity\EntityInterface;
use Drupal\depcalc\DependencyStack;
use Drupal\depcalc\DependentEntityWrapper;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\Tests\Traits\Core\PathAliasTestTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
class EntityPathAliasCollectorTest extends KernelTestBase {
use NodeCreationTrait;
use ContentTypeCreationTrait;
use UserCreationTrait;
use PathAliasTestTrait;
protected $alias;
protected $calculator;
protected $node;
public static $modules = [
'depcalc',
'field',
'filter',
'node',
'system',
'text',
'user',
'path_alias',
];
protected function setUp() : void {
parent::setUp();
$this
->installConfig([
'node',
'field',
'filter',
]);
$this
->installEntitySchema('node');
$this
->installEntitySchema('path_alias');
$this
->installEntitySchema('user');
$this
->createContentType();
$this->node = $this
->createNode();
$this->alias = $this
->createPathAlias("/node/{$this->node->id()}", "/test-alias");
$this->calculator = \Drupal::service('entity.dependency.calculator');
}
public function testDependencyCollector() {
$node_dependencies = $this
->calculateDependencies($this->node);
$this
->assertArrayHasKey($this->alias
->uuid(), $node_dependencies);
}
protected function calculateDependencies(EntityInterface $entity) : array {
$wrapper = new DependentEntityWrapper($entity);
return $this->calculator
->calculateDependencies($wrapper, new DependencyStack());
}
}