CourseTestBase.php in Course 3.x
File
tests/src/Functional/CourseTestBase.php
View source
<?php
namespace Drupal\Tests\course\Functional;
use Drupal\course\Entity\CourseObject;
use Drupal\course\Entity\Course;
use Drupal\Tests\BrowserTestBase;
use stdClass;
use function course_get_course_object;
abstract class CourseTestBase extends BrowserTestBase {
protected function setUp() {
parent::setUp();
$this->admin_user = $this
->drupalCreateUser(array(
'bypass node access',
'administer course',
'administer courses',
));
$this->student_user = $this
->createStudentUser();
$this
->drupalLogin($this->admin_user);
}
protected function createStudentUser() {
return $this
->drupalCreateUser();
}
protected $defaultTheme = 'stark';
protected static $modules = array(
'course_test',
);
function createCourse(array $extra = array()) {
$defaults = array(
'type' => 'course',
);
$course = Course::create(array_merge_recursive($defaults, $extra));
$course
->save();
return $course;
}
function createCourseObject(Course $course, $graded = FALSE) {
static $weight = 0;
if ($graded) {
$courseObject = CourseObject::create([
'object_type' => 'course_test_graded_object',
]);
}
else {
$courseObject = CourseObject::create([
'object_type' => 'course_test_object',
]);
}
$courseObject
->setCourse($course);
$courseObject
->setOption('weight', $weight++);
$courseObject
->save();
return $courseObject;
}
}