NodeSearchTest.php in Multiversion 8
File
tests/src/Functional/NodeSearchTest.php
View source
<?php
namespace Drupal\Tests\multiversion\Functional;
$GLOBALS['skip_test'] = FALSE;
if (!class_exists('\\Drupal\\Tests\\search\\Functional\\SearchNodeUpdateAndDeletionTest')) {
class_alias('\\Drupal\\Tests\\BrowserTestBase', '\\CoreSearchNodeUpdateAndDeletionTest');
$GLOBALS['skip_test'] = TRUE;
}
else {
class_alias('\\Drupal\\Tests\\search\\Functional\\SearchNodeUpdateAndDeletionTest', '\\CoreSearchNodeUpdateAndDeletionTest');
}
class NodeSearchTest extends \CoreSearchNodeUpdateAndDeletionTest {
protected static $modules = [
'node',
'search',
'multiversion',
];
public function testSearchIndexUpdateOnNodeDeletion() {
if ($GLOBALS['skip_test']) {
$this
->markTestSkipped();
}
$node = $this
->drupalCreateNode([
'title' => 'No dragons here',
'body' => [
[
'value' => 'Again: No dragons here',
],
],
'type' => 'page',
]);
$node_search_plugin = $this->container
->get('plugin.manager.search')
->createInstance('node_search');
$node_search_plugin
->updateIndex();
search_update_totals();
$edit = [
'keys' => 'dragons',
];
$this
->drupalPostForm('search/node', $edit, t('Search'));
$this
->assertText($node
->label());
$search_index_dataset = db_query("SELECT sid FROM {search_index} WHERE type = 'node_search' AND word = :word", [
':word' => 'dragons',
])
->fetchField();
$this
->assertNotEqual($search_index_dataset, FALSE, t('Node info found on the search_index'));
$node
->delete();
$search_index_dataset = db_query("SELECT sid FROM {search_index} WHERE type = 'node_search' AND word = :word", [
':word' => 'dragons',
])
->fetchField();
$this
->assertNotEmpty($search_index_dataset, t('Node info found on the search_index'));
$this
->drupalPostForm('search/node', $edit, t('Search'));
$this
->assertNoText($node
->label());
}
}