ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilSettingActivityTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
3
15{
16 public function setUp()
17 {
18 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
19 //ilUnitUtil::performInitialisation();
20
21 // Empty workflow.
22 require_once './Services/WorkflowEngine/classes/workflows/class.ilEmptyWorkflow.php';
23 $this->workflow = new ilEmptyWorkflow();
24
25 // Basic node
26 require_once './Services/WorkflowEngine/classes/nodes/class.ilBasicNode.php';
27 $this->node = new ilBasicNode($this->workflow);
28
29 // Wiring up so the node is attached to the workflow.
30 $this->workflow->addNode($this->node);
31
32 require_once './Services/WorkflowEngine/classes/activities/class.ilSettingActivity.php';
33 }
34
35 public function tearDown()
36 {
37 global $ilSetting;
38 if($ilSetting != null)
39 {
40 $ilSetting->delete( 'IL_PHPUNIT_TEST_TIME' );
41 $ilSetting->delete( 'IL_PHPUNIT_TEST_MICROTIME' );
42 }
43 }
44
46 {
47 // Act
48 $activity = new ilSettingActivity($this->node);
49
50 // Assert
51 // No exception - good
52 $this->assertTrue(
53 true,
54 'Construction failed with valid context passed to constructor.'
55 );
56 }
57
58 public function testSetGetSettingName()
59 {
60 // Arrange
61 $activity = new ilSettingActivity($this->node);
62
63 // Act
64 $expected = 'Günther';
65 $activity->setSettingName($expected);
66 $actual = $activity->getSettingName();
67
68 // Assert
69 $this->assertEquals($actual, $expected);
70 }
71
72 public function testSetGetSettingValue()
73 {
74 // Arrange
75 $activity = new ilSettingActivity($this->node);
76
77 // Act
78 $expected = 'Günther';
79 $activity->setSettingValue($expected);
80 $actual = $activity->getSettingValue();
81
82 // Assert
83 $this->assertEquals($actual, $expected);
84 }
85
86 public function testSetSetting()
87 {
88 // Arrange
89 $activity = new ilSettingActivity($this->node);
90
91 // Act
92 $expected_name = 'Ralle';
93 $expected_value = 'OK';
94 $activity->setSetting($expected_name, $expected_value);
95 $actual_name = $activity->getSettingName();
96 $actual_value = $activity->getSettingValue();
97
98 // Assert
99 $this->assertEquals(
100 $actual_name.$actual_value,
101 $expected_name.$expected_value
102 );
103 }
104
105 public function testExecute()
106 {
107 // Arrange
108 $activity = new ilSettingActivity($this->node);
109 $expected_name = 'Ralle';
110 $expected_val = 'OK';
111 $activity->setSetting($expected_name, $expected_val);
112
113 require_once './Services/Administration/classes/class.ilSetting.php';
114 $ilSetting_mock = $this->getMock('ilSetting',array('set'),array(),'', FALSE);
115
116 $ilSetting_mock->expects($this->exactly(1))
117 ->method('set')
118 ->with($expected_name, $expected_val);
119 $stashed_real_object = @$GLOBALS['ilSetting'];
120 $GLOBALS['ilSetting'] = $ilSetting_mock;
121
122 // Act
123 $activity->execute();
124
125 $GLOBALS['ilSetting'] = $stashed_real_object;
126
127 }
128
129 public function testGetContext()
130 {
131 // Arrange
132 $activity = new ilSettingActivity($this->node);
133
134 // Act
135 $actual = $activity->getContext();
136
137 // Assert
138 if ($actual === $this->node)
139 {
140 $this->assertEquals($actual, $this->node);
141 } else {
142 $this->assertTrue(false, 'Context not identical.');
143 }
144 }
145}
An exception for terminatinating execution or to throw for unit testing.
@noinspection PhpIncludeInspection
@noinspection PhpIncludeInspection
ilSettingActivityTest is part of the petri net based workflow engine.
@noinspection PhpIncludeInspection
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilSetting
Definition: privfeed.php:17