ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 ()
 ilWorkflowFilesystemException More...
 
 testSetGetIllegalExtensionLogFile ()
 ilWorkflowObjectStateException More...
 
 testSetGetLegalMessage ()
 
 testSetGetNullLogMessage ()
 ilWorkflowObjectStateException More...
 
 testSetGetEmptyLogMessage ()
 ilWorkflowObjectStateException More...
 
 testSetGetValidLogLevel ()
 
 testSetGetInvalidLogLevel ()
 ilWorkflowObjectStateException More...
 
 testExecute ()
 
 testPassInUnwriteablePath ()
 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.

References defined.

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

◆ tearDown()

ilLoggingActivityTest::tearDown ( )

Definition at line 51 of file ilLoggingActivityTest.php.

References $ilSetting.

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

◆ testConstructorValidContext()

ilLoggingActivityTest::testConstructorValidContext ( )

Definition at line 60 of file ilLoggingActivityTest.php.

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

◆ testExecute()

ilLoggingActivityTest::testExecute ( )

Definition at line 203 of file ilLoggingActivityTest.php.

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

◆ testGetContext()

ilLoggingActivityTest::testGetContext ( )

Definition at line 237 of file ilLoggingActivityTest.php.

238  {
239  // Arrange
240  $activity = new ilLoggingActivity($this->node);
241 
242  // Act
243  $actual = $activity->getContext();
244 
245  // Assert
246  if ($actual === $this->node) {
247  $this->assertEquals($actual, $this->node);
248  } else {
249  $this->assertTrue(false, 'Context not identical.');
250  }
251  }
PhpIncludeInspection

◆ testPassInUnwriteablePath()

ilLoggingActivityTest::testPassInUnwriteablePath ( )

ilWorkflowFilesystemException

Definition at line 230 of file ilLoggingActivityTest.php.

231  {
232  // Arrange
233  $activity = new ilLoggingActivity($this->node);
234  $activity->setLogFile(vfs\vfsStream::url('example.txt'));
235  }
PhpIncludeInspection

◆ testSetGetEmptyLogMessage()

ilLoggingActivityTest::testSetGetEmptyLogMessage ( )

ilWorkflowObjectStateException

Definition at line 159 of file ilLoggingActivityTest.php.

160  {
161  // Arrange
162  $activity = new ilLoggingActivity($this->node);
163 
164  // Act
165  $activity->setLogMessage('');
166  $actual = $activity->getLogMessage();
167 
168  // Assertion via phpdoc. (Exception)
169  }
PhpIncludeInspection

◆ testSetGetIllegalExtensionLogFile()

ilLoggingActivityTest::testSetGetIllegalExtensionLogFile ( )

ilWorkflowObjectStateException

Definition at line 109 of file ilLoggingActivityTest.php.

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

◆ testSetGetInvalidLogLevel()

ilLoggingActivityTest::testSetGetInvalidLogLevel ( )

ilWorkflowObjectStateException

Definition at line 192 of file ilLoggingActivityTest.php.

193  {
194  // Arrange
195  $activity = new ilLoggingActivity($this->node);
196  $expected = "guenther";
197 
198  // Act
199  $activity->setLogLevel($expected);
200  $actual = $activity->getLogLevel();
201  }
PhpIncludeInspection

◆ testSetGetLegalMessage()

ilLoggingActivityTest::testSetGetLegalMessage ( )

Definition at line 123 of file ilLoggingActivityTest.php.

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

◆ testSetGetNonWriteableLogFile()

ilLoggingActivityTest::testSetGetNonWriteableLogFile ( )

ilWorkflowFilesystemException

Definition at line 93 of file ilLoggingActivityTest.php.

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

◆ testSetGetNullLogMessage()

ilLoggingActivityTest::testSetGetNullLogMessage ( )

ilWorkflowObjectStateException

Definition at line 144 of file ilLoggingActivityTest.php.

145  {
146  // Arrange
147  $activity = new ilLoggingActivity($this->node);
148 
149  // Act
150  $activity->setLogMessage(null);
151  $actual = $activity->getLogMessage();
152 
153  // Assertion via phpdoc. (Exception)
154  }
PhpIncludeInspection

◆ testSetGetValidLogFile()

ilLoggingActivityTest::testSetGetValidLogFile ( )

Definition at line 73 of file ilLoggingActivityTest.php.

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

◆ testSetGetValidLogLevel()

ilLoggingActivityTest::testSetGetValidLogLevel ( )

Definition at line 171 of file ilLoggingActivityTest.php.

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

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: