You are here

public function OpignoStatisticsTest::testOpignoStatisticsPagesAccess in Opigno statistics 3.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/OpignoStatisticsTest.php \Drupal\Tests\opigno_statistics\Functional\OpignoStatisticsTest::testOpignoStatisticsPagesAccess()

Tests statistics pages access.

File

tests/src/Functional/OpignoStatisticsTest.php, line 15

Class

OpignoStatisticsTest
Common tests for Opigno Statistics.

Namespace

Drupal\Tests\opigno_statistics\Functional

Code

public function testOpignoStatisticsPagesAccess() {

  // Create Global statistics manager.
  $statistics_manager = $this
    ->drupalCreateUser();
  $statistics_manager
    ->addRole('statistics_reader');
  $statistics_manager
    ->save();
  $this
    ->drupalLogin($statistics_manager);
  $this->accountSwitcher
    ->switchTo($statistics_manager);

  // Create test training.
  $training = $this
    ->createGroup();

  // Test access to a statistics dashboard.
  $this
    ->drupalGet('/statistics/dashboard');
  $assertSession = $this
    ->assertSession();
  $assertSession
    ->addressEquals('/statistics/dashboard');
  $assertSession
    ->statusCodeEquals(200, 'Global statistics manager has access to a statistics dashboard page.');

  // Test access to a statistics for training
  // where Global statistics manager is not a member.
  $this
    ->drupalGet('/statistics/training/' . $training
    ->id());
  $assertSession = $this
    ->assertSession();
  $assertSession
    ->pageTextContains($training
    ->label());
  $assertSession
    ->statusCodeEquals(200, 'Global statistics manager has access to a statistics any training page.');

  // Test access to a user profile page.
  $this
    ->drupalGet('/user/' . $this->groupCreator
    ->id());

  // @todo: fix issue with user_picture field (considered as unknown)
  $this
    ->assertSession()
    ->statusCodeEquals(200, 'Global statistics manager has access to a user profile page.');
}