SearchPageOverrideTest.php

Same filename and directory in other branches
  1. 8.9.x core/modules/search/tests/src/Functional/SearchPageOverrideTest.php
  2. 10 core/modules/search/tests/src/Functional/SearchPageOverrideTest.php
  3. 11.x core/modules/search/tests/src/Functional/SearchPageOverrideTest.php

Namespace

Drupal\Tests\search\Functional

File

core/modules/search/tests/src/Functional/SearchPageOverrideTest.php

View source
<?php

namespace Drupal\Tests\search\Functional;

use Drupal\Tests\BrowserTestBase;

/**
 * Tests if the result page can be overridden.
 *
 * Verifies that a plugin can override the buildResults() method to
 * control what the search results page looks like.
 *
 * @group search
 */
class SearchPageOverrideTest extends BrowserTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'search',
        'search_extra_type',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * A user with permission to administer search.
     *
     * @var \Drupal\user\UserInterface
     */
    public $searchUser;
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        parent::setUp();
        // Log in as a user that can create and search content.
        $this->searchUser = $this->drupalCreateUser([
            'search content',
            'administer search',
        ]);
        $this->drupalLogin($this->searchUser);
    }
    public function testSearchPageHook() {
        $keys = 'bike shed ' . $this->randomMachineName();
        $this->drupalGet("search/dummy_path", [
            'query' => [
                'keys' => $keys,
            ],
        ]);
        $this->assertSession()
            ->pageTextContains('Dummy search snippet');
        $this->assertSession()
            ->pageTextContains('Test page text is here');
    }

}

Classes

Title Deprecated Summary
SearchPageOverrideTest Tests if the result page can be overridden.

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