CourseContextTestCase.php in Course 8.2
File
tests/src/Functional/CourseContextTestCase.php
View source
<?php
namespace Drupal\Tests\course\Functional;
class CourseContextTestCase extends CourseTestCase {
function testDetermineContext() {
$course = $this
->createCourse();
$co1 = $this
->createCourseObject($course);
$co1
->setInstanceId(1234)
->save();
$find_co1 = course_get_course_object('course_test_object', 1234);
$this
->assertEqual($co1
->getId(), $find_co1
->getId(), 'Found the same course object.');
$find_course1 = course_determine_context('course_test_object', 1234);
$this
->assertEqual($find_course1
->id(), $course
->id(), 'Context came back to the same course.');
}
function testMultiContext() {
$course1 = $this
->createCourse();
$course2 = $this
->createCourse();
$co1 = $this
->createCourseObject($course1);
$co1
->setInstanceId(1234)
->save();
$co2 = $this
->createCourseObject($course2);
$co2
->setInstanceId(1234)
->save();
$co1
->takeObject();
$foundCourseNode1 = course_determine_context('course_test_object', 1234);
$this
->assertEqual($course1
->id(), $foundCourseNode1
->id(), 'Found the right course context, pass 1.');
drupal_static_reset('course_determine_context');
$co2
->takeObject();
$foundCourseNode2 = course_determine_context('course_test_object', 1234);
$this
->assertEqual($course2
->id(), $foundCourseNode2
->id(), 'Found the right course context, pass 2.');
drupal_static_reset('course_determine_context');
$co1
->takeObject();
$foundCourseNode1 = course_determine_context('course_test_object', 1234);
$this
->assertEqual($course1
->id(), $foundCourseNode1
->id(), 'Found the right course context, pass 3.');
drupal_static_reset('course_determine_context');
unset($_SESSION['course']);
$foundCourseNode1 = course_determine_context('course_test_object', 1234);
$this
->assertEqual($course1
->id(), $foundCourseNode1
->id(), 'Found the right course context, pass 4.');
}
}