You are here

function SearchAdvancedSearchFormTest::testNodeType in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/search/src/Tests/SearchAdvancedSearchFormTest.php \Drupal\search\Tests\SearchAdvancedSearchFormTest::testNodeType()

Tests advanced search by node type.

File

core/modules/search/src/Tests/SearchAdvancedSearchFormTest.php, line 45
Contains \Drupal\search\Tests\SearchAdvancedSearchFormTest.

Class

SearchAdvancedSearchFormTest
Indexes content and tests the advanced search form.

Namespace

Drupal\search\Tests

Code

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', array(
    'query' => array(
      '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', array(
    'query' => array(
      '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 = array(
    'or' => $this->node
      ->label(),
  );
  $this
    ->drupalPostForm('search/node', $edit, t('Advanced search'));
  $this
    ->assertText($this->node
    ->label(), 'Basic page node is found with POST query.');

  // Search by node type.
  $this
    ->drupalPostForm('search/node', array_merge($edit, array(
    'type[page]' => 'page',
  )), t('Advanced search'));
  $this
    ->assertText($this->node
    ->label(), 'Basic page node is found with POST query and type:page.');
  $this
    ->drupalPostForm('search/node', array_merge($edit, array(
    'type[article]' => 'article',
  )), t('Advanced search'));
  $this
    ->assertText('search yielded no results', 'Article node is not found with POST query and type:article.');
}