View source
<?php
namespace Drupal\search\Tests;
class SearchAdvancedSearchFormTest extends SearchTestBase {
protected $node;
protected function setUp() {
parent::setUp();
$test_user = $this
->drupalCreateUser(array(
'access content',
'search content',
'use advanced search',
'administer nodes',
));
$this
->drupalLogin($test_user);
$this->node = $this
->drupalCreateNode();
$this->container
->get('plugin.manager.search')
->createInstance('node_search')
->updateIndex();
search_update_totals();
}
function testNodeType() {
$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.");
$this
->drupalGet('search/node', array(
'query' => array(
'keys' => $dummy_title,
),
));
$this
->assertNoText($this->node
->label(), 'Basic page node is not found with dummy title.');
$this
->drupalGet('search/node', array(
'query' => array(
'keys' => $this->node
->label(),
),
));
$this
->assertText($this->node
->label(), 'Basic page node is found with GET 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.');
$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.');
}
function testFormRefill() {
$edit = array(
'keys' => 'cat',
'or' => 'dog gerbil',
'phrase' => 'pets are nice',
'negative' => 'fish snake',
'type[page]' => 'page',
);
$this
->drupalPostForm('search/node', $edit, t('Advanced search'));
$this
->assertText('Search for cat dog OR gerbil -fish -snake');
foreach ($edit as $key => $value) {
if ($key != 'type[page]') {
$elements = $this
->xpath('//input[@name=:name]', array(
':name' => $key,
));
$this
->assertTrue(isset($elements[0]) && $elements[0]['value'] == $value, "Field {$key} is set to {$value}");
}
else {
$elements = $this
->xpath('//input[@name=:name]', array(
':name' => $key,
));
$this
->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), "Field {$key} is checked");
}
}
$edit2 = array(
'keys' => 'cat dog OR gerbil -fish -snake',
);
$this
->drupalPostForm('search/node', $edit2, t('Advanced search'));
$this
->assertText('Search for cat dog OR gerbil -fish -snake');
foreach ($edit as $key => $value) {
if ($key != 'type[page]') {
$elements = $this
->xpath('//input[@name=:name]', array(
':name' => $key,
));
$this
->assertFalse(isset($elements[0]) && $elements[0]['value'] == $value, "Field {$key} is not set to {$value}");
}
}
}
}