CourseDeleteTest.php in Course 3.x
File
tests/src/Functional/CourseDeleteTest.php
View source
<?php
namespace Drupal\Tests\course\Functional;
use Drupal\course\Entity\Course;
use Drupal\course\Entity\CourseEnrollment;
use Drupal\course\Entity\CourseObject;
use Drupal\course\Entity\CourseObjectFulfillment;
class CourseDeleteTest extends CourseTestBase {
protected static $modules = [
'course_test',
'block',
];
function testCourseDelete() {
$course = $this
->createCourse();
$co1 = CourseObject::create([
'object_type' => 'course_test_object',
]);
$co1
->setCourse($course);
$co1
->setOption('title', 'Course object 1');
$co1
->setOption('weight', 1);
$co1
->save();
$co2 = CourseObject::create([
'object_type' => 'course_test_object',
]);
$co2
->setCourse($course);
$co2
->setOption('title', 'Course object 2');
$co2
->setOption('weight', 2);
$co2
->save();
$this
->drupalLogin($this->student_user);
$course_enrollment = $course
->enroll($this->student_user);
$course_enrollment2 = $course
->enroll($this->admin_user);
$this
->drupalGet("course/{$course->id()}/take");
$this
->clickLink('Course object 1');
$cof1 = $co1
->getFulfillment($this->student_user);
$cof2 = $co2
->getFulfillment($this->student_user);
$cof1
->setComplete(1)
->save();
$cof2
->setComplete(1)
->save();
$this
->refreshVariables();
$course
->delete();
$this
->assertNull(Course::load($course
->id()), 'Course #1 was deleted');
$this
->assertNull(CourseEnrollment::load($course_enrollment
->id()), 'Course enrollment #1 was deleted');
$this
->assertNull(CourseEnrollment::load($course_enrollment2
->id()), 'Course enrollment #2 was deleted');
$this
->assertNull(CourseObject::load($co1
->id()), 'Course object #1 was deleted');
$this
->assertNull(CourseObject::load($co2
->id()), 'Course object #2 was deleted');
$this
->assertNull(CourseObjectFulfillment::load($cof1
->id()), 'Course object fulfillment #1 was deleted');
$this
->assertNull(CourseObjectFulfillment::load($cof2
->id()), 'Course object fulfillment #2 was deleted');
}
}