ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
79  $ilDB = $DIC['ilDB'];
80 
81  include_once './Modules/TestQuestionPool/classes/class.assMultipleChoice.php';
82  $insert_id = self::createSampleQuestion(null);
83  $this->assertGreaterThan(0, $insert_id);
84  if ($insert_id > 0)
85  {
86  $mc = new assMultipleChoice();
87  $mc->loadFromDb($insert_id);
88  $this->assertEquals($mc->getPoints(),2);
89  $this->assertEquals($mc->getTitle(),"unit test multiple choice question");
90  $this->assertEquals($mc->getComment(),"unit test multiple choice question comment");
91  $this->assertEquals($mc->getAuthor(),"Helmut Schottmüller");
92  $this->assertEquals($mc->getQuestion(),"<p><strong>unit tests</strong> are...</p>");
93  $this->assertEquals(count($mc->getAnswers()), 4);
94  $result = $mc->delete($insert_id);
95  $this->assertEquals($result,true);
96  }
97  }
98  */
100  {
101  $obj = new assMultipleChoice();
102  $this->assertEquals(false, $obj->isComplete());
103  $obj->setTitle('Tilte');
104  $obj->setAuthor('Me or another');
105  $obj->setQuestion('My great Question.');
106  $obj->addAnswer('Super simple single Choice', 1);
107 
108  $this->assertEquals(true, $obj->isComplete());
109  }
110 
112  {
113  $obj = new assMultipleChoice();
114  $this->assertEquals('thumb.', $obj->getThumbPrefix());
115  }
116 
118  {
119  $obj = new assMultipleChoice();
120  $obj->setOutputType(0);
121  $this->assertEquals(0, $obj->getOutputType());
122  }
124  {
125  $obj = new assMultipleChoice();
126  $this->assertEquals(0, $obj->getAnswerCount());
127  $obj->addAnswer('Points for checked', 1, 0, 0);
128  $obj->addAnswer('Points for unchecked', 0, 1, 1);
129  $this->assertEquals(2, $obj->getAnswerCount());
130  $obj->deleteAnswer(0);
131  $this->assertEquals(1, $obj->getAnswerCount());
132  }
133 
135  {
136  $obj = new assMultipleChoice();
137  $obj->addAnswer('1', 1, 0, 0);
138  $obj->addAnswer('1', 1, 0, 1);
139  $this->assertEquals(2, $obj->getAnswerCount());
140  $obj->flushAnswers();
141  $this->assertEquals(0, $obj->getAnswerCount());
142  }
143 
145  {
146  $obj = new assMultipleChoice();
147  $this->assertEquals('assMultipleChoice', $obj->getQuestionType());
148  }
149 
151  {
152  $obj = new assMultipleChoice();
153  $this->assertEquals('qpl_qst_mc', $obj->getAdditionalTableName());
154  }
155 
157  {
158  $obj = new assMultipleChoice();
159  $this->assertEquals('qpl_a_mc', $obj->getAnswerTableName());
160  }
161 
163  {
164  $obj = new assMultipleChoice();
165  $obj->addAnswer('Points for checked', 1, 0, 0);
166  $obj->addAnswer('Points for checked', 1, 0, 1);
167  $this->assertEquals(2, $obj->getMaximumPoints());
168  }
170  {
171  $obj = new assMultipleChoice();
172  $obj->addAnswer('Points for unchecked', 0, 1, 0);
173  $obj->addAnswer('Points for unchecked', 0, 1, 1);
174  $this->assertEquals(2, $obj->getMaximumPoints());
175  }
177  {
178  $obj = new assMultipleChoice();
179  $obj->addAnswer('Points for unchecked', 0, 1, 0);
180  $obj->addAnswer('Points for unchecked', 0, 1, 1);
181  $this->assertEquals(2, $obj->getMaximumPoints());
182  $obj->addAnswer('Points for checked', 1, 0, 2);
183  $obj->addAnswer('Points for checked', 1, 0, 3);
184  $this->assertEquals(4, $obj->getMaximumPoints());
185  $obj->addAnswer('Points for checked', 1, 1, 4);
186  $obj->addAnswer('Points for checked', 1, 1, 5);
187  $this->assertEquals(6, $obj->getMaximumPoints());
188  }
189 }
test_isComplete_shouldReturnTrue()
Create a sample question and save it to the database.
Class for multiple choice tests.
Unit tests for single choice questions.
test_getMaximumPointsIfMoreForUnchecked_shouldReturnAnswerTableName()