Loading admin_toolbar_search/tests/src/FunctionalJavascript/AdminToolbarToolsSearchTest.php +0 −7 Original line number Diff line number Diff line Loading @@ -185,13 +185,6 @@ class AdminToolbarToolsSearchTest extends AdminToolbarSearchTestBase { // Test that bundle within admin toolbar appears in search. $this->assertSuggestionContains('lola', 'admin/structure/media/manage/lola/fields'); // Assert that a link after the limit doesn't appear in admin toolbar. $zora_url = '/admin/structure/media/manage/zora/fields'; $assert_session->elementNotContains('css', '#toolbar-administration', $zora_url); // Assert that a link excluded from admin toolbar appears in search. $this->assertSuggestionContains('zora', $zora_url); // Test that adding a new bundle updates the extra links loaded from // admin_toolbar.search route. $this->createMediaType('image', [ Loading tests/src/Functional/AdminToolbarAdminMenuTest.php +39 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\Tests\admin_toolbar\Functional; use Drupal\Core\EventSubscriber\MainContentViewSubscriber; use Drupal\Tests\toolbar\Functional\ToolbarAdminMenuTest; /** Loading @@ -20,4 +21,42 @@ class AdminToolbarAdminMenuTest extends ToolbarAdminMenuTest { 'admin_toolbar', ]; /** * Tests that the 'toolbar/subtrees/{hash}' is reachable and correct. * * This is a workaround for a failing test in core 10.2: * 'X-Requested-With: XMLHttpRequest' * Remove after dropping support for Drupal 10.2 and below. */ public function testSubtreesJsonRequest(): void { // Only alter this test on Drupal 10.0 through 10.2. if (version_compare(\Drupal::VERSION, '10.0.0', '<') || version_compare(\Drupal::VERSION, '10.3.0', '>=')) { parent::testSubtreesJsonRequest(); return; } $admin_user = $this->adminUser; $this->drupalLogin($admin_user); // Request a new page to refresh the drupalSettings object. $subtrees_hash = $this->getSubtreesHash(); $this->drupalGet('toolbar/subtrees/' . $subtrees_hash, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With' => 'XMLHttpRequest']); $ajax_result = json_decode($this->getSession()->getPage()->getContent(), TRUE); $this->assertEquals('setToolbarSubtrees', $ajax_result[0]['command'], 'Subtrees response uses the correct command.'); $this->assertEquals(['system-admin_content', 'system-admin_structure', 'system-themes_page', 'system-modules_list', 'system-admin_config', 'entity-user-collection', 'front'], array_keys($ajax_result[0]['subtrees']), 'Correct subtrees returned.'); } /** * Get the hash value from the admin menu subtrees route path. * * @return string * The hash value from the admin menu subtrees route path. */ private function getSubtreesHash() { $settings = $this->getDrupalSettings(); // The toolbar module defines a route '/toolbar/subtrees/{hash}' that // returns JSON for the rendered subtrees. This hash is provided to the // client in drupalSettings. return $settings['toolbar']['subtreesHash']; } } tests/src/Functional/AdminToolbarAlterTest.php +10 −3 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ class AdminToolbarAlterTest extends BrowserTestBase { 'toolbar', 'breakpoint', 'admin_toolbar', 'user', ]; /** Loading @@ -40,11 +41,17 @@ class AdminToolbarAlterTest extends BrowserTestBase { protected function setUp(): void { parent::setUp(); // Create and log in an administrative user. $this->adminUser = $this->drupalCreateUser([ $perms = [ 'access toolbar', 'access administration pages', ]); 'administer site configuration', 'administer permissions', 'administer users', 'administer account settings' ]; // Create and log in an administrative user. $this->adminUser = $this->drupalCreateUser($perms); $this->drupalLogin($this->adminUser); } Loading Loading
admin_toolbar_search/tests/src/FunctionalJavascript/AdminToolbarToolsSearchTest.php +0 −7 Original line number Diff line number Diff line Loading @@ -185,13 +185,6 @@ class AdminToolbarToolsSearchTest extends AdminToolbarSearchTestBase { // Test that bundle within admin toolbar appears in search. $this->assertSuggestionContains('lola', 'admin/structure/media/manage/lola/fields'); // Assert that a link after the limit doesn't appear in admin toolbar. $zora_url = '/admin/structure/media/manage/zora/fields'; $assert_session->elementNotContains('css', '#toolbar-administration', $zora_url); // Assert that a link excluded from admin toolbar appears in search. $this->assertSuggestionContains('zora', $zora_url); // Test that adding a new bundle updates the extra links loaded from // admin_toolbar.search route. $this->createMediaType('image', [ Loading
tests/src/Functional/AdminToolbarAdminMenuTest.php +39 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\Tests\admin_toolbar\Functional; use Drupal\Core\EventSubscriber\MainContentViewSubscriber; use Drupal\Tests\toolbar\Functional\ToolbarAdminMenuTest; /** Loading @@ -20,4 +21,42 @@ class AdminToolbarAdminMenuTest extends ToolbarAdminMenuTest { 'admin_toolbar', ]; /** * Tests that the 'toolbar/subtrees/{hash}' is reachable and correct. * * This is a workaround for a failing test in core 10.2: * 'X-Requested-With: XMLHttpRequest' * Remove after dropping support for Drupal 10.2 and below. */ public function testSubtreesJsonRequest(): void { // Only alter this test on Drupal 10.0 through 10.2. if (version_compare(\Drupal::VERSION, '10.0.0', '<') || version_compare(\Drupal::VERSION, '10.3.0', '>=')) { parent::testSubtreesJsonRequest(); return; } $admin_user = $this->adminUser; $this->drupalLogin($admin_user); // Request a new page to refresh the drupalSettings object. $subtrees_hash = $this->getSubtreesHash(); $this->drupalGet('toolbar/subtrees/' . $subtrees_hash, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With' => 'XMLHttpRequest']); $ajax_result = json_decode($this->getSession()->getPage()->getContent(), TRUE); $this->assertEquals('setToolbarSubtrees', $ajax_result[0]['command'], 'Subtrees response uses the correct command.'); $this->assertEquals(['system-admin_content', 'system-admin_structure', 'system-themes_page', 'system-modules_list', 'system-admin_config', 'entity-user-collection', 'front'], array_keys($ajax_result[0]['subtrees']), 'Correct subtrees returned.'); } /** * Get the hash value from the admin menu subtrees route path. * * @return string * The hash value from the admin menu subtrees route path. */ private function getSubtreesHash() { $settings = $this->getDrupalSettings(); // The toolbar module defines a route '/toolbar/subtrees/{hash}' that // returns JSON for the rendered subtrees. This hash is provided to the // client in drupalSettings. return $settings['toolbar']['subtreesHash']; } }
tests/src/Functional/AdminToolbarAlterTest.php +10 −3 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ class AdminToolbarAlterTest extends BrowserTestBase { 'toolbar', 'breakpoint', 'admin_toolbar', 'user', ]; /** Loading @@ -40,11 +41,17 @@ class AdminToolbarAlterTest extends BrowserTestBase { protected function setUp(): void { parent::setUp(); // Create and log in an administrative user. $this->adminUser = $this->drupalCreateUser([ $perms = [ 'access toolbar', 'access administration pages', ]); 'administer site configuration', 'administer permissions', 'administer users', 'administer account settings' ]; // Create and log in an administrative user. $this->adminUser = $this->drupalCreateUser($perms); $this->drupalLogin($this->adminUser); } Loading