CourseOutlineUiTestCase.php in Course 8.2
File
tests/src/Functional/CourseOutlineUiTestCase.php
View source
<?php
namespace Drupal\Tests\course\Functional;
class CourseOutlineUiTestCase extends CourseTestCase {
function createCourseObjectUi($courseNode) {
$edit = array();
$edit["more[object_type]"] = 'course_test_object';
$this
->drupalPostForm(NULL, $edit, t('Add object'));
$this
->assertText(t('Test course object'));
}
function testCourseOutlineCrud() {
$course = $this
->createCourse();
$this
->drupalGet("course/{$course->id()}/outline");
$this
->createCourseObjectUi($course);
$this
->clickLink('Settings');
}
function testCourseOutlineMaxOccurences() {
$course = $this
->createCourse();
$this
->drupalGet("course/{$course->id()}/outline");
$this
->createCourseObjectUi($course);
$this
->createCourseObjectUi($course);
$elements = $this
->xpath('//select[@id=:id]//option[@value=:option]', array(
':id' => 'edit-more-object-type',
':option' => 'course_test_object',
));
$this
->assertTrue((bool) $elements, 'User able to add up to maxOccurances of course objects.');
$this
->createCourseObjectUi($course);
$elements = $this
->xpath('//select[@id=:id]//option[@value=:option]', array(
':id' => 'edit-more-object-type',
':option' => 'course_test_object',
));
$this
->assertFalse((bool) $elements, 'User was not able to add more than maxOccurances of course objects.');
}
function testObjectDeletion() {
$this
->testCourseOutlineCrud();
$this
->drupalPostForm(NULL, [], t('edit-delete-button'));
$this
->assertText('Object will be removed from outline');
$this
->drupalGet("course/1/outline");
$this
->drupalPostForm(NULL, [], t('Save outline'));
$this
->assertNoText('Object will be removed from outline');
}
}