You are here

function SearchbyPageAttachReindexTest::testSearchAttach in Search by Page 6

Same name and namespace in other branches
  1. 7 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 SearchByPageAttachCCKTest::testSearchAttach

File

tests/search_by_page.test, line 2814
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/settings/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_init();

  // 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();
    $tmp = array(
      'description' => $newdesc,
    );
    $key = rand(0, count($this->nodes) - 1);
    $node = node_load($this->nodes[$key]->nid, NULL, TRUE);
    $node->field_myfile[0]['data'] = $tmp;
    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");
  }
}