View source
<?php
namespace Drupal\Tests\depcalc\Kernel\EventSubscriber\DependencyCollector;
use Drupal\KernelTests\KernelTestBase;
use Drupal\taxonomy\Entity\Term;
class TermParentCollectorTest extends KernelTestBase {
use CalculateDependenciesEventDispatcherTrait;
protected static $modules = [
'depcalc',
'field',
'filter',
'language',
'content_translation',
'node',
'system',
'text',
'user',
'file',
'taxonomy',
'path_alias',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('filter_format');
$this
->installEntitySchema('node');
$this
->installEntitySchema('user');
$this
->installEntitySchema('file');
$this
->installEntitySchema('path_alias');
$this
->installEntitySchema('taxonomy_term');
$this
->installSchema('system', 'sequences');
$this
->installSchema('file', 'file_usage');
$this
->installConfig([
'node',
'user',
'file',
'filter',
]);
}
public function testParentWasAdded() {
$parent = Term::create([
'vid' => 'tags',
'status' => 1,
'name' => 'Term parent',
]);
$parent
->save();
$child = Term::create([
'vid' => 'tags',
'status' => 1,
'name' => 'Term child',
]);
$child->parent->entity = $parent;
$child
->save();
$event = $this
->dispatchCalculateDependencies($child, []);
$dependencies = $event
->getDependencies();
$this
->assertArrayHasKey($parent
->uuid(), $dependencies, 'Taxonomy term should have parent as a dependency');
}
}