ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 if (defined('ILIAS_PHPUNIT_CONTEXT'))
20 {
21 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
22 ilUnitUtil::performInitialisation();
23 }
24 else
25 {
26 chdir( dirname( __FILE__ ) );
27 chdir('../../../');
28 }
29 }
30
37 public static function createSampleQuestion($obj_id = null)
38 {
39 $obj_id = ($obj_id) ? $obj_id : 99999999;
40 include_once './Modules/TestQuestionPool/classes/class.assMultipleChoice.php';
41
42 $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>');
43 $mc->addAnswer(
44 'important',
45 0.5,
46 -0.5,
47 1
48 );
49 $mc->addAnswer(
50 'useless',
51 -0.5,
52 0.5,
53 2
54 );
55 $mc->addAnswer(
56 'stupid',
57 -0.5,
58 0.5,
59 3
60 );
61 $mc->addAnswer(
62 'cool',
63 0.5,
64 -0.5,
65 4
66 );
67 $mc->setObjId($obj_id);
68 $mc->saveToDb();
69 return $mc->getId();
70 }
71
77 public function t_e_stCreation()
78 {
79 global $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}
$result
Unit tests for single choice questions.
static createSampleQuestion($obj_id=null)
Create a sample question and save it to the database.
t_e_stCreation()
Question creation test.
Class for multiple choice tests.
global $ilDB