function SearchAdvancedSearchFormTest::testNodeType

Same name and namespace in other branches
  1. 11.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. 9 core/modules/search/tests/src/Functional/SearchAdvancedSearchFormTest.php \Drupal\Tests\search\Functional\SearchAdvancedSearchFormTest::testNodeType()
  4. main 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->assertTrue($this->node
    ->getType() == 'page', 'Node type is Basic page.');
  $dummy_title = 'Lorem ipsum';
  $this->assertNotEqual($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->assertNoText($this->node
    ->label(), 'Basic page node is not found with dummy title.');
  // Search for the title of the node with a GET query.
  $this->drupalGet('search/node', [
    'query' => [
      'keys' => $this->node
        ->label(),
    ],
  ]);
  $this->assertText($this->node
    ->label(), 'Basic page node is found with GET query.');
  // Search for the title of the node with a POST query.
  $edit = [
    'or' => $this->node
      ->label(),
  ];
  $this->drupalPostForm('search/node', $edit, 'edit-submit--2');
  $this->assertText($this->node
    ->label(), 'Basic page node is found with POST query.');
  // Search by node type.
  $this->drupalPostForm('search/node', array_merge($edit, [
    'type[page]' => 'page',
  ]), 'edit-submit--2');
  $this->assertText($this->node
    ->label(), 'Basic page node is found with POST query and type:page.');
  $this->drupalPostForm('search/node', array_merge($edit, [
    'type[article]' => 'article',
  ]), 'edit-submit--2');
  $this->assertText('search yielded no results', 'Article node is not found with POST query and type:article.');
}

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