You are here

function SearchbyPageAttachReindexTest::testSearchAttach in Search by Page 7

Same name and namespace in other branches
  1. 6 tests/search_by_page.test \SearchbyPageAttachReindexTest::testSearchAttach()

Tests that attachments are reindexed when the node changes.

Note that the name must be testSearchAttach() to override the function by the same name in the base class.

Overrides SearchByPageAttachTest::testSearchAttach

File

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

Class

SearchbyPageAttachReindexTest
Tests attachment reindexing.

Code

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

  // Verify that all the test nodes are found on a search for their
  // descriptions, and for the attachment (contains daisy).
  for ($i = 0; $i < count($this->nodes); $i++) {
    $node = $this->nodes[$i];
    $desc = $this->descs[$i];
    $this
      ->drupalPost($search_path, array(
      'keys' => 'daisy',
    ), t('Search pages'));
    $this
      ->assertText($node->title, "Node appears in search of first attachment");
    $this
      ->drupalPost($search_path, array(
      'keys' => $desc,
    ), t('Search pages'));
    $this
      ->assertText($node->title, "Node appears in search of attachment description");
  }

  // Set to never reindex automatically.
  $this
    ->drupalPost('admin/config/search/search_by_page/edit/' . $this->envid2, array(
    'sbp_attach_min_time' => 0,
    'sbp_attach_max_time' => 0,
  ), 'Save configuration');
  cache_clear_all('variables', 'cache');
  variable_initialize();

  // Set search so it only indexes 1 node per cron run.
  variable_set('sbp_cron_limit', 1);

  // Run the next test several times. Pick a random node, attach the
  // file again with a new description, and run cron to index it.
  // Verify the new description can be found.
  for ($i = 0; $i < 10; $i++) {

    // Choose a random title and index.
    $newdesc = $this
      ->randomName();
    $key = rand(0, count($this->nodes) - 1);
    $node = node_load($this->nodes[$key]->nid, NULL, TRUE);
    foreach ($node->field_myfile as $lang => $stuff) {
      $node->field_myfile[$lang][0]['description'] = $newdesc;
    }
    node_save($node);
    $this
      ->doCronrun();
    $this
      ->drupalLogin($this->superuser);
    $this
      ->drupalGet('admin/reports/dblog');
    $this
      ->assertText(t('Cron run completed'), 'Log shows cron run completed');
    $this
      ->drupalPost($search_path, array(
      'keys' => $newdesc,
    ), t('Search pages'));
    $this
      ->assertText($this->nodes[$key]->title, "Node appears in search of attachment description after reindex");
  }
}