You are here

public function SearchAdvancedSearchFormTest::testNodeType in Drupal 9

Same name and namespace in other branches
  1. 8 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 56

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');
}