You are here

public function SearchByPageUsersTest::setUp in Search by Page 8

Overrides SearchByPageTesterTest::setUp

File

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

Class

SearchByPageUsersTest
Functionality tests for Search by Page Users.

Namespace

Drupal\Tests\search_by_page\Functional

Code

public function setUp() {
  parent::setUp('search', 'search_by_page', 'search_by_page_users', 'search_by_page_test', 'dblog');
  $this
    ->setUpEnvironments();

  // Create some random users that won't be found
  $u = $this
    ->drupalCreateUser();
  $u = $this
    ->drupalCreateUser();
  $u = $this
    ->drupalCreateUser();
  $u = $this
    ->drupalCreateUser();

  // Set up two users for searching - just make sure they have different
  // permissions, so they get different roles.
  $this->usera = $this
    ->drupalCreateUser(array(
    'access content',
  ));
  $this->userb = $this
    ->drupalCreateUser(array(
    'access content',
    $this
      ->searchPerm($this->envinfo2),
  ));

  // Set up a user that can see user profiles, to use when indexing.
  $this->indexuser = $this
    ->drupalCreateUser(array(
    'access user profiles',
  ));

  // Verify that this user can see user profiles A and B
  $this
    ->drupalLogin($this->indexuser);
  $this
    ->drupalGet('user/' . $this->usera->uid);
  $this
    ->assertText($this->usera->name, "Indexing user can see user A page");
  $this
    ->drupalGet('user/' . $this->userb->uid);
  $this
    ->assertText($this->userb->name, "Indexing user can see user B page");

  // Set up an admin user and login as that user
  $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->envinfo2),
    'administer site configuration',
    'administer users',
    'administer permissions',
    'view test private content',
    'access user profiles',
    'access site reports',
  ));
  $this
    ->drupalLogin($this->superuser);

  // Set up so user a is indexed and user b is not.
  // First have to find the role ID that SimpleTest set up.
  // Relies on the role name having the word 'test' in it somewhere.
  $rid = $this
    ->getNewRoleID($this->usera);
  $this
    ->drupalPostForm('admin/config/search/search_by_page/edit/' . $this->envid2, array(
    'search_by_page_users_roles_indexed[' . $rid . ']' => TRUE,
    'search_by_page_users_role' => $this
      ->getNewRoleID($this->indexuser),
    'button_label' => t('Search pages'),
  ), 'Save configuration');
  \Drupal::service('cache.bootstrap')
    ->invalidateAll();
  variable_initialize();
  $this
    ->doCronRun();
  $this
    ->drupalLogin($this->superuser);
  $this
    ->drupalGet('admin/reports/dblog');
  $this
    ->assertText(t('Cron run completed'), 'Log shows cron run completed');
}