ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
assSingleChoiceTest.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.assSingleChoice.php';
20 if (defined('ILIAS_PHPUNIT_CONTEXT'))
21 {
22 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
23 ilUnitUtil::performInitialisation();
24 }
25 else
26 {
27 chdir( dirname( __FILE__ ) );
28 chdir('../../../');
29 }
30 require_once './Services/Utilities/classes/class.ilUtil.php';
31 }
32
39 /*public static function createSampleQuestion($obj_id = null)
40 {
41 $obj_id = ($obj_id) ? $obj_id : 99999999;
42 include_once './Modules/TestQuestionPool/classes/class.assSingleChoice.php';
43 $sc = new assSingleChoice('unit test single choice question', 'unit test single choice question comment', 'Helmut Schottmüller', -1, '<p>is a <strong>unit test</strong> required?</p>');
44 $sc->addAnswer(
45 'Yes',
46 1,
47 0,
48 1
49 );
50 $sc->addAnswer(
51 'No',
52 -1,
53 0,
54 2
55 );
56 $sc->setObjId($obj_id);
57 $sc->saveToDb();
58 return $sc->getId();
59 }*/
60
66 /*public function t_e_stCreation()
67 {
68 global $ilDB;
69
70 include_once './Modules/TestQuestionPool/classes/class.assSingleChoice.php';
71 $insert_id = ilassSingleChoiceTest::createSampleQuestion();
72 $this->assertGreaterThan(0, $insert_id);
73 if ($insert_id > 0)
74 {
75 $sc = new assSingleChoice();
76 $sc->loadFromDb($insert_id);
77 $this->assertEquals($sc->getPoints(),1);
78 $this->assertEquals($sc->getTitle(),"unit test single choice question");
79 $this->assertEquals($sc->getComment(),"unit test single choice question comment");
80 $this->assertEquals($sc->getAuthor(),"Helmut Schottmüller");
81 $this->assertEquals($sc->getQuestion(),"<p>is a <strong>unit test</strong> required?</p>");
82 $this->assertEquals(count($sc->getAnswers()), 2);
83 $result = $sc->delete($insert_id);
84 $this->assertEquals($result,true);
85 }
86 }
87*/
89 {
90 $obj = new assSingleChoice();
91 $this->assertEquals(false, $obj->isComplete());
92 $obj->setTitle('Tilte');
93 $obj->setAuthor('Me or another');
94 $obj->setQuestion('My great Question.');
95 $obj->addAnswer('Super simple single Choice', 1);
96
97 $this->assertEquals(true, $obj->isComplete());
98 }
99
101 {
102 $obj = new assSingleChoice();
103 $this->assertEquals('thumb.', $obj->getThumbPrefix());
104 }
105
107 {
108 $obj = new assSingleChoice();
109 $obj->setOutputType(0);
110 $this->assertEquals(0, $obj->getOutputType());
111 }
112
114 {
115 $obj = new assSingleChoice();
116 $this->assertEquals(0, $obj->getAnswerCount());
117 $obj->addAnswer('1', 1, 0);
118 $obj->addAnswer('1', 1, 1);
119 $this->assertEquals(2, $obj->getAnswerCount());
120 $obj->deleteAnswer(0);
121 $this->assertEquals(1, $obj->getAnswerCount());
122 }
123
125 {
126 $obj = new assSingleChoice();
127 $obj->addAnswer('1', 1, 0);
128 $obj->addAnswer('1', 1, 1);
129 $this->assertEquals(2, $obj->getAnswerCount());
130 $obj->flushAnswers();
131 $this->assertEquals(0, $obj->getAnswerCount());
132 }
133
135 {
136 $obj = new assSingleChoice();
137 $this->assertEquals('assSingleChoice', $obj->getQuestionType());
138 }
139
141 {
142 $obj = new assSingleChoice();
143 $this->assertEquals('qpl_qst_sc', $obj->getAdditionalTableName());
144 }
145
147 {
148 $obj = new assSingleChoice();
149 $this->assertEquals('qpl_a_sc', $obj->getAnswerTableName());
150 }
151
152}
Unit tests for single choice questions.
test_getAdditionalTableName_shouldReturnAdditionalTableName()
test_isComplete_shouldReturnTrue()
Create a sample question and save it to the database.
Class for single choice questions.