ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
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  }
54 
55  public function tearDown()
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  }
64 
65  public function testConstructorValidContext()
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  }
77 
78  public function testSetGetValidLogFile()
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  }
94 
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  }
110 
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  }
127 
128  public function testSetGetLegalMessage()
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  }
145 
149  public function testSetGetNullLogMessage()
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  }
160 
164  public function testSetGetEmptyLogMessage()
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  }
175 
176  public function testSetGetValidLogLevel()
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  }
193 
197  public function testSetGetInvalidLogLevel()
198  {
199  // Arrange
200  $activity = new ilLoggingActivity($this->node);
201  $expected = "guenther";
202 
203  // Act
204  $activity->setLogLevel($expected);
205  $actual = $activity->getLogLevel();
206  }
207 
208  public function testExecute()
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  }
231 
235  public function testPassInUnwriteablePath()
236  {
237  // Arrange
238  $activity = new ilLoggingActivity($this->node);
239  $activity->setLogFile(vfs\vfsStream::url('example.txt'));
240  }
241 
242  public function testGetContext()
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  }
258 }
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