function SearchAdvancedSearchFormTest::testNodeType

Same name and namespace in other branches
  1. 8.9.x core/modules/search/tests/src/Functional/SearchAdvancedSearchFormTest.php \Drupal\Tests\search\Functional\SearchAdvancedSearchFormTest::testNodeType()
  2. 10 core/modules/search/tests/src/Functional/SearchAdvancedSearchFormTest.php \Drupal\Tests\search\Functional\SearchAdvancedSearchFormTest::testNodeType()
  3. 11.x core/modules/search/tests/src/Functional/SearchAdvancedSearchFormTest.php \Drupal\Tests\search\Functional\SearchAdvancedSearchFormTest::testNodeType()

Tests advanced search by node type.

File

core/modules/search/tests/src/Functional/SearchAdvancedSearchFormTest.php, line 59

Class

SearchAdvancedSearchFormTest
Indexes content and tests the advanced search form.

Namespace

Drupal\Tests\search\Functional

Code

public function testNodeType() {
    // Verify some properties of the node that was created.
    $this->assertSame('page', $this->node
        ->getType(), 'Node type is Basic page.');
    $dummy_title = 'Lorem ipsum';
    $this->assertNotEquals($dummy_title, $this->node
        ->label(), "Dummy title doesn't equal node title.");
    // Search for the dummy title with a GET query.
    $this->drupalGet('search/node', [
        'query' => [
            'keys' => $dummy_title,
        ],
    ]);
    $this->assertSession()
        ->pageTextNotContains($this->node
        ->label());
    // Search for the title of the node with a GET query.
    $this->drupalGet('search/node', [
        'query' => [
            'keys' => $this->node
                ->label(),
        ],
    ]);
    $this->assertSession()
        ->pageTextContains($this->node
        ->label());
    // Search for the title of the node with a POST query.
    $edit = [
        'or' => $this->node
            ->label(),
    ];
    $this->drupalGet('search/node');
    $this->submitForm($edit, 'edit-submit--2');
    $this->assertSession()
        ->pageTextContains($this->node
        ->label());
    // Search by node type.
    $this->drupalGet('search/node');
    $this->submitForm(array_merge($edit, [
        'type[page]' => 'page',
    ]), 'edit-submit--2');
    $this->assertSession()
        ->pageTextContains($this->node
        ->label());
    $this->drupalGet('search/node');
    $this->submitForm(array_merge($edit, [
        'type[article]' => 'article',
    ]), 'edit-submit--2');
    $this->assertSession()
        ->pageTextContains('search yielded no results');
}

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