You are here

function SearchByPageNodesReindexTest::testReindexingOnComment in Search by Page 6

Same name and namespace in other branches
  1. 7 tests/search_by_page.test \SearchByPageNodesReindexTest::testReindexingOnComment()

Tests that node reindexing happens in the right order on comment update.

File

tests/search_by_page.test, line 811
Tests for the Search by Page module. By Jennifer Hodgdon of Poplar ProductivityWare, www.poplarware.com

Class

SearchByPageNodesReindexTest
Tests when nodes are reindexed.

Code

function testReindexingOnComment() {
  $this
    ->drupalLogin($this->superuser);
  $search_path = $this->envinfo1['page_path'];

  // Turn on comments for 'sbp_indexed' content type, and put the
  // comment form on the node.
  $this
    ->drupalPost('admin/content/node-type/sbp-indexed', array(
    'comment' => '2',
    'comment_form_location' => '1',
    'comment_preview' => '0',
  ), 'Save content type');

  // Set to never reindex automatically.
  $this
    ->drupalPost('admin/settings/search_by_page/edit/' . $this->envid1, array(
    'sbp_nodes_min_time' => 0,
    'sbp_nodes_max_time' => 0,
  ), 'Save configuration');
  cache_clear_all('variables', 'cache');
  variable_init();

  // Set search so it only indexes 1 node per cron run.
  variable_set('sbp_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
      ->drupalPost('node/' . $this->nodes[$i]->nid, array(
      'subject' => $newsubj,
      'comment' => $newbody,
    ), 'Save');

    // Verify new comment subject is not searchable.
    $this
      ->drupalPost($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
      ->drupalPost($search_path, array(
      'keys' => $newsubj,
    ), t('Search pages'));
    $this
      ->assertText($newsubj, 'New comment found in search after reindex');
  }
}