CourseOutlineUiTest.php in Course 3.x
File
tests/src/Functional/CourseOutlineUiTest.php
View source
<?php
namespace Drupal\Tests\course\Functional;
class CourseOutlineUiTest extends CourseTestBase {
function createCourseObjectUi($courseNode) {
$edit = array();
$edit["more[object_type]"] = 'course_test_object';
$this
->submitForm($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');
}
function testDeleteCourse() {
$course = $this
->createCourse([
'title' => 'Course 1',
]);
$this
->drupalGet("course/{$course->id()}/delete");
$this
->drupalPostForm(NULL, [], t('Delete'));
$this
->assertSession()
->pageTextContains('The course Course 1 has been deleted.');
}
}
Classes
Name |
Description |
CourseOutlineUiTest |
Test class for dealing with adding and removing elements from the course
outline. |