You are here

public function SearchByPageNodesTest::setUp in Search by Page 6

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

Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix. A temporary files directory is created with the same name as the database prefix.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Overrides DrupalWebTestCase::setUp

File

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

Class

SearchByPageNodesTest
Functionality tests for Search by Page Nodes.

Code

public function setUp() {
  parent::setUp('search', 'search_by_page', 'sbp_nodes', 'sbp_test', 'dblog');

  // Note: I think SimpleTest inherits the default node access from the
  // base system. Needs to be rebuilt in order for the access tests below
  // to pass!
  node_access_rebuild();
  $this
    ->setUpEnvironments();

  // Set up super-user and other users with different privileges.
  $this->superuser = $this
    ->drupalCreateUser(array(
    'administer nodes',
    'access content',
    'administer content types',
    'administer blocks',
    'administer search',
    'search content',
    'administer search by page',
    'access administration pages',
    $this
      ->searchPerm($this->envinfo1),
    'administer site configuration',
    'administer users',
    'administer permissions',
    'view test private content',
    'access site reports',
  ));
  $this->noprivuser = $this
    ->drupalCreateUser(array(
    'access content',
    'search content',
    $this
      ->searchPerm($this->envinfo1),
  ));
  $this->privuser = $this
    ->drupalCreateUser(array(
    'access content',
    'search content',
    $this
      ->searchPerm($this->envinfo1),
    'view test private content',
  ));
  $this
    ->drupalLogin($this->superuser);

  // Set up so "sbp_indexed" nodes are searchable, and "sbp_hidden" nodes are
  // not. Index them with the privileged user.
  $this
    ->drupalPost('admin/settings/search_by_page/edit/' . $this->envid1, array(
    'sbp_nodes_types_indexed[sbp_indexed]' => TRUE,
    'sbp_nodes_display_type' => 'excerpts',
    'sbp_nodes_role' => $this
      ->getNewRoleID($this->privuser),
    'button_label' => t('Search pages'),
  ), 'Save configuration');
  cache_clear_all('variables', 'cache');
  variable_init();

  // Throw in a few nodes that won't match our tests.
  $info = array(
    'body' => 'blah',
    'teaser' => 'blah',
    'title' => 'blah',
  );
  $this
    ->drupalCreateNode($info);
  $this
    ->drupalCreateNode($info);
  $this
    ->drupalCreateNode($info);
  $this
    ->drupalCreateNode($info);

  // Create some content that we'll look for - make sure it has the
  // word "walk" in it.
  $info = array(
    'body' => 'I walk through the streets, looking around for trouble',
    'teaser' => 'I walk on a path, where it is quiet',
    'type' => 'sbp_indexed',
    'test_private' => FALSE,
  );
  $node = $this
    ->drupalCreateNode($info);
  $this->nodetitle1 = $node->title;
  $this
    ->assertFalse($node->test_private, "Created a non-private node");
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText('streets', "Streets appears on first node page");
  $this
    ->assertNoText('north', "North does not appear on first node page");
  $this
    ->assertNoText('people', "People does not appear on first node page");

  // Create some "private" content, also with the word "walk" in it
  $info = array(
    'body' => 'I can walk really far, maybe even to the north pole.',
    'teaser' => 'I will walk to the south pole.',
    'type' => 'sbp_indexed',
    'test_private' => TRUE,
  );
  $node = $this
    ->drupalCreateNode($info);
  $this->privnodeid = $node->nid;
  $this
    ->assertTrue($node->test_private, "Created a private node");
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertNoText('streets', "Streets does not appear on second node page");
  $this
    ->assertText('north', "North appears on second node page");
  $this
    ->assertNoText('people', "People does not appear on second node page");

  // Create some non-indexed content, also with the word "walk" in it
  $info = array(
    'body' => 'When I walk, I try not to run into people.',
    'type' => 'sbp_hidden',
    'test_private' => FALSE,
  );
  $node = $this
    ->drupalCreateNode($info);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertNoText('streets', "Streets does not appear on third node page");
  $this
    ->assertNoText('north', "North does not appear on third node page");
  $this
    ->assertText('people', "People appears on third node page");

  // Create some content with excluded tags. Make sure to use Full HTML
  // input format.
  $excluded = search_by_page_setting_get('exclude_tags', $this->envid1, '');
  $this
    ->assertEqual($excluded, 'tagtoexclude', 'Correct tag is marked excluded');
  $info = array(
    'body' => 'This content <tagtoexclude>only has walk gobble in the excluded tag</tagtoexclude> and then gobble appears after it.',
    'format' => 2,
    'teaser' => 'Short version of this content',
    'type' => 'sbp_indexed',
    'test_private' => FALSE,
  );
  $node = $this
    ->drupalCreateNode($info);
  $this->exclnodetitle = $node->title;
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText('walk', "walk appears on the excluded node page");
  $this
    ->assertText('gobble', "gobble appears on the excluded node page");
  $this
    ->doCronrun();
  $this
    ->drupalLogin($this->superuser);
  $this
    ->drupalGet('admin/reports/dblog');
  $this
    ->assertText(t('Cron run completed'), 'Log shows cron run completed');
  $this
    ->drupalLogout();
}