function CourseObjectWebformTestCase::testWebformCourseObject in Course 7.2
Same name and namespace in other branches
- 6 modules/course_webform/course_webform.test \CourseObjectWebformTestCase::testWebformCourseObject()
- 7 modules/course_webform/course_webform.test \CourseObjectWebformTestCase::testWebformCourseObject()
File
- modules/
course_webform/ course_webform.test, line 34
Class
- CourseObjectWebformTestCase
- Tests for conditional event-based access to course objects.
Code
function testWebformCourseObject() {
module_load_include('inc', 'webform', 'includes/webform.submissions');
$this
->drupalLogin($this->webform_admin);
// Create a course with 1 webform.
$courseNode = $this
->createCourseNode();
$co1 = course_get_course_object('course_webform', 'webform');
$co1
->setCourse($courseNode->nid);
$co1
->save();
$this
->assertTrue($co1
->getInstanceId() > 0, 'Webform node created on course object save.');
$webformNode = node_load($co1
->getInstanceId());
$this
->assertTrue($webformNode->type == 'webform', 'Webform node is a webform.');
// Allow drafts
$webformNode->webform['allow_draft'] = 1;
node_save($webformNode);
// Add a question.
$this
->drupalGet("node/{$webformNode->nid}/webform");
$this
->drupalPost(NULL, array(
'add[name]' => 'test',
'add[type]' => 'textfield',
), 'Add');
$this
->drupalPost(NULL, array(), 'Save component');
$this
->drupalLogin($this->student_user);
// Enroll the user in the course
course_enroll($courseNode, $this->student_user);
// Take the webform.
$this
->drupalGet("node/{$webformNode->nid}");
$this
->assertFalse($co1
->getFulfillment($this->student_user)
->isComplete(), 'Check that webform is not completed yet.');
// Draft the webform.
$this
->drupalPost(NULL, array(
'submitted[test]' => 1,
), t('Save Draft'));
$sid = $co1
->getFulfillment($this->student_user)
->getInstanceId();
$this
->assertTrue(empty($sid), 'Check that webform submission was not recorded.');
$this
->assertFalse($co1
->getFulfillment($this->student_user)
->isComplete(), 'Check that webform is not complete.');
// Finish the webform.
$this
->drupalPost(NULL, array(
'submitted[test]' => 1,
), t('Submit'));
$sid = $co1
->getFulfillment($this->student_user)
->getInstanceId();
$this
->assertTrue($sid, 'Check that webform submission was recorded.');
$this
->assertTrue($co1
->getFulfillment($this->student_user)
->isComplete(), 'Check that webform is completed.');
// Test that on unenroll, the user's webform submission is deleted.
$co1
->getFulfillment($this->student_user)
->delete();
drupal_static('webform_get_submission', array(), TRUE);
$submission = webform_get_submission($co1
->getNode()->nid, $sid);
$this
->assertFalse($submission, 'Check that webform submission was deleted.');
}