You are here

CourseOutlineUiTestCase.test in Course 7.2

File

tests/CourseOutlineUiTestCase.test
View source
<?php

/**
 * Test class for dealing with adding and removing elements from the course
 * outline.
 */
class CourseOutlineUiTestCase extends CourseTestCase {
  public static function getInfo() {

    // Note that getInfo() strings are not translated with t().
    return array(
      'name' => 'Course outline',
      'description' => 'Ensure that the Course outline functions properly.',
      'group' => 'Course',
    );
  }

  /**
   * Create a course object through the interface.
   *
   * @param stdClass $courseNode
   */
  function createCourseObjectUi($courseNode) {

    // Add a new course content object.
    $edit = array();
    $edit["more[object_type]"] = 'course_test-course_test_object';
    $this
      ->drupalPost(NULL, $edit, t('Add object'));
    $this
      ->assertText(t('Test course object'));
  }

  /**
   * Test creating a course object through the UI.
   */
  function testCourseOutlineCrud() {
    $courseNode = $this
      ->createCourseNode();
    $this
      ->drupalGet("node/{$courseNode->nid}/course-outline");
    $this
      ->createCourseObjectUi($courseNode);
    $this
      ->clickLink('Settings');
  }

  /**
   * Test maximum course objects per course.
   */
  function testCourseOutlineMaxOccurences() {
    $courseNode = $this
      ->createCourseNode();
    $this
      ->drupalGet("node/{$courseNode->nid}/course-outline");
    $this
      ->createCourseObjectUi($courseNode);
    $this
      ->createCourseObjectUi($courseNode);
    $elements = $this
      ->xpath('//select[@id=:id]//option[@value=:option]', array(
      ':id' => 'edit-more-object-type',
      ':option' => 'course_test-course_test_object',
    ));
    $this
      ->assertTrue((bool) $elements, 'User able to add up to maxOccurances of course objects.');
    $this
      ->createCourseObjectUi($courseNode);
    $elements = $this
      ->xpath('//select[@id=:id]//option[@value=:option]', array(
      ':id' => 'edit-more-object-type',
      ':option' => 'course_test-course_test_object',
    ));
    $this
      ->assertFalse((bool) $elements, 'User was not able to add more than maxOccurances of course objects.');
  }

  /**
   * Test that an object can be marked for deletion from the course outline
   * without validation.
   */
  function testObjectDeletion() {
    $this
      ->testCourseOutlineCrud();
    $this
      ->drupalPost(NULL, array(), t('Delete'));
    $this
      ->assertText('Object will be removed from outline');
    $this
      ->drupalPost(NULL, array(), t('Save outline'));
    $this
      ->assertNoText(t('Test course object'));
  }

}

Classes

Namesort descending Description
CourseOutlineUiTestCase Test class for dealing with adding and removing elements from the course outline.