You are here

public function SearchByPagePathsTest::setUp in Search by Page 7

Same name and namespace in other branches
  1. 6 tests/search_by_page.test \SearchByPagePathsTest::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 1349
Tests for the Search by Page module. By Jennifer Hodgdon of Poplar ProductivityWare, www.poplarware.com

Class

SearchByPagePathsTest
Functionality tests for Search by Page Paths.

Code

public function setUp() {
  parent::setUp('search', 'search_by_page', 'sbp_paths', 'sbp_test', 'dblog');
  $this
    ->setUpEnvironments();
  $this->superuser = $this
    ->drupalCreateUser(array(
    'administer nodes',
    'access content',
    'administer content types',
    'administer blocks',
    'administer search',
    'search content',
    'administer search by page',
    $this
      ->searchPerm($this->envinfo1),
    'access administration pages',
    'administer site configuration',
    'administer users',
    'administer permissions',
    'view test private content',
    'access site reports',
  ));
  $this->noprivuser = $this
    ->drupalCreateUser(array(
    $this
      ->searchPerm($this->envinfo1),
    'access content',
    'search content',
  ));
  $this->privuser = $this
    ->drupalCreateUser(array(
    'access content',
    'search content',
    $this
      ->searchPerm($this->envinfo1),
    'view test private content',
  ));

  // Verify that the priv user can see the pages.
  $this
    ->drupalLogin($this->privuser);
  $this
    ->drupalGet('sbp_test_priv_page');
  $this
    ->assertText('Trees', "Private page can be seen.");
  $this
    ->drupalGet('sbp_test_pub_page');
  $this
    ->assertText('Trees', "Public page can be seen.");
  $this
    ->drupalGet('sbp_test_another_page');
  $this
    ->assertText('Trees', "Another page can be seen.");

  // Verify that the non-priv user can see only some of the pages.
  $this
    ->drupalLogin($this->noprivuser);
  $this
    ->drupalGet('sbp_test_priv_page');
  $this
    ->assertNoText('Trees', "Private page cannot be seen.");
  $this
    ->drupalGet('sbp_test_pub_page');
  $this
    ->assertText('Trees', "Public page can be seen.");
  $this
    ->drupalGet('sbp_test_another_page');
  $this
    ->assertText('Trees', "Another page can be seen.");
  $this
    ->drupalLogin($this->superuser);

  // Set up indexing of pages.
  $this
    ->drupalPost('admin/config/search/search_by_page/edit/' . $this->envid1, array(
    'button_label' => t('Search pages'),
  ), 'Save configuration');
  $path_add_path = 'admin/config/search/search_by_page/edit/' . $this->envid1 . '/paths/add';
  $this
    ->drupalPost($path_add_path, array(
    'path' => 'sbp_test_priv_page',
    'title' => t("Private page"),
    'type' => t('Page'),
    'snippet' => 'yes',
    'role' => $this
      ->getNewRoleID($this->privuser),
  ), 'Create new indexed page');
  $this
    ->drupalPost($path_add_path, array(
    'path' => 'sbp_test_pub_page',
    'title' => t("Public page"),
    'type' => t('Page'),
    'snippet' => 'yes',
    'role' => $this
      ->getNewRoleID($this->noprivuser),
  ), 'Create new indexed page');
  $this
    ->drupalPost($path_add_path, array(
    'path' => 'sbp_test_another_page',
    'title' => t("Public page"),
    'type' => t('Page'),
    'snippet' => t('Trees: Orange and Lemon'),
    'role' => $this
      ->getNewRoleID($this->noprivuser),
  ), 'Create new indexed page');
  $this
    ->drupalGet('sbp_test_queried_page', array(
    'query' => array(
      'a' => 3,
    ),
  ));
  $this
    ->assertText('three', 'First query page shows query text');
  $this
    ->drupalGet('sbp_test_queried_page', array(
    'query' => array(
      'a' => 4,
    ),
  ));
  $this
    ->assertText('four', 'Second query page shows query text');
  $this
    ->drupalPost($path_add_path, array(
    'path' => 'sbp_test_queried_page?a=3',
    'title' => t("Public page with query"),
    'type' => t('Page'),
    'snippet' => 'yes',
    'role' => $this
      ->getNewRoleID($this->noprivuser),
  ), 'Create new indexed page');
  $this
    ->drupalPost($path_add_path, array(
    'path' => 'sbp_test_queried_page?a=4',
    'title' => t("Public page with other query"),
    'type' => t('Page'),
    'snippet' => 'yes',
    'role' => $this
      ->getNewRoleID($this->noprivuser),
  ), 'Create new indexed page');
  $this
    ->drupalPost($path_add_path, array(
    'path' => 'sbp_test_exclude_page',
    'title' => t("Public page with excluded text"),
    'type' => t('Page'),
    'snippet' => 'yes',
    'role' => $this
      ->getNewRoleID($this->noprivuser),
  ), 'Create new indexed page');
  cache_clear_all('variables', 'cache_bootstrap');
  variable_initialize();
  $this
    ->doCronRun();
  $this
    ->drupalLogin($this->superuser);
  $this
    ->drupalGet('admin/reports/dblog');
  $this
    ->assertText(t('Cron run completed'), 'Log shows cron run completed');
}