course_webform.test in Course 6
File
modules/course_webform/course_webform.test
View source
<?php
require_once drupal_get_path('module', 'course') . '/tests/CourseTestCase.test';
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();
$this->webform_admin = $this
->drupalCreateUser(array(
'administer nodes',
) + webform_perm());
}
function testWebformCourseObject() {
$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.');
$this
->drupalGet("node/{$webformNode->nid}/webform");
$this
->drupalPost(NULL, array(
'add[name]' => 'test',
'add[type]' => 'textfield',
), 'Add');
$this
->drupalPost(NULL, array(), 'Save component');
$this
->drupalGet("node/{$webformNode->nid}");
$this
->assertFalse($co1
->getFulfillment()
->isComplete(), 'Check that webform is not completed yet.');
$this
->drupalPost(NULL, array(
'submitted[test]' => 1,
), 'Submit');
$co1 = course_get_course_object_by_id($co1
->getId(), $this->webform_admin);
$this
->assertTrue($co1
->getFulfillment()
->isComplete(), 'Check that webform is completed.');
}
}