function SearchAdminThemeTest::testSearchUsingAdminTheme

Same name in other branches
  1. 9 core/modules/search/tests/src/Functional/SearchAdminThemeTest.php \Drupal\Tests\search\Functional\SearchAdminThemeTest::testSearchUsingAdminTheme()
  2. 11.x core/modules/search/tests/src/Functional/SearchAdminThemeTest.php \Drupal\Tests\search\Functional\SearchAdminThemeTest::testSearchUsingAdminTheme()

Tests that search results could be displayed in administration theme.

See also

\Drupal\node\Plugin\Search\NodeSearch

\Drupal\search_extra_type\Plugin\Search\SearchExtraTypeSearch

\Drupal\user\Plugin\Search\UserSearch

File

core/modules/search/tests/src/Functional/SearchAdminThemeTest.php, line 74

Class

SearchAdminThemeTest
Verify the search results using administration theme for specific plugins.

Namespace

Drupal\Tests\search\Functional

Code

public function testSearchUsingAdminTheme() : void {
    
    /** @var \Drupal\search\SearchPageRepositoryInterface $repository */
    $repository = \Drupal::service('search.search_page_repository');
    $pages = $repository->getActiveSearchPages();
    // Test default configured pages.
    $page_ids = [
        'node_search' => FALSE,
        'dummy_search_type' => TRUE,
        'help_search' => TRUE,
        'user_search' => FALSE,
    ];
    foreach ($page_ids as $page_id => $use_admin_theme) {
        $plugin = $pages[$page_id]->getPlugin();
        $path = 'search/' . $pages[$page_id]->getPath();
        $this->drupalGet($path);
        $session = $this->assertSession();
        // Make sure help plugin rendered help link.
        $path_help = $path . '/help';
        $session->linkByHrefExists($path_help);
        $this->assertSame($use_admin_theme, $plugin->usesAdminTheme());
        $this->assertAdminTheme($use_admin_theme);
        // Make sure that search help also rendered in admin theme.
        $this->drupalGet($path_help);
        $this->assertAdminTheme($use_admin_theme);
    }
}

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