You are here

public function SearchByPageNodesTest::setUp in Search by Page 7

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

Sets up a Drupal site for running functional and integration tests.

Generates a random database prefix and installs Drupal with the specified installation profile in DrupalWebTestCase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

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

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

File

tests/search_by_page.test, line 374
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');
  $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',
    'bypass node access',
  ));
  $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 priveleged user.
  $this
    ->drupalPost('admin/config/search/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_bootstrap');
  variable_initialize();
  $info = array(
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'double trouble',
        ),
      ),
    ),
    'type' => 'page',
    'language' => LANGUAGE_NONE,
    'title' => 'first page',
  );
  $node = $this
    ->drupalCreateNode($info);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText('trouble', "Node page could be found");

  // Throw in a few nodes that won't match our tests.
  $info = array(
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'blah',
          'summary' => 'blah',
        ),
      ),
    ),
    'title' => 'blah',
    'language' => LANGUAGE_NONE,
  );
  $node = $this
    ->drupalCreateNode($info);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText('blah', "Node page could be found");
  $node = $this
    ->drupalCreateNode($info);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText('blah', "Node page could be found");
  $node = $this
    ->drupalCreateNode($info);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText('blah', "Node page could be found");

  // Create some content that we'll look for - make sure it has the
  // word "walk" in it.
  $info = array(
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'I walk through the streets, looking around for trouble',
          'summary' => 'I walk on a path, where it is quiet',
        ),
      ),
    ),
    'type' => 'sbp_indexed',
    'test_private' => FALSE,
    'language' => LANGUAGE_NONE,
  );
  $node = $this
    ->drupalCreateNode($info);
  $this->nodetitle1 = $node->title;
  $this->nodeid1 = $node->nid;
  $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' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'I can walk really far, maybe even to the north pole.',
          'summary' => 'I will walk to the south pole.',
        ),
      ),
    ),
    'type' => 'sbp_indexed',
    'test_private' => TRUE,
    'language' => LANGUAGE_NONE,
  );
  $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' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'When I walk, I try not to run into people.',
        ),
      ),
    ),
    'type' => 'sbp_hidden',
    'test_private' => FALSE,
    'language' => LANGUAGE_NONE,
  );
  $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');

  // Find the Full HTML format.
  $filters = filter_formats();
  $filternum = 0;
  foreach ($filters as $filter) {
    if ($filter->name == 'Full HTML') {
      $filternum = $filter->format;
      break;
    }
  }
  $info = array(
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'This content <tagtoexclude>only has walk gobble in the excluded tag</tagtoexclude> and then gobble appears after it.',
          'summary' => 'Short version of this content',
          'format' => $filternum,
        ),
      ),
    ),
    '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');
}