ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
assErrorTextTest.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  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
19  ilUnitUtil::performInitialisation();
20  } else {
21  chdir(dirname(__FILE__));
22  chdir('../../../');
23 
24  parent::setUp();
25 
26  require_once './Services/UICore/classes/class.ilCtrl.php';
27  $ilCtrl_mock = $this->createMock('ilCtrl');
28  $ilCtrl_mock->expects($this->any())->method('saveParameter');
29  $ilCtrl_mock->expects($this->any())->method('saveParameterByClass');
30  $this->setGlobalVariable('ilCtrl', $ilCtrl_mock);
31 
32  require_once './Services/Language/classes/class.ilLanguage.php';
33  $lng_mock = $this->createMock('ilLanguage', array('txt'), array(), '', false);
34  //$lng_mock->expects( $this->once() )->method( 'txt' )->will( $this->returnValue('Test') );
35  $this->setGlobalVariable('lng', $lng_mock);
36 
37  $this->setGlobalVariable('ilias', $this->getIliasMock());
38  $this->setGlobalVariable('tpl', $this->getGlobalTemplateMock());
39  $this->setGlobalVariable('ilDB', $this->getDatabaseMock());
40  }
41  }
42 
43  public function test_instantiateObjectSimple()
44  {
45  // Arrange
46  require_once './Modules/TestQuestionPool/classes/class.assErrorText.php';
47 
48  // Act
49  $instance = new assErrorText();
50 
51  // Assert
52  $this->assertInstanceOf('assErrorText', $instance);
53  }
54 
55  public function test_getErrorsFromText()
56  {
57  // Arrange
58  require_once './Modules/TestQuestionPool/classes/class.assErrorText.php';
59  $instance = new assErrorText();
60 
61  $errortext = '
62  Eine ((Kündigung)) kommt durch zwei gleichlautende Willenserklärungen zustande.
63  Ein Vertrag kommt durch ((drei gleichlaute)) Willenserklärungen zustande.
64  Ein Kaufvertrag an der Kasse im #Supermarkt kommt durch das legen von Ware auf das
65  Kassierband und den Kassiervorgang zustande. Dies nennt man ((konsequentes)) Handeln.';
66 
67  $expected = array(
68  'passages' => array( 0 => 'Kündigung', 1 => 'drei gleichlaute', 3 => 'konsequentes'),
69  'words' => array( 2 => 'Supermarkt')
70  );
71 
72  // Act
73  $actual = $instance->getErrorsFromText($errortext);
74 
75  // Assert
76  $this->assertEquals($expected, $actual);
77  }
78 
80  {
81  // Arrange
82  require_once './Modules/TestQuestionPool/classes/class.assErrorText.php';
83  $instance = new assErrorText();
84 
85  $errortext = '
86  Eine Kündigung)) kommt durch zwei gleichlautende (Willenserklärungen) zustande.
87  Ein Vertrag kommt durch (drei gleichlaute) Willenserklärungen zustande.
88  Ein Kaufvertrag an der Kasse im Supermarkt [kommt] durch das legen von Ware auf das
89  Kassierband und den [[Kassiervorgang]] zustande. Dies nennt man *konsequentes Handeln.';
90 
91  $expected = array();
92 
93  // Act
94  $actual = $instance->getErrorsFromText($errortext);
95 
96  // Assert
97  $this->assertEquals($expected, $actual);
98  }
99 
101  {
102  // Arrange
103  require_once './Modules/TestQuestionPool/classes/class.assErrorText.php';
104  $instance = new assErrorText();
105 
106  $errortext = '
107  Eine ((Kündigung)) kommt durch zwei gleichlautende Willenserklärungen zustande.
108  Ein Vertrag kommt durch ((drei gleichlaute)) Willenserklärungen zustande.
109  Ein Kaufvertrag an der Kasse im #Supermarkt kommt durch das legen von Ware auf das
110  Kassierband und den Kassiervorgang zustande. Dies nennt man ((konsequentes)) Handeln.';
111 
112  $expected = array(
113  'passages' => array( 0 => 'Kündigung', 1 => 'drei gleichlaute', 3 => 'konsequentes'),
114  'words' => array( 2 => 'Supermarkt')
115  );
116 
117  // Act
118  $instance->setErrorText($errortext);
119  $actual = $instance->getErrorsFromText('');
120 
121  // Assert
122  $this->assertEquals($expected, $actual);
123  }
124 
125  public function test_setErrordata_newError()
126  {
127  // Arrange
128  require_once './Modules/TestQuestionPool/classes/class.assErrorText.php';
129  $instance = new assErrorText();
130 
131  $errordata = array('passages' => array( 0 => 'drei Matrosen'), 'words' => array());
132  require_once "./Modules/TestQuestionPool/classes/class.assAnswerErrorText.php";
133  $expected = new assAnswerErrorText($errordata['passages'][0], '', 0.0);
134 
135  // Act
136  $instance->setErrorData($errordata);
137 
138  $all_errors = $instance->getErrorData();
139  $actual = $all_errors[0];
140 
141  // Assert
142  $this->assertEquals($expected, $actual);
143  }
144 
146  {
147  // Arrange
148  require_once './Modules/TestQuestionPool/classes/class.assErrorText.php';
149  $instance = new assErrorText();
150 
151  $errordata = array('passages' => array( 0 => 'drei Matrosen'), 'words' => array());
152  require_once "./Modules/TestQuestionPool/classes/class.assAnswerErrorText.php";
153  $expected = new assAnswerErrorText($errordata['passages'][0], '', 0);
154  $instance->errordata = $expected;
155 
156  // Act
157  $instance->setErrorData($errordata);
158 
159  $all_errors = $instance->getErrorData();
160  $actual = $all_errors[0];
161 
162  // Assert
163  $this->assertEquals($expected, $actual);
164  }
165 }
Unit tests for assErrorTextTest.
Class assBaseTestCase.
Class for error text answers.
setGlobalVariable($name, $value)
test_getErrorsFromText_emptyArgShouldPullInternal()
Class for error text questions.