ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilLoggingActivityTest Class Reference

ilLoggingActivityTest is part of the petri net based workflow engine. More...

+ Inheritance diagram for ilLoggingActivityTest:
+ Collaboration diagram for ilLoggingActivityTest:

Public Member Functions

 setUp ()
 
 tearDown ()
 
 testConstructorValidContext ()
 
 testSetGetValidLogFile ()
 
 testSetGetNonWriteableLogFile ()
 
 testSetGetIllegalExtensionLogFile ()
 
 testSetGetLegalMessage ()
 
 testSetGetNullLogMessage ()
 
 testSetGetEmptyLogMessage ()
 
 testSetGetValidLogLevel ()
 
 testSetGetInvalidLogLevel ()
 
 testExecute ()
 
 testPassInUnwriteablePath ()
 
 testGetContext ()
 

Data Fields

 $test_dir
 vfsStream Test Directory, see setup. More...
 

Detailed Description

ilLoggingActivityTest is part of the petri net based workflow engine.

This class holds all tests for the class activities/class.ilLoggingActivity

Author
Maximilian Becker mbeck.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

/

Definition at line 17 of file ilLoggingActivityTest.php.

Member Function Documentation

◆ setUp()

ilLoggingActivityTest::setUp ( )

Definition at line 22 of file ilLoggingActivityTest.php.

22 : void
23 {
24 chdir(dirname(__FILE__));
25 chdir('../../../../');
26
27 try {
28 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
29 //ilUnitUtil::performInitialisation();
30 } catch (Exception $exception) {
31 if (!defined('IL_PHPUNIT_TEST')) {
32 define('IL_PHPUNIT_TEST', false);
33 }
34 }
35
36 // Empty workflow.
37 require_once './Services/WorkflowEngine/classes/workflows/class.ilEmptyWorkflow.php';
38 $this->workflow = new ilEmptyWorkflow();
39
40 // Basic node
41 require_once './Services/WorkflowEngine/classes/nodes/class.ilBasicNode.php';
42 $this->node = new ilBasicNode($this->workflow);
43
44 // Wiring up so the node is attached to the workflow.
45 $this->workflow->addNode($this->node);
46
47 require_once './Services/WorkflowEngine/classes/activities/class.ilLoggingActivity.php';
48
49 $this->test_dir = vfs\vfsStream::setup('example');
50 }
@noinspection PhpIncludeInspection
@noinspection PhpIncludeInspection

◆ tearDown()

ilLoggingActivityTest::tearDown ( )

Definition at line 52 of file ilLoggingActivityTest.php.

52 : void
53 {
54 global $ilSetting;
55 if ($ilSetting != null) {
56 //$ilSetting->delete('IL_PHPUNIT_TEST_TIME');
57 //$ilSetting->delete('IL_PHPUNIT_TEST_MICROTIME');
58 }
59 }
global $ilSetting
Definition: privfeed.php:17

References $ilSetting.

◆ testConstructorValidContext()

ilLoggingActivityTest::testConstructorValidContext ( )

Definition at line 61 of file ilLoggingActivityTest.php.

62 {
63 // Act
64 $activity = new ilLoggingActivity($this->node);
65
66 // Assert
67 // No exception - good
68 $this->assertTrue(
69 true,
70 'Construction failed with valid context passed to constructor.'
71 );
72 }
@noinspection PhpIncludeInspection

◆ testExecute()

ilLoggingActivityTest::testExecute ( )

Definition at line 214 of file ilLoggingActivityTest.php.

215 {
216 // Arrange
217 $activity = new ilLoggingActivity($this->node);
218 $activity->setLogFile(vfs\vfsStream::url('example/log.txt'));
219 $activity->setLogLevel('MESSAGE');
220 $activity->setLogMessage('TEST');
221
222 // Act
223 $activity->execute();
224
225 // Assert
226 $expected = ' :: MESSAGE :: TEST';
227 $fp = fopen(vfs\vfsStream::url('example/log.txt'), 'r');
228 $line = fgets($fp);
229 $actual = substr($line, 25, strlen($line) - 27);
230
231 $this->assertEquals(
232 $actual,
233 $expected,
234 'Logging Activity did not write expected output.'
235 );
236 }

◆ testGetContext()

ilLoggingActivityTest::testGetContext ( )

Definition at line 250 of file ilLoggingActivityTest.php.

251 {
252 // Arrange
253 $activity = new ilLoggingActivity($this->node);
254
255 // Act
256 $actual = $activity->getContext();
257
258 // Assert
259 if ($actual === $this->node) {
260 $this->assertEquals($actual, $this->node);
261 } else {
262 $this->assertTrue(false, 'Context not identical.');
263 }
264 }

◆ testPassInUnwriteablePath()

ilLoggingActivityTest::testPassInUnwriteablePath ( )

Definition at line 241 of file ilLoggingActivityTest.php.

