You are here

function CourseObjectContentTest::testContentCourseObjectCreation in Course 3.x

Test course content object creation.

File

modules/course_content/tests/src/Functional/CourseObjectContentTest.php, line 21

Class

CourseObjectContentTest
Tests content in courses.

Namespace

Drupal\Tests\course_content\Functional

Code

function testContentCourseObjectCreation() {
  $ct1 = $this
    ->drupalCreateContentType();
  $ct1
    ->setThirdPartySetting('course_content', 'use', 1);
  $ct1
    ->save();

  // Save a new object, which should create a node with our new content type.
  $course = $this
    ->createCourse();
  $co1 = CourseObject::create([
    'object_type' => 'content',
  ]);
  $co1
    ->setCourse($course
    ->id());
  $co1
    ->save();

  // Reload course.
  foreach ($course
    ->getObjects() as $courseObject) {
    $node = Node::load($courseObject
      ->getInstanceId());
    $this
      ->assertEqual($node
      ->bundle(), $ct1
      ->id(), "Node type saved is the same node type specified by the course object.");
  }
}