ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilLoggingActivityTest.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
5 
17 {
19  public $test_dir;
20 
21  public function setUp()
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  }
50 
51  public function tearDown()
52  {
53  global $ilSetting;
54  if ($ilSetting != null) {
55  //$ilSetting->delete('IL_PHPUNIT_TEST_TIME');
56  //$ilSetting->delete('IL_PHPUNIT_TEST_MICROTIME');
57  }
58  }
59 
60  public function testConstructorValidContext()
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  }
72 
73  public function testSetGetValidLogFile()
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  }
89 
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  }
105 
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  }
122 
123  public function testSetGetLegalMessage()
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  }
140 
144  public function testSetGetNullLogMessage()
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  }
155 
159  public function testSetGetEmptyLogMessage()
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  }
170 
171  public function testSetGetValidLogLevel()
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  }
188 
192  public function testSetGetInvalidLogLevel()
193  {
194  // Arrange
195  $activity = new ilLoggingActivity($this->node);
196  $expected = "guenther";
197 
198  // Act
199  $activity->setLogLevel($expected);
200  $actual = $activity->getLogLevel();
201  }
202 
203  public function testExecute()
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  }
226 
230  public function testPassInUnwriteablePath()
231  {
232  // Arrange
233  $activity = new ilLoggingActivity($this->node);
234  $activity->setLogFile(vfs\vfsStream::url('example.txt'));
235  }
236 
237  public function testGetContext()
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  }
252 }
testSetGetNonWriteableLogFile()
ilWorkflowFilesystemException
$test_dir
vfsStream Test Directory, see setup.
testSetGetNullLogMessage()
ilWorkflowObjectStateException
PhpIncludeInspection
ilLoggingActivityTest is part of the petri net based workflow engine.
testPassInUnwriteablePath()
ilWorkflowFilesystemException
testSetGetIllegalExtensionLogFile()
ilWorkflowObjectStateException
PhpIncludeInspection
testSetGetEmptyLogMessage()
ilWorkflowObjectStateException
global $ilSetting
Definition: privfeed.php:17
PhpIncludeInspection
testSetGetInvalidLogLevel()
ilWorkflowObjectStateException
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27