ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
4 require_once 'Services/WorkflowEngine/test/ilWorkflowEngineBaseTest.php';
5 
17 {
18  public function setUp() : void
19  {
20  parent::setUp();
21 
22  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
23  //ilUnitUtil::performInitialisation();
24 
25  // Empty workflow.
26  require_once './Services/WorkflowEngine/classes/workflows/class.ilEmptyWorkflow.php';
27  $this->workflow = new ilEmptyWorkflow();
28 
29  // Basic node
30  require_once './Services/WorkflowEngine/classes/nodes/class.ilBasicNode.php';
31  $this->node = new ilBasicNode($this->workflow);
32 
33  // Wiring up so the node is attached to the workflow.
34  $this->workflow->addNode($this->node);
35 
36  require_once './Services/WorkflowEngine/classes/activities/class.ilSettingActivity.php';
37  }
38 
39  public function tearDown() : void
40  {
41  global $DIC;
42 
43  if (isset($DIC['ilSetting'])) {
44  $DIC['ilSetting']->delete('IL_PHPUNIT_TEST_TIME');
45  $DIC['ilSetting']->delete('IL_PHPUNIT_TEST_MICROTIME');
46  }
47  }
48 
49  public function testConstructorValidContext()
50  {
51  // Act
52  $activity = new ilSettingActivity($this->node);
53 
54  // Assert
55  // No exception - good
56  $this->assertTrue(
57  true,
58  'Construction failed with valid context passed to constructor.'
59  );
60  }
61 
62  public function testSetGetSettingName()
63  {
64  // Arrange
65  $activity = new ilSettingActivity($this->node);
66 
67  // Act
68  $expected = 'Günther';
69  $activity->setSettingName($expected);
70  $actual = $activity->getSettingName();
71 
72  // Assert
73  $this->assertEquals($actual, $expected);
74  }
75 
76  public function testSetGetSettingValue()
77  {
78  // Arrange
79  $activity = new ilSettingActivity($this->node);
80 
81  // Act
82  $expected = 'Günther';
83  $activity->setSettingValue($expected);
84  $actual = $activity->getSettingValue();
85 
86  // Assert
87  $this->assertEquals($actual, $expected);
88  }
89 
90  public function testSetSetting()
91  {
92  // Arrange
93  $activity = new ilSettingActivity($this->node);
94 
95  // Act
96  $expected_name = 'Ralle';
97  $expected_value = 'OK';
98  $activity->setSetting($expected_name, $expected_value);
99  $actual_name = $activity->getSettingName();
100  $actual_value = $activity->getSettingValue();
101 
102  // Assert
103  $this->assertEquals(
104  $actual_name . $actual_value,
105  $expected_name . $expected_value
106  );
107  }
108 
109  public function testExecute()
110  {
111  // Arrange
112  $activity = new ilSettingActivity($this->node);
113  $expected_name = 'Ralle';
114  $expected_val = 'OK';
115  $activity->setSetting($expected_name, $expected_val);
116 
117  $ilSetting_mock = $this->createMock('ilSetting', array('set'), array(), '', false);
118 
119  $ilSetting_mock->expects($this->exactly(1))
120  ->method('set')
121  ->with($expected_name, $expected_val);
122 
123  $stashed_real_object = '';
124  if (isset($GLOBALS['DIC']['ilSetting'])) {
125  $stashed_real_object = $GLOBALS['DIC']['ilSetting'];
126  }
127 
128  unset($GLOBALS['DIC']['ilSetting']);
129  $GLOBALS['DIC']['ilSetting'] = $ilSetting_mock;
130 
131  // Act
132  $activity->execute();
133 
134  $GLOBALS['DIC']['ilSetting'] = $stashed_real_object;
135  }
136 
137  public function testGetContext()
138  {
139  // Arrange
140  $activity = new ilSettingActivity($this->node);
141 
142  // Act
143  $actual = $activity->getContext();
144 
145  // Assert
146  if ($actual === $this->node) {
147  $this->assertEquals($actual, $this->node);
148  } else {
149  $this->assertTrue(false, 'Context not identical.');
150  }
151  }
152 }
Class ilWorkflowEngineBaseTest.
ilSettingActivityTest is part of the petri net based workflow engine.
PhpIncludeInspection
PhpIncludeInspection
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$DIC
Definition: xapitoken.php:46
PhpIncludeInspection