NavigationDefaultBlockDefinitionTest.php
Same filename in this branch
Same filename and directory in other branches
Namespace
Drupal\Tests\navigation\KernelFile
-
core/
modules/ navigation/ tests/ src/ Kernel/ NavigationDefaultBlockDefinitionTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\navigation\Kernel;
use Drupal\Core\Url;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\user\Traits\UserCreationTrait;
/**
* Tests the default block provider logic.
*/
class NavigationDefaultBlockDefinitionTest extends KernelTestBase {
use UserCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'test_page_test',
'block',
'user',
'system',
'layout_discovery',
'layout_builder',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->installEntitySchema('user');
}
/**
* Tests the default block flow enabling Navigation module first.
*/
public function testNavigationDefaultAfterNavigation() : void {
$test_page_url = Url::fromRoute('test_page_test.test_page');
$module_installer = \Drupal::service('module_installer');
// After installing Navigation, the bar is present, but not the block.
$module_installer->install([
'navigation',
]);
$this->installConfig([
'navigation',
]);
$this->setCurrentUser($this->createUser([
'access navigation',
]));
$this->drupalGet($test_page_url);
$this->assertSession()
->elementExists('css', '.admin-toolbar');
$this->assertSession()
->elementNotExists('css', '.toolbar-button--icon--test-block');
// After installing Navigation Test Block, both elements are present.
$module_installer->install([
'navigation_test_block',
]);
// Refresh the mink session so we don't have a stale container.
// @todo remove after https://www.drupal.org/project/drupal/issues/3609730
$this->initMink();
$this->drupalGet($test_page_url);
$this->assertSession()
->elementExists('css', '.admin-toolbar');
$this->assertSession()
->elementContains('css', '.toolbar-button--icon--test-block', 'Test Navigation Block');
}
/**
* Tests the default block flow enabling the block provider module first.
*/
public function testNavigationDefaultBeforeNavigation() : void {
$test_page_url = Url::fromRoute('test_page_test.test_page');
$module_installer = \Drupal::service('module_installer');
// After installing Navigation Test Block, none of the elements are present.
$module_installer->install([
'navigation_test_block',
]);
$this->drupalGet($test_page_url);
$this->assertSession()
->elementNotExists('css', '.admin-toolbar');
$this->assertSession()
->elementNotExists('css', '.toolbar-button--icon--test-block');
// After installing Navigation, both elements are present.
$module_installer->install([
'navigation',
]);
// Refresh the mink session so we don't have a stale container.
$this->initMink();
$this->setCurrentUser($this->createUser([
'access navigation',
]));
$this->drupalGet($test_page_url);
$this->assertSession()
->elementExists('css', '.admin-toolbar');
$this->assertSession()
->elementContains('css', '.toolbar-button--icon--test-block', 'Test Navigation Block');
}
}
Classes
| Title | Deprecated | Summary |
|---|---|---|
| NavigationDefaultBlockDefinitionTest | Tests the default block provider logic. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.