function SearchByPageNodesReindexTest::testReindexingOnComment in Search by Page 8
Tests that node reindexing happens in the right order on comment update.
File
- tests/
src/ Functional/ search_by_page.test, line 500 - 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 testReindexingOnComment() {
$this
->drupalLogin($this->superuser);
$search_path = $this->envinfo1['page_path'];
// Turn on comments for 'search_by_page_indexed' content type, and put the
// comment form on the node.
$this
->drupalPostForm('admin/structure/types/manage/sbp-indexed', array(
'comment' => '2',
'comment_form_location' => '1',
'comment_preview' => '0',
), 'Save content type');
// 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++) {
// Enter a random comment.
$newsubj = $this
->randomName();
$newbody = $this
->randomName();
$i = rand(0, count($this->nodes) - 1);
$this
->drupalPostForm('node/' . $this->nodes[$i]->nid, array(
'subject' => $newsubj,
'comment_body[und][0][value]' => $newbody,
), 'Save');
// Verify new comment subject is not searchable.
$this
->drupalPostForm($search_path, array(
'keys' => $newsubj,
), t('Search pages'));
$this
->assertNoText($newsubj, 'New comment 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' => $newsubj,
), t('Search pages'));
$this
->assertText($newsubj, 'New comment found in search after reindex');
}
}