ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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() : void
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
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
100 /* Removed by @kergomard 17 NOV 2022, we should introduce this again
101 public function test_getErrorsFromText_emptyArgShouldPullInternal()
102 {
103 // Arrange
104 require_once './Modules/TestQuestionPool/classes/class.assErrorText.php';
105 $instance = new assErrorText();
106
107 $errortext = '
108 Eine ((Kündigung)) kommt durch zwei gleichlautende Willenserklärungen zustande.
109 Ein Vertrag kommt durch ((drei gleichlaute)) Willenserklärungen zustande.
110 Ein Kaufvertrag an der Kasse im #Supermarkt kommt durch das legen von Ware auf das
111 Kassierband und den Kassiervorgang zustande. Dies nennt man ((konsequentes)) Handeln.';
112
113 $expected = array(
114 'passages' => array( 0 => 'Kündigung', 1 => 'drei gleichlaute', 3 => 'konsequentes'),
115 'words' => array( 2 => 'Supermarkt')
116 );
117
118 // Act
119 $instance->setErrorText($errortext);
120 $actual = $instance->getErrorsFromText('');
121
122 // Assert
123 $this->assertEquals($expected, $actual);
124 } */
125
127 {
128 // Arrange
129 require_once './Modules/TestQuestionPool/classes/class.assErrorText.php';
130 $instance = new assErrorText();
131
132 $errordata = array('passages' => array( 0 => 'drei Matrosen'), 'words' => array());
133 require_once "./Modules/TestQuestionPool/classes/class.assAnswerErrorText.php";
134 $expected = new assAnswerErrorText($errordata['passages'][0], '', 0.0);
135
136 // Act
137 $instance->setErrorData($errordata);
138
139 $all_errors = $instance->getErrorData();
140 $actual = $all_errors[0];
141
142 // Assert
143 $this->assertEquals($expected, $actual);
144 }
145
147 {
148 // Arrange
149 require_once './Modules/TestQuestionPool/classes/class.assErrorText.php';
150 $instance = new assErrorText();
151
152 $errordata = array('passages' => array( 0 => 'drei Matrosen'), 'words' => array());
153 require_once "./Modules/TestQuestionPool/classes/class.assAnswerErrorText.php";
154 $expected = new assAnswerErrorText($errordata['passages'][0], '', 0);
155 $instance->errordata = $expected;
156
157 // Act
158 $instance->setErrorData($errordata);
159
160 $all_errors = $instance->getErrorData();
161 $actual = $all_errors[0];
162
163 // Assert
164 $this->assertEquals($expected, $actual);
165 }
166}
An exception for terminatinating execution or to throw for unit testing.
Class for error text answers.
Class assBaseTestCase.
setGlobalVariable($name, $value)
Unit tests for assErrorTextTest.
Class for error text questions.