function AddNavigationBlockConfigActionTest::testAddBlockToNavigation
Tests add item logic.
@testWith [0, 0] [1, 1] [3, 3] [7, 3]
File
-
core/
modules/ navigation/ tests/ src/ Kernel/ ConfigAction/ AddNavigationBlockConfigActionTest.php, line 48
Class
- AddNavigationBlockConfigActionTest
- @covers \Drupal\navigation\Plugin\ConfigAction\AddNavigationBlock @group navigation @group Recipe
Namespace
Drupal\Tests\navigation\Kernel\ConfigActionCode
public function testAddBlockToNavigation($delta, $computed_delta) : void {
// Load the navigation section storage.
$navigation_storage = \Drupal::service('plugin.manager.layout_builder.section_storage')->load('navigation', [
'navigation' => new Context(new ContextDefinition('string'), 'navigation'),
]);
$section = $navigation_storage->getSection(0);
$components = $section->getComponentsByRegion('content');
$this->assertCount(3, $components);
$data = [
'delta' => $delta,
'configuration' => [
'id' => 'navigation_menu:content',
'label' => 'Content From Recipe',
'label_display' => 1,
'provider' => 'navigation',
'level' => 1,
'depth' => 2,
],
];
// Use the action to add a new block to Navigation.
/** @var \Drupal\Core\Config\Action\ConfigActionManager $manager */
$manager = $this->container
->get('plugin.manager.config_action');
$manager->applyAction('addNavigationBlock', 'navigation.block_layout', $data);
// Load the config after the execution.
$navigation_storage = \Drupal::service('plugin.manager.layout_builder.section_storage')->load('navigation', [
'navigation' => new Context(new ContextDefinition('string'), 'navigation'),
]);
$section = $navigation_storage->getSection(0);
$components = $section->getComponentsByRegion('content');
$this->assertCount(4, $components);
$component = array_values($components)[$computed_delta];
$this->assertSame('content', $component->getRegion());
$this->assertEquals($data['configuration'], $component->get('configuration'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.