ILIAS  release_4-4 Revision
assAnswerOrderingTest.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
13  protected $backupGlobals = FALSE;
14 
15  protected function setUp()
16  {
17  if (defined('ILIAS_PHPUNIT_CONTEXT'))
18  {
19  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
20  ilUnitUtil::performInitialisation();
21  }
22  else
23  {
24  chdir( dirname( __FILE__ ) );
25  chdir('../../../');
26  }
27  }
28 
30  {
31  // Arrange
32  require_once './Modules/TestQuestionPool/classes/class.assAnswerOrdering.php';
33 
34  // Act
35  $instance = new ASS_AnswerOrdering();
36 
37  $this->assertInstanceOf('ASS_AnswerOrdering', $instance);
38  }
39 
40  public function test_setGetRandomId()
41  {
42  // Arrange
43  require_once './Modules/TestQuestionPool/classes/class.assAnswerOrdering.php';
44  $instance = new ASS_AnswerOrdering();
45  $expected = 13579;
46 
47  // Act
48  $instance->setRandomID($expected);
49  $actual = $instance->getRandomID();
50 
51  // Assert
52  $this->assertEquals($expected, $actual);
53  }
54 
55  public function test_setGetAnswerId()
56  {
57  // Arrange
58  require_once './Modules/TestQuestionPool/classes/class.assAnswerOrdering.php';
59  $instance = new ASS_AnswerOrdering();
60  $expected = 13579;
61 
62  // Act
63  $instance->setAnswerId($expected);
64  $actual = $instance->getAnswerId();
65 
66  // Assert
67  $this->assertEquals($expected, $actual);
68  }
69 
70 
71  public function test_setGetOrdeingDepth()
72  {
73  // Arrange
74  require_once './Modules/TestQuestionPool/classes/class.assAnswerOrdering.php';
75  $instance = new ASS_AnswerOrdering();
76  $expected = 13579;
77 
78  // Act
79  $instance->setOrderingDepth($expected);
80  $actual = $instance->getOrderingDepth();
81 
82  // Assert
83  $this->assertEquals($expected, $actual);
84  }
85 
87  {
88  // Arrange
89  require_once './Modules/TestQuestionPool/classes/class.assAnswerOrdering.php';
90  $instance = new ASS_AnswerOrdering();
91  $random_id = 13579;
92 
93  //require_once './Services/PEAR/lib/MDB2.php';
94  require_once './Services/Database/classes/class.ilDB.php';
95  $ildb_mock = $this->getMock('ilDBMySQL', array('queryF', 'fetchAssoc'), array(), '', false, false);
96  $ildb_mock->expects( $this->once() )
97  ->method( 'queryF' )
98  ->with( $this->equalTo('SELECT * FROM qpl_a_ordering WHERE random_id = %s'),
99  $this->equalTo(array('integer')),
100  $this->equalTo(array($random_id))
101  )
102  ->will( $this->returnValue('Test') );
103  $ildb_mock->expects( $this->exactly(2) )
104  ->method( 'fetchAssoc' )
105  ->with( $this->equalTo('Test') )
106  ->will( $this->onConsecutiveCalls(array('answer_id' => 123, 'depth' => 456), false ) );
107  global $ilDB;
108  $ilDB = $ildb_mock;
109 
110  // Act
111  $instance->getAdditionalOrderingFieldsByRandomId($random_id);
112 
113  // Assert
114  $this->assertEquals(123, $instance->getAnswerId());
115  $this->assertEquals(456, $instance->getOrderingDepth());
116  }
117 }
Class for ordering question answers.