public function MenuDependencyTest::testMenuEntityDependencies in Dependency Calculation 8
Tests the calculation of menu entity dependencies.
@dataProvider menuDependenciesDataProvider
Parameters
string $test_entity_type: The test entity type.
string $test_entity_uuid: The test entity uuid.
array $entities: Entities to create.
array $expected_entities: The list of expected entities.
array $expected_modules: The list of expected modules.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
\Drupal\Core\Entity\EntityStorageException
File
- tests/
src/ Kernel/ EventSubscriber/ DependencyCollector/ MenuDependencyTest.php, line 88
Class
- MenuDependencyTest
- Class MenuDependencyTest.
Namespace
Drupal\Tests\depcalc\Kernel\EventSubscriber\DependencyCollectorCode
public function testMenuEntityDependencies(string $test_entity_type, string $test_entity_uuid, array $entities, array $expected_entities, array $expected_modules) {
/** @var \Drupal\Core\Entity\EntityRepositoryInterface $repository */
$repository = \Drupal::service('entity.repository');
$entity_type_manager = \Drupal::entityTypeManager();
foreach ($entities as $entity_type => $entities_values) {
foreach ($entities_values as $entity_values) {
$entity = $entity_type_manager
->getStorage($entity_type)
->create($entity_values);
$entity
->save();
}
}
$test_entity = $repository
->loadEntityByUuid($test_entity_type, $test_entity_uuid);
$wrapper = new DependentEntityWrapper($test_entity);
$stack = new DependencyStack();
$event = new CalculateEntityDependenciesEvent($wrapper, $stack);
$subscriber = new MenuItemContentDependencyCollector();
$subscriber
->onCalculateDependencies($event);
$this
->assertEqual(array_keys($wrapper
->getDependencies()), $expected_entities);
$this
->assertEqual($wrapper
->getModuleDependencies(), $expected_modules);
}