public function OpignoILTTest::testOpignoILTAccess in Opigno Instructor-led Trainings 8
Same name and namespace in other branches
- 3.x tests/src/Functional/OpignoILTTest.php \Drupal\Tests\opigno_ilt\Functional\OpignoILTTest::testOpignoILTAccess()
Tests ILT access.
File
- tests/
src/ Functional/ OpignoILTTest.php, line 19
Class
- OpignoILTTest
- Common tests for Opigno ILT.
Namespace
Drupal\Tests\opigno_ilt\FunctionalCode
public function testOpignoILTAccess() {
// Create test training.
$training = $this
->createGroup();
// Create students.
$student_1 = $this
->drupalCreateUser();
$student_2 = $this
->drupalCreateUser();
// Add students to training.
$training
->addMember($student_1);
$training
->addMember($student_2);
$training
->save();
// Training members count.
$this
->assertEquals(3, count($training
->getMembers()), 'Training members - a Group admin and two students.');
// Create ILT.
$meeting = ILT::create([
'title' => $this
->randomString(),
'training' => $training
->id(),
'place' => $this
->randomString(),
'date' => $this
->createDummyDaterange(),
]);
$meeting
->save();
$ilt_path = Url::fromRoute('entity.opigno_ilt.canonical', [
'opigno_ilt' => $meeting
->id(),
]);
// Log out admin.
$this
->drupalLogout();
// Check access for a student without restriction.
$this
->drupalLogin($student_1);
$this
->drupalGet($ilt_path);
$this
->assertSession()
->pageTextContains($meeting
->getTitle());
$this
->assertSession()
->statusCodeEquals(200, 'Student without restriction has access to ILT');
// Add only one student to ILT.
$meeting = ILT::load($meeting
->id());
$meeting
->setMembersIds([
$student_2
->id(),
]);
$meeting
->save();
// Check access for a student with restriction.
$this
->drupalGet($ilt_path);
$this
->assertSession()
->pageTextNotContains($meeting
->getTitle());
$this
->assertSession()
->statusCodeEquals(403, 'Student with restriction does not have access to ILT');
}