CourseObjectNodeTestCase.php in Course 8.3
File
modules/course_content/tests/src/Functional/CourseObjectNodeTestCase.php
View source
<?php
namespace Drupal\Tests\course_content\Functional;
use Drupal\course\Entity\CourseObject;
use Drupal\Tests\course\Functional\CourseTestCase;
class CourseObjectNodeTestCase extends CourseTestCase {
public static $modules = array(
'course_content',
'course_test',
);
function testContentAccess() {
$course = $this
->createCourse();
$co1 = CourseObject::create([
'object_type' => 'content',
'cid' => $course
->id(),
]);
$co1
->set('private', 1);
$co1
->save();
$this
->drupalLogin($this->student_user);
$course
->enroll($this->student_user);
$this
->drupalGet("node/" . $co1
->getInstanceId());
$this
->assertResponse(403, 'Check that node is protected outside the course.');
$cof = $co1
->getFulfillment($this->student_user);
$cof
->save();
$this
->drupalGet("node/" . $co1
->getInstanceId());
$this
->assertResponse(200, 'Check that node is accessible when user enters course object.');
$fulfillments = \Drupal\course\Entity\CourseObjectFulfillment::loadMultiple();
\Drupal::entityTypeManager()
->getStorage('course_object_fulfillment')
->delete($fulfillments);
$this
->drupalGet("node/" . $co1
->getInstanceId());
$this
->assertResponse(403, 'Check that node is protected outside the course, after revoke.');
}
}