View source
<?php
class CourseObjectWebformTestCase extends CourseTestCase {
public static function getInfo() {
return array(
'name' => 'Course object webform',
'description' => 'Ensure that webform Course object support functions properly.',
'group' => 'Course',
);
}
function getModules() {
$modules = parent::getModules();
$modules[] = 'webform';
$modules[] = 'course_webform';
return $modules;
}
function setUp() {
parent::setUp();
$webform_version = drupal_get_installed_schema_version('webform');
$perms = array(
'create webform content',
'edit any webform content',
);
if ($webform_version >= 7420) {
$perms[] = 'edit webform components';
}
$this->webform_admin = $this
->drupalCreateUser($perms);
}
function testWebformCourseObject() {
module_load_include('inc', 'webform', 'includes/webform.submissions');
$this
->drupalLogin($this->webform_admin);
$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.');
$webformNode->webform['allow_draft'] = 1;
node_save($webformNode);
$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);
course_enroll($courseNode, $this->student_user);
$this
->drupalGet("node/{$webformNode->nid}");
$this
->assertFalse($co1
->getFulfillment($this->student_user)
->isComplete(), 'Check that webform is not completed yet.');
$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.');
$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.');
$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.');
}
}