242 {
243 $this->expectException(ilWorkflowFilesystemException::class);
244
245 // Arrange
246 $activity = new ilLoggingActivity($this->node);
247 $activity->setLogFile(vfs\vfsStream::url('example.txt'));
248 }

◆ testSetGetEmptyLogMessage()

ilLoggingActivityTest::testSetGetEmptyLogMessage ( )

Definition at line 166 of file ilLoggingActivityTest.php.

167 {
168 $this->expectException(ilWorkflowObjectStateException::class);
169
170 // Arrange
171 $activity = new ilLoggingActivity($this->node);
172
173 // Act
174 $activity->setLogMessage('');
175 $actual = $activity->getLogMessage();
176
177 // Assertion via phpdoc. (Exception)
178 }

◆ testSetGetIllegalExtensionLogFile()

ilLoggingActivityTest::testSetGetIllegalExtensionLogFile ( )

Definition at line 112 of file ilLoggingActivityTest.php.

113 {
114 $this->expectException(ilWorkflowObjectStateException::class);
115
116 // Arrange
117 $activity = new ilLoggingActivity($this->node);
118 $expected = './Services/WorkflowEngine/test/malicious.php';
119 // Is either one of: .log or .txt
120
121 // Act
122 $activity->setLogFile($expected);
123 $actual = $activity->getLogFile();
124
125 // Assertion via phpdoc. (Exception)
126 }

◆ testSetGetInvalidLogLevel()

ilLoggingActivityTest::testSetGetInvalidLogLevel ( )

Definition at line 201 of file ilLoggingActivityTest.php.

202 {
203 $this->expectException(ilWorkflowObjectStateException::class);
204
205 // Arrange
206 $activity = new ilLoggingActivity($this->node);
207 $expected = "guenther";
208
209 // Act
210 $activity->setLogLevel($expected);
211 $actual = $activity->getLogLevel();
212 }

◆ testSetGetLegalMessage()

ilLoggingActivityTest::testSetGetLegalMessage ( )

Definition at line 128 of file ilLoggingActivityTest.php.

129 {
130 // Arrange
131 $activity = new ilLoggingActivity($this->node);
132 $expected = 'Hallo Spencer!';
133
134 // Act
135 $activity->setLogMessage($expected);
136 $actual = $activity->getLogMessage();
137
138 // Assert
139 $this->assertEquals(
140 $actual,
141 $expected,
142 'Get/Set corrupted message.'
143 );
144 }

◆ testSetGetNonWriteableLogFile()

ilLoggingActivityTest::testSetGetNonWriteableLogFile ( )

Definition at line 94 of file ilLoggingActivityTest.php.

95 {
96 $this->expectException(ilWorkflowFilesystemException::class);
97
98 // Arrange
99 $activity = new ilLoggingActivity($this->node);
100 $expected = '/dev/ilias_unit_test_log_file_can_be_deleted_safely.txt';
101
102 // Act
103 $activity->setLogFile($expected);
104 $actual = $activity->getLogFile();
105
106 // Assertion via phpdoc. (Exception)
107 }

◆ testSetGetNullLogMessage()

ilLoggingActivityTest::testSetGetNullLogMessage ( )

Definition at line 149 of file ilLoggingActivityTest.php.

150 {
151 $this->expectException(ilWorkflowObjectStateException::class);
152
153 // Arrange
154 $activity = new ilLoggingActivity($this->node);
155
156 // Act
157 $activity->setLogMessage(null);
158 $actual = $activity->getLogMessage();
159
160 // Assertion via phpdoc. (Exception)
161 }

◆ testSetGetValidLogFile()

ilLoggingActivityTest::testSetGetValidLogFile ( )

Definition at line 74 of file ilLoggingActivityTest.php.

75 {
76 // Arrange
77 $activity = new ilLoggingActivity($this->node);
78 $expected = './Services/WorkflowEngine/test/testlog.txt';
79
80 // Act
81 $activity->setLogFile($expected);
82 $actual = $activity->getLogFile();
83
84 $this->assertEquals(
85 $actual,
86 $expected,
87 'Valid log file was given, returned value differed.'
88 );
89 }

◆ testSetGetValidLogLevel()

ilLoggingActivityTest::testSetGetValidLogLevel ( )

Definition at line 180 of file ilLoggingActivityTest.php.

181 {
182 // Arrange
183 $activity = new ilLoggingActivity($this->node);
184 $expected = "MESSAGE";
185
186 // Act
187 $activity->setLogLevel($expected);
188 $actual = $activity->getLogLevel();
189
190 // Assert
191 $this->assertEquals(
192 $actual,
193 $expected,
194 'Get/Set corrupted log level.'
195 );
196 }

Field Documentation

◆ $test_dir

ilLoggingActivityTest::$test_dir

vfsStream Test Directory, see setup.

Definition at line 20 of file ilLoggingActivityTest.php.


The documentation for this class was generated from the following file: