QuizTestCase.test in Quiz 7.5
Same filename and directory in other branches
Unit tests for the quiz question Module.
File
tests/QuizTestCase.testView source
<?php
/**
* @file
* Unit tests for the quiz question Module.
*/
/**
* Base test class for Quiz questions.
*/
abstract class QuizTestCase extends DrupalWebTestCase {
protected $profile = 'testing';
/**
* Set up a question test case.
*
* @param array $modules
* Array of modules to enable.
* @param array $admin_permissions
* Array of admin permissions to add.
* @param array $user_permissions
* Array of user permissions to add.
*/
public function setUp($modules = array(), $admin_permissions = array(), $user_permissions = array()) {
$modules[] = 'quiz';
$modules[] = 'quiz_question';
parent::setUp($modules);
// Add text formats.
$filtered_html_format = array(
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'weight' => 0,
'filters' => array(
// URL filter.
'filter_url' => array(
'weight' => 0,
'status' => 1,
),
// HTML filter.
'filter_html' => array(
'weight' => 1,
'status' => 1,
),
// Line break filter.
'filter_autop' => array(
'weight' => 2,
'status' => 1,
),
// HTML corrector filter.
'filter_htmlcorrector' => array(
'weight' => 10,
'status' => 1,
),
),
);
$filtered_html_format = (object) $filtered_html_format;
filter_format_save($filtered_html_format);
$full_html_format = array(
'format' => 'full_html',
'name' => 'Full HTML',
'weight' => 1,
'filters' => array(
// URL filter.
'filter_url' => array(
'weight' => 0,
'status' => 1,
),
// Line break filter.
'filter_autop' => array(
'weight' => 1,
'status' => 1,
),
// HTML corrector filter.
'filter_htmlcorrector' => array(
'weight' => 10,
'status' => 1,
),
),
);
$full_html_format = (object) $full_html_format;
filter_format_save($full_html_format);
// Enable default permissions for system roles.
$filtered_html_permission = filter_permission_name($filtered_html_format);
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array(
$filtered_html_permission,
));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array(
$filtered_html_permission,
));
$admin_permissions[] = 'administer quiz configuration';
$admin_permissions[] = 'create quiz content';
$admin_permissions[] = 'edit any quiz content';
$admin_permissions[] = 'edit question titles';
$admin_permissions[] = 'access quiz';
$user_permissions[] = 'access quiz';
$this->admin = $this
->drupalCreateUser(array_unique($admin_permissions));
$this->user = $this
->drupalCreateUser(array_unique($user_permissions));
}
/**
* Link a question to a new or provided quiz.
*/
public function linkQuestionToQuiz($question_node, $quiz_node = NULL) {
if (!$quiz_node) {
// Create a new quiz with defaults.
$quiz_node = $this
->drupalCreateQuiz();
}
_quiz_question_get_instance($question_node)
->saveRelationships($quiz_node->nid, $quiz_node->vid);
return $quiz_node;
}
public function drupalCreateQuiz($settings = array()) {
$settings += array(
'type' => 'quiz',
'result_type' => 'quiz_result',
'review_options' => array(
'end' => drupal_map_assoc(array_keys(quiz_get_feedback_options())),
),
);
return $this
->drupalCreateNode($settings);
}
public function testQuizNodeSettings() {
}
public function quizDeleteAllResults() {
db_query('DELETE FROM {quiz_node_results}');
}
}
Classes
Name | Description |
---|---|
QuizTestCase | Base test class for Quiz questions. |