function SearchByPageNodesReindexTest::testReindexingOnUpdate in Search by Page 8
Tests that node reindexing happens in the right order on node update.
File
- tests/
src/ Functional/ search_by_page.test, line 451 - Tests for the Search by Page module. By Jennifer Hodgdon of Poplar ProductivityWare, www.poplarware.com
Class
- SearchByPageNodesReindexTest
- Tests when nodes are reindexed.
Namespace
Drupal\Tests\search_by_page\FunctionalCode
function testReindexingOnUpdate() {
$this
->drupalLogin($this->superuser);
$search_path = $this->envinfo1['page_path'];
// Set to never reindex automatically.
$this
->drupalPostForm('admin/config/search/search_by_page/edit/' . $this->envid1, array(
'search_by_page_nodes_min_time' => 0,
'search_by_page_nodes_max_time' => 0,
), 'Save configuration');
drupal_flush_all_caches();
variable_initialize();
// Set search so it only indexes 1 node per cron run.
\Drupal::state()
->set('search_by_page_cron_limit', 1);
// Run this test several times...
for ($j = 0; $j < 10; $j++) {
// Choose a random title and index.
$newtitle = $this
->randomName();
$i = rand(0, count($this->nodes) - 1);
$this->nodes[$i]->title = $newtitle;
node_save($this->nodes[$i]);
// Verify new title is not searchable.
$this
->drupalPostForm($search_path, array(
'keys' => $newtitle,
), t('Search pages'));
$this
->assertNoText($newtitle, 'New title not found in search');
// Run cron - should reindex just this node.
$this
->doCronrun();
$this
->drupalLogin($this->superuser);
// Verify new title is searchable.
$this
->drupalPostForm($search_path, array(
'keys' => $newtitle,
), t('Search pages'));
$this
->assertText($newtitle, 'New title found in search after reindex');
}
}