ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
assMultipleChoiceTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
14{
15 protected $backupGlobals = false;
16
17 protected function setUp()
18 {
19 require_once './Modules/TestQuestionPool/classes/class.assMultipleChoice.php';
20 if (defined('ILIAS_PHPUNIT_CONTEXT')) {
21 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
22 ilUnitUtil::performInitialisation();
23 } else {
24 chdir(dirname(__FILE__));
25 chdir('../../../');
26 }
27 require_once './Services/Utilities/classes/class.ilUtil.php';
28 }
29
36 /* public static function createSampleQuestion($obj_id = null)
37 {
38 $obj_id = ($obj_id) ? $obj_id : 99999999;
39 include_once './Modules/TestQuestionPool/classes/class.assMultipleChoice.php';
40
41 $mc = new assMultipleChoice('unit test multiple choice question', 'unit test multiple choice question comment', 'Helmut Schottmüller', -1, '<p><strong>unit tests</strong> are...</p>');
42 $mc->addAnswer(
43 'important',
44 0.5,
45 -0.5,
46 1
47 );
48 $mc->addAnswer(
49 'useless',
50 -0.5,
51 0.5,
52 2
53 );
54 $mc->addAnswer(
55 'stupid',
56 -0.5,
57 0.5,
58 3
59 );
60 $mc->addAnswer(
61 'cool',
62 0.5,
63 -0.5,
64 4
65 );
66 $mc->setObjId($obj_id);
67 $mc->saveToDb();
68 return $mc->getId();
69 }
70 */
76 /* public function t_e_stCreation()
77 {
78 global $ilDB;
79
80 include_once './Modules/TestQuestionPool/classes/class.assMultipleChoice.php';
81 $insert_id = self::createSampleQuestion(null);
82 $this->assertGreaterThan(0, $insert_id);
83 if ($insert_id > 0)
84 {
85 $mc = new assMultipleChoice();
86 $mc->loadFromDb($insert_id);
87 $this->assertEquals($mc->getPoints(),2);
88 $this->assertEquals($mc->getTitle(),"unit test multiple choice question");
89 $this->assertEquals($mc->getComment(),"unit test multiple choice question comment");
90 $this->assertEquals($mc->getAuthor(),"Helmut Schottmüller");
91 $this->assertEquals($mc->getQuestion(),"<p><strong>unit tests</strong> are...</p>");
92 $this->assertEquals(count($mc->getAnswers()), 4);
93 $result = $mc->delete($insert_id);
94 $this->assertEquals($result,true);
95 }
96 }
97 */
99 {
100 $obj = new assMultipleChoice();
101 $this->assertEquals(false, $obj->isComplete());
102 $obj->setTitle('Tilte');
103 $obj->setAuthor('Me or another');
104 $obj->setQuestion('My great Question.');
105 $obj->addAnswer('Super simple single Choice', 1);
106
107 $this->assertEquals(true, $obj->isComplete());
108 }
109
111 {
112 $obj = new assMultipleChoice();
113 $this->assertEquals('thumb.', $obj->getThumbPrefix());
114 }
115
117 {
118 $obj = new assMultipleChoice();
119 $obj->setOutputType(0);
120 $this->assertEquals(0, $obj->getOutputType());
121 }
123 {
124 $obj = new assMultipleChoice();
125 $this->assertEquals(0, $obj->getAnswerCount());
126 $obj->addAnswer('Points for checked', 1, 0, 0);
127 $obj->addAnswer('Points for unchecked', 0, 1, 1);
128 $this->assertEquals(2, $obj->getAnswerCount());
129 $obj->deleteAnswer(0);
130 $this->assertEquals(1, $obj->getAnswerCount());
131 }
132
134 {
135 $obj = new assMultipleChoice();
136 $obj->addAnswer('1', 1, 0, 0);
137 $obj->addAnswer('1', 1, 0, 1);
138 $this->assertEquals(2, $obj->getAnswerCount());
139 $obj->flushAnswers();
140 $this->assertEquals(0, $obj->getAnswerCount());
141 }
142
144 {
145 $obj = new assMultipleChoice();
146 $this->assertEquals('assMultipleChoice', $obj->getQuestionType());
147 }
148
150 {
151 $obj = new assMultipleChoice();
152 $this->assertEquals('qpl_qst_mc', $obj->getAdditionalTableName());
153 }
154
156 {
157 $obj = new assMultipleChoice();
158 $this->assertEquals('qpl_a_mc', $obj->getAnswerTableName());
159 }
160
162 {
163 $obj = new assMultipleChoice();
164 $obj->addAnswer('Points for checked', 1, 0, 0);
165 $obj->addAnswer('Points for checked', 1, 0, 1);
166 $this->assertEquals(2, $obj->getMaximumPoints());
167 }
169 {
170 $obj = new assMultipleChoice();
171 $obj->addAnswer('Points for unchecked', 0, 1, 0);
172 $obj->addAnswer('Points for unchecked', 0, 1, 1);
173 $this->assertEquals(2, $obj->getMaximumPoints());
174 }
176 {
177 $obj = new assMultipleChoice();
178 $obj->addAnswer('Points for unchecked', 0, 1, 0);
179 $obj->addAnswer('Points for unchecked', 0, 1, 1);
180 $this->assertEquals(2, $obj->getMaximumPoints());
181 $obj->addAnswer('Points for checked', 1, 0, 2);
182 $obj->addAnswer('Points for checked', 1, 0, 3);
183 $this->assertEquals(4, $obj->getMaximumPoints());
184 $obj->addAnswer('Points for checked', 1, 1, 4);
185 $obj->addAnswer('Points for checked', 1, 1, 5);
186 $this->assertEquals(6, $obj->getMaximumPoints());
187 }
188}
An exception for terminatinating execution or to throw for unit testing.
Unit tests for single choice questions.
test_isComplete_shouldReturnTrue()
Create a sample question and save it to the database.
test_getMaximumPointsIfMoreForUnchecked_shouldReturnAnswerTableName()
Class for multiple choice tests.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27