ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 require_once './Services/UICore/classes/class.ilCtrl.php';
25 $ilCtrl_mock = $this->createMock('ilCtrl');
26 $ilCtrl_mock->expects($this->any())->method('saveParameter');
27 $ilCtrl_mock->expects($this->any())->method('saveParameterByClass');
28 global $ilCtrl;
29 $ilCtrl = $ilCtrl_mock;
30
31 require_once './Services/Language/classes/class.ilLanguage.php';
32 $lng_mock = $this->createMock('ilLanguage', array('txt'), array(), '', false);
33 //$lng_mock->expects( $this->once() )->method( 'txt' )->will( $this->returnValue('Test') );
34 global $lng;
35 $lng = $lng_mock;
36
37 $ilias_mock = new stdClass();
38 $ilias_mock->account = new stdClass();
39 $ilias_mock->account->id = 6;
40 $ilias_mock->account->fullname = 'Esther Tester';
41 global $ilias;
42 $ilias = $ilias_mock;
43 }
44 }
45
47 {
48 // Arrange
49 require_once './Modules/TestQuestionPool/classes/class.assErrorText.php';
50
51 // Act
52 $instance = new assErrorText();
53
54 // Assert
55 $this->assertInstanceOf('assErrorText', $instance);
56 }
57
58 public function test_getErrorsFromText()
59 {
60 // Arrange
61 require_once './Modules/TestQuestionPool/classes/class.assErrorText.php';
62 $instance = new assErrorText();
63
64 $errortext = '
65 Eine ((Kündigung)) kommt durch zwei gleichlautende Willenserklärungen zustande.
66 Ein Vertrag kommt durch ((drei gleichlaute)) Willenserklärungen zustande.
67 Ein Kaufvertrag an der Kasse im #Supermarkt kommt durch das legen von Ware auf das
68 Kassierband und den Kassiervorgang zustande. Dies nennt man ((konsequentes)) Handeln.';
69
70 $expected = array(
71 'passages' => array( 0 => 'Kündigung', 1=> 'drei gleichlaute', 3 => 'konsequentes'),
72 'words' => array( 2 => 'Supermarkt')
73 );
74
75 // Act
76 $actual = $instance->getErrorsFromText($errortext);
77
78 // Assert
79 $this->assertEquals($expected, $actual);
80 }
81
83 {
84 // Arrange
85 require_once './Modules/TestQuestionPool/classes/class.assErrorText.php';
86 $instance = new assErrorText();
87
88 $errortext = '
89 Eine Kündigung)) kommt durch zwei gleichlautende (Willenserklärungen) zustande.
90 Ein Vertrag kommt durch (drei gleichlaute) Willenserklärungen zustande.
91 Ein Kaufvertrag an der Kasse im Supermarkt [kommt] durch das legen von Ware auf das
92 Kassierband und den [[Kassiervorgang]] zustande. Dies nennt man *konsequentes Handeln.';
93
94 $expected = array();
95
96 // Act
97 $actual = $instance->getErrorsFromText($errortext);
98
99 // Assert
100 $this->assertEquals($expected, $actual);
101 }
102
104 {
105 // Arrange
106 require_once './Modules/TestQuestionPool/classes/class.assErrorText.php';
107 $instance = new assErrorText();
108
109 $errortext = '
110 Eine ((Kündigung)) kommt durch zwei gleichlautende Willenserklärungen zustande.
111 Ein Vertrag kommt durch ((drei gleichlaute)) Willenserklärungen zustande.
112 Ein Kaufvertrag an der Kasse im #Supermarkt kommt durch das legen von Ware auf das
113 Kassierband und den Kassiervorgang zustande. Dies nennt man ((konsequentes)) Handeln.';
114
115 $expected = array(
116 'passages' => array( 0 => 'Kündigung', 1=> 'drei gleichlaute', 3 => 'konsequentes'),
117 'words' => array( 2 => 'Supermarkt')
118 );
119
120 // Act
121 $instance->setErrorText($errortext);
122 $actual = $instance->getErrorsFromText('');
123
124 // Assert
125 $this->assertEquals($expected, $actual);
126 }
127
129 {
130 // Arrange
131 require_once './Modules/TestQuestionPool/classes/class.assErrorText.php';
132 $instance = new assErrorText();
133
134 $errordata = array('passages' => array( 0 => 'drei Matrosen'), 'words' => array());
135 require_once "./Modules/TestQuestionPool/classes/class.assAnswerErrorText.php";
136 $expected = new assAnswerErrorText($errordata['passages'][0], '', 0.0);
137
138 // Act
139 $instance->setErrorData($errordata);
140
141 $all_errors = $instance->getErrorData();
142 $actual = $all_errors[0];
143
144 // Assert
145 $this->assertEquals($expected, $actual);
146 }
147
149 {
150 // Arrange
151 require_once './Modules/TestQuestionPool/classes/class.assErrorText.php';
152 $instance = new assErrorText();
153
154 $errordata = array('passages' => array( 0 => 'drei Matrosen'), 'words' => array());
155 require_once "./Modules/TestQuestionPool/classes/class.assAnswerErrorText.php";
156 $expected = new assAnswerErrorText($errordata['passages'][0], '', 0);
157 $instance->errordata = $expected;
158
159 // Act
160 $instance->setErrorData($errordata);
161
162 $all_errors = $instance->getErrorData();
163 $actual = $all_errors[0];
164
165 // Assert
166 $this->assertEquals($expected, $actual);
167 }
168}
An exception for terminatinating execution or to throw for unit testing.
Class for error text answers.
Unit tests for assErrorTextTest.
test_getErrorsFromText_emptyArgShouldPullInternal()
Class for error text questions.
global $ilCtrl
Definition: ilias.php:18
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
global $lng
Definition: privfeed.php:17