ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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() : void
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  */
99 
100  /* Removed by @kergomard 17 NOV 2022, we should introduce this again
101  public function test_isComplete_shouldReturnTrue()
102  {
103  $obj = new assMultipleChoice();
104  $this->assertEquals(false, $obj->isComplete());
105  $obj->setTitle('Tilte');
106  $obj->setAuthor('Me or another');
107  $obj->setQuestion('My great Question.');
108  $obj->addAnswer('Super simple single Choice', 1);
109 
110  $this->assertEquals(true, $obj->isComplete());
111  } */
112 
114  {
115  $obj = new assMultipleChoice();
116  $this->assertEquals('thumb.', $obj->getThumbPrefix());
117  }
118 
120  {
121  $obj = new assMultipleChoice();
122  $obj->setOutputType(0);
123  $this->assertEquals(0, $obj->getOutputType());
124  }
125 
126  /* Removed by @kergomard 17 NOV 2022, we should introduce this again
127  public function test_getAnswerCount_shouldReturnCount()
128  {
129  $obj = new assMultipleChoice();
130  $this->assertEquals(0, $obj->getAnswerCount());
131  $obj->addAnswer('Points for checked', 1, 0, 0);
132  $obj->addAnswer('Points for unchecked', 0, 1, 1);
133  $this->assertEquals(2, $obj->getAnswerCount());
134  $obj->deleteAnswer(0);
135  $this->assertEquals(1, $obj->getAnswerCount());
136  }
137 
138  public function test_flushAnswers_shouldClearAnswers()
139  {
140  $obj = new assMultipleChoice();
141  $obj->addAnswer('1', 1, 0, 0);
142  $obj->addAnswer('1', 1, 0, 1);
143  $this->assertEquals(2, $obj->getAnswerCount());
144  $obj->flushAnswers();
145  $this->assertEquals(0, $obj->getAnswerCount());
146  } */
147 
149  {
150  $obj = new assMultipleChoice();
151  $this->assertEquals('assMultipleChoice', $obj->getQuestionType());
152  }
153 
155  {
156  $obj = new assMultipleChoice();
157  $this->assertEquals('qpl_qst_mc', $obj->getAdditionalTableName());
158  }
159 
161  {
162  $obj = new assMultipleChoice();
163  $this->assertEquals('qpl_a_mc', $obj->getAnswerTableName());
164  }
165 
166  /* Removed by @kergomard 17 NOV 2022, we should introduce this again
167  public function test_getMaximumPoints_shouldReturnAnswerTableName()
168  {
169  $obj = new assMultipleChoice();
170  $obj->addAnswer('Points for checked', 1, 0, 0);
171  $obj->addAnswer('Points for checked', 1, 0, 1);
172  $this->assertEquals(2, $obj->getMaximumPoints());
173  }
174  public function test_getMaximumPointsIfMoreForUnchecked_shouldReturnAnswerTableName()
175  {
176  $obj = new assMultipleChoice();
177  $obj->addAnswer('Points for unchecked', 0, 1, 0);
178  $obj->addAnswer('Points for unchecked', 0, 1, 1);
179  $this->assertEquals(2, $obj->getMaximumPoints());
180  }
181  public function test_getMaximumPointsMixed_shouldReturnAnswerTableName()
182  {
183  $obj = new assMultipleChoice();
184  $obj->addAnswer('Points for unchecked', 0, 1, 0);
185  $obj->addAnswer('Points for unchecked', 0, 1, 1);
186  $this->assertEquals(2, $obj->getMaximumPoints());
187  $obj->addAnswer('Points for checked', 1, 0, 2);
188  $obj->addAnswer('Points for checked', 1, 0, 3);
189  $this->assertEquals(4, $obj->getMaximumPoints());
190  $obj->addAnswer('Points for checked', 1, 1, 4);
191  $obj->addAnswer('Points for checked', 1, 1, 5);
192  $this->assertEquals(6, $obj->getMaximumPoints());
193  } */
194 }
test_getThumbPrefix_shouldReturnString()
Create a sample question and save it to the database.
Class assBaseTestCase.
Class for multiple choice tests.
Unit tests for single choice questions.