ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
assMultipleChoiceTest.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
34 {
35  protected $backupGlobals = FALSE;
36 
37  protected function setUp()
38  {
39  if (defined('ILIAS_PHPUNIT_CONTEXT'))
40  {
41  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
42  ilUnitUtil::performInitialisation();
43  }
44  else
45  {
46  chdir( dirname( __FILE__ ) );
47  chdir('../../../');
48  }
49  }
50 
57  public static function createSampleQuestion($obj_id = null)
58  {
59  $obj_id = ($obj_id) ? $obj_id : 99999999;
60  include_once './Modules/TestQuestionPool/classes/class.assMultipleChoice.php';
61 
62  $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>');
63  $mc->addAnswer(
64  'important',
65  0.5,
66  -0.5,
67  1
68  );
69  $mc->addAnswer(
70  'useless',
71  -0.5,
72  0.5,
73  2
74  );
75  $mc->addAnswer(
76  'stupid',
77  -0.5,
78  0.5,
79  3
80  );
81  $mc->addAnswer(
82  'cool',
83  0.5,
84  -0.5,
85  4
86  );
87  $mc->setObjId($obj_id);
88  $mc->saveToDb();
89  return $mc->getId();
90  }
91 
97  public function testCreation()
98  {
99  global $ilDB;
100 
101  include_once './Modules/TestQuestionPool/classes/class.assMultipleChoice.php';
103  $this->assertGreaterThan(0, $insert_id);
104  if ($insert_id > 0)
105  {
106  $mc = new assMultipleChoice();
107  $mc->loadFromDb($insert_id);
108  $this->assertEquals($mc->getPoints(),2);
109  $this->assertEquals($mc->getTitle(),"unit test multiple choice question");
110  $this->assertEquals($mc->getComment(),"unit test multiple choice question comment");
111  $this->assertEquals($mc->getAuthor(),"Helmut Schottmüller");
112  $this->assertEquals($mc->getQuestion(),"<p><strong>unit tests</strong> are...</p>");
113  $this->assertEquals(count($mc->getAnswers()), 4);
114  $result = $mc->delete($insert_id);
115  $this->assertEquals($result,true);
116  }
117  }
118 }