function NavigationLinkBlockTest::setUp

Overrides PageCacheTagsTestBase::setUp

File

core/modules/navigation/tests/src/Functional/NavigationLinkBlockTest.php, line 48

Class

NavigationLinkBlockTest
Tests for \Drupal\navigation\Plugin\Block\NavigationLinkBlockTest.

Namespace

Drupal\Tests\navigation\Functional

Code

protected function setUp() : void {
    parent::setUp();
    // Create an admin user, log in and enable test navigation blocks.
    $this->adminUser = $this->drupalCreateUser([
        'access administration pages',
        'administer site configuration',
        'access navigation',
    ]);
    // Create additional users to test caching modes.
    $this->normalUser = $this->drupalCreateUser([
        'access navigation',
    ]);
    // Add programmatically a link block to the navigation.
    $section_storage_manager = \Drupal::service('plugin.manager.layout_builder.section_storage');
    $cacheability = new CacheableMetadata();
    $contexts = [
        'navigation' => new Context(ContextDefinition::create('string'), 'navigation'),
    ];
    
    /** @var \Drupal\layout_builder\SectionListInterface $section_list */
    $section_list = $section_storage_manager->findByContext($contexts, $cacheability);
    $section = $section_list->getSection(0);
    $section->appendComponent(new SectionComponent(\Drupal::service('uuid')->generate(), 'content', [
        'id' => 'navigation_link',
        'label' => 'Admin Main Page',
        'label_display' => '0',
        'provider' => 'navigation',
        'context_mapping' => [],
        'title' => 'Navigation Settings',
        'uri' => 'internal:/admin/config/user-interface/navigation/settings',
        'icon_class' => 'admin-link',
    ]));
    $section_list->save();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.