ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 ()
 @expectedException ilWorkflowFilesystemException More...
 
 testSetGetIllegalExtensionLogFile ()
 @expectedException ilWorkflowObjectStateException More...
 
 testSetGetLegalMessage ()
 
 testSetGetNullLogMessage ()
 @expectedException ilWorkflowObjectStateException More...
 
 testSetGetEmptyLogMessage ()
 @expectedException ilWorkflowObjectStateException More...
 
 testSetGetValidLogLevel ()
 
 testSetGetInvalidLogLevel ()
 @expectedException ilWorkflowObjectStateException More...
 
 testExecute ()
 
 testPassInUnwriteablePath ()
 @expectedException ilWorkflowFilesystemException More...
 
 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 16 of file ilLoggingActivityTest.php.

Member Function Documentation

◆ setUp()

ilLoggingActivityTest::setUp ( )

Definition at line 21 of file ilLoggingActivityTest.php.

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

References defined.

◆ tearDown()

ilLoggingActivityTest::tearDown ( )

Definition at line 55 of file ilLoggingActivityTest.php.

56 {
57 global $ilSetting;
58 if ($ilSetting != NULL)
59 {
60 //$ilSetting->delete('IL_PHPUNIT_TEST_TIME');
61 //$ilSetting->delete('IL_PHPUNIT_TEST_MICROTIME');
62 }
63 }
global $ilSetting
Definition: privfeed.php:17

References $ilSetting.

◆ testConstructorValidContext()

ilLoggingActivityTest::testConstructorValidContext ( )

Definition at line 65 of file ilLoggingActivityTest.php.

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

◆ testExecute()

ilLoggingActivityTest::testExecute ( )

Definition at line 208 of file ilLoggingActivityTest.php.

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

◆ testGetContext()

ilLoggingActivityTest::testGetContext ( )

Definition at line 242 of file ilLoggingActivityTest.php.

243 {
244 // Arrange
245 $activity = new ilLoggingActivity($this->node);
246
247 // Act
248 $actual = $activity->getContext();
249
250 // Assert
251 if ($actual === $this->node)
252 {
253 $this->assertEquals($actual, $this->node);
254 } else {
255 $this->assertTrue(false, 'Context not identical.');
256 }
257 }

◆ testPassInUnwriteablePath()

ilLoggingActivityTest::testPassInUnwriteablePath ( )

@expectedException ilWorkflowFilesystemException

Definition at line 235 of file ilLoggingActivityTest.php.

236 {
237 // Arrange
238 $activity = new ilLoggingActivity($this->node);
239 $activity->setLogFile(vfs\vfsStream::url('example.txt'));
240 }

◆ testSetGetEmptyLogMessage()

ilLoggingActivityTest::testSetGetEmptyLogMessage ( )

@expectedException ilWorkflowObjectStateException

Definition at line 164 of file ilLoggingActivityTest.php.

165 {
166 // Arrange
167 $activity = new ilLoggingActivity($this->node);
168
169 // Act
170 $activity->setLogMessage('');
171 $actual = $activity->getLogMessage();
172
173 // Assertion via phpdoc. (Exception)
174 }

◆ testSetGetIllegalExtensionLogFile()

ilLoggingActivityTest::testSetGetIllegalExtensionLogFile ( )

@expectedException ilWorkflowObjectStateException

Definition at line 114 of file ilLoggingActivityTest.php.

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 ( )

@expectedException ilWorkflowObjectStateException

Definition at line 197 of file ilLoggingActivityTest.php.

198 {
199 // Arrange
200 $activity = new ilLoggingActivity($this->node);
201 $expected = "guenther";
202
203 // Act
204 $activity->setLogLevel($expected);
205 $actual = $activity->getLogLevel();
206 }

◆ 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 ( )

@expectedException ilWorkflowFilesystemException

Definition at line 98 of file ilLoggingActivityTest.php.

99 {
100 // Arrange
101 $activity = new ilLoggingActivity($this->node);
102 $expected = '/dev/ilias_unit_test_log_file_can_be_deleted_safely.txt';
103
104 // Act
105 $activity->setLogFile($expected);
106 $actual = $activity->getLogFile();
107
108 // Assertion via phpdoc. (Exception)
109 }

◆ testSetGetNullLogMessage()

ilLoggingActivityTest::testSetGetNullLogMessage ( )

@expectedException ilWorkflowObjectStateException

Definition at line 149 of file ilLoggingActivityTest.php.

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

◆ testSetGetValidLogFile()

ilLoggingActivityTest::testSetGetValidLogFile ( )

Definition at line 78 of file ilLoggingActivityTest.php.

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

◆ testSetGetValidLogLevel()

ilLoggingActivityTest::testSetGetValidLogLevel ( )

Definition at line 176 of file ilLoggingActivityTest.php.

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

Field Documentation

◆ $test_dir

ilLoggingActivityTest::$test_dir

vfsStream Test Directory, see setup.

Definition at line 19 of file ilLoggingActivityTest.php.


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