ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilTermsOfServiceUserHasGlobalRoleCriterionTest Class Reference

Class ilTermsOfServiceUserHasGlobalRoleCriterionTest. More...

+ Inheritance diagram for ilTermsOfServiceUserHasGlobalRoleCriterionTest:
+ Collaboration diagram for ilTermsOfServiceUserHasGlobalRoleCriterionTest:

Public Member Functions

 setUp ()
 @inheritDoc More...
 
 testInstanceCanBeCreated ()
 
 testFormUserInterfaceElementsAreProperlyBuilt (ilTermsOfServiceUserHasGlobalRoleCriterion $criterion)
 
 testValuesFromFormUserInterfaceElementsCanBeRetrieved (ilTermsOfServiceUserHasGlobalRoleCriterion $criterion)
 @depends testFormUserInterfaceElementsAreProperlyBuilt More...
 
 testTypeIdentPresentationIsANonEmptyString (ilTermsOfServiceUserHasGlobalRoleCriterion $criterion)
 @depends testFormUserInterfaceElementsAreProperlyBuilt More...
 
 objectCacheProvider ()
 
 failingConfigProvider ()
 
 testEvaluationFailsIfConfiguredRoleDoesNotMatchTheExpectedFormat (ilTermsOfServiceUserHasGlobalRoleCriterion $criterion, ilTermsOfServiceCriterionConfig $config)
 
 testEvaluationFailsIfConfiguredRoleIsNotAGlobalRole ()
 
 testEvaluationFailsIfUserIsNotAssignedToConfiguredGlobalRole ()
 
 testEvaluationSucceedsIfUserIsAssignedToDefinedGlobalRole ()
 

Protected Member Functions

 getInstance ()
 
 buildForm (ilTermsOfServiceCriterionTypeGUI $gui, string $httpCriterionSelectionBodyParameter)
 
- Protected Member Functions inherited from ilTermsOfServiceCriterionBaseTest
 getRbacReviewMock ()
 
 getObjectDataCacheMock ()
 
 getRadioGroupMock ()
 
 getFormMock ()
 
 getUserMock ()
 
- Protected Member Functions inherited from ilTermsOfServiceBaseTest
 setUp ()
 
 getLanguageMock ()
 
 getUiFactoryMock ()
 
 setGlobalVariable (string $name, $value)
 
 getCriterionConfig ($value=null)
 

Protected Attributes

 $rbacReview
 
 $lng
 
 $expectedInitialValue = 2
 
 $expectedAfterFormSubmitValue = 4
 
 $userRoleTitle = 'User'
 
 $adminRoleTitle = 'Administrator'
 
- Protected Attributes inherited from ilTermsOfServiceBaseTest
 $dic
 

Detailed Description

Member Function Documentation

◆ buildForm()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::buildForm ( ilTermsOfServiceCriterionTypeGUI  $gui,
string  $httpCriterionSelectionBodyParameter 
)
protected
Parameters
ilTermsOfServiceCriterionTypeGUI$gui
string$httpCriterionSelectionBodyParameter
Returns
MockObject|ilPropertyFormGUI
Exceptions
ReflectionException

Definition at line 83 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

87 $form = $this->getFormMock();
88
89 $radioGroup = $this->getRadioGroupMock();
90
91 $radioGroup
92 ->expects($this->any())
93 ->method('getPostVar')
94 ->willReturn($httpCriterionSelectionBodyParameter);
95
96 $form->addItem($radioGroup);
97
98 $gui->appendOption(
99 $radioGroup,
100 new ilTermsOfServiceCriterionConfig(['role_id' => $this->expectedInitialValue])
101 );
102
103 return $form;
104 }
This class represents a property form user interface.
Class ilTermsOfServiceCriterionConfig.
appendOption(ilRadioGroupInputGUI $option, ilTermsOfServiceCriterionConfig $config)

◆ failingConfigProvider()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::failingConfigProvider ( )
Returns
array
Exceptions
ReflectionException

Definition at line 223 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

223 : array
224 {
225 $criterion = $this->getInstance();
226
227 return [
228 'Array' => [$criterion, $this->getCriterionConfig(['role_id' => []])],
229 'Object' => [$criterion, $this->getCriterionConfig(['role_id' => new stdClass()])],
230 'Double' => [$criterion, $this->getCriterionConfig(['role_id' => 1.424])],
231 'String' => [$criterion, $this->getCriterionConfig(['role_id' => 'phpunit'])],
232 'Wrong Key Provided for Extracting Role' => [
233 $criterion,
234 $this->getCriterionConfig(['another_config_key' => true])
235 ],
236 'Empty Configuration' => [$criterion, $this->getCriterionConfig()],
237 ];
238 }

◆ getInstance()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::getInstance ( )
protected
Returns
ilTermsOfServiceUserHasGlobalRoleCriterion
Exceptions
ReflectionException

Definition at line 51 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

52 {
53 $this->rbacReview = $this->getRbacReviewMock();
54
56 $this->rbacReview,
58 );
59
60 return $criterion;
61 }

References ilTermsOfServiceCriterionBaseTest\getObjectDataCacheMock(), and ilTermsOfServiceCriterionBaseTest\getRbacReviewMock().

Referenced by testInstanceCanBeCreated().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ objectCacheProvider()

◆ setUp()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::setUp ( )

@inheritDoc

Reimplemented from ilTermsOfServiceBaseTest.

Definition at line 35 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

35 : void
36 {
37 parent::setUp();
38
39 $this->lng = $this->getLanguageMock();
40
41 $this->lng
42 ->expects($this->any())
43 ->method('txt')
44 ->willReturn('dummy');
45 }

References ilTermsOfServiceBaseTest\getLanguageMock().

+ Here is the call graph for this function:

◆ testEvaluationFailsIfConfiguredRoleDoesNotMatchTheExpectedFormat()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testEvaluationFailsIfConfiguredRoleDoesNotMatchTheExpectedFormat ( ilTermsOfServiceUserHasGlobalRoleCriterion  $criterion,
ilTermsOfServiceCriterionConfig  $config 
)
Parameters
ilTermsOfServiceUserHasGlobalRoleCriterion$criterion
ilTermsOfServiceCriterionConfig$config@dataProvider failingConfigProvider
Exceptions
ReflectionException

Definition at line 246 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

249 : void {
250 $user = $this->getUserMock();
251
252 $this->assertFalse($criterion->evaluate($user, $config));
253 }
evaluate(ilObjUser $user, ilTermsOfServiceCriterionConfig $config)
bool
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68

◆ testEvaluationFailsIfConfiguredRoleIsNotAGlobalRole()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testEvaluationFailsIfConfiguredRoleIsNotAGlobalRole ( )
Exceptions
ReflectionException

Definition at line 258 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

258 : void
259 {
260 $user = $this->getUserMock();
261 $criterion = $this->getInstance();
262
263 $this->rbacReview
264 ->expects($this->once())
265 ->method('isGlobalRole')
266 ->willReturn(false);
267
268 $this->assertFalse(
269 $criterion->evaluate($user, $this->getCriterionConfig(['role_id' => $this->expectedAfterFormSubmitValue]))
270 );
271 }

References ilTermsOfServiceUserHasGlobalRoleCriterion\evaluate().

+ Here is the call graph for this function:

◆ testEvaluationFailsIfUserIsNotAssignedToConfiguredGlobalRole()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testEvaluationFailsIfUserIsNotAssignedToConfiguredGlobalRole ( )
Exceptions
ReflectionException

Definition at line 276 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

276 : void
277 {
278 $user = $this->getUserMock();
279 $criterion = $this->getInstance();
280
281 $this->rbacReview
282 ->expects($this->once())
283 ->method('isGlobalRole')
284 ->willReturn(true);
285
286 $this->rbacReview
287 ->expects($this->once())
288 ->method('isAssigned')
289 ->willReturn(false);
290
291 $this->assertFalse(
292 $criterion->evaluate($user, $this->getCriterionConfig(['role_id' => $this->expectedAfterFormSubmitValue]))
293 );
294 }

References ilTermsOfServiceUserHasGlobalRoleCriterion\evaluate().

+ Here is the call graph for this function:

◆ testEvaluationSucceedsIfUserIsAssignedToDefinedGlobalRole()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testEvaluationSucceedsIfUserIsAssignedToDefinedGlobalRole ( )
Exceptions
ReflectionException

Definition at line 299 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

299 : void
300 {
301 $user = $this->getUserMock();
302 $criterion = $this->getInstance();
303
304 $this->rbacReview
305 ->expects($this->once())
306 ->method('isGlobalRole')
307 ->willReturn(true);
308
309 $this->rbacReview
310 ->expects($this->once())
311 ->method('isAssigned')
312 ->willReturn(true);
313
314 $this->assertTrue(
315 $criterion->evaluate($user, $this->getCriterionConfig(['role_id' => $this->expectedAfterFormSubmitValue]))
316 );
317 }

References ilTermsOfServiceUserHasGlobalRoleCriterion\evaluate().

+ Here is the call graph for this function:

◆ testFormUserInterfaceElementsAreProperlyBuilt()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testFormUserInterfaceElementsAreProperlyBuilt ( ilTermsOfServiceUserHasGlobalRoleCriterion  $criterion)
Parameters
ilTermsOfServiceUserHasGlobalRoleCriterion$criterion@depends testInstanceCanBeCreated
Returns
ilTermsOfServiceUserHasGlobalRoleCriterion
Exceptions
ReflectionException

Definition at line 112 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

115 $httpCriterionSelectionBodyParameter = 'criterion';
116 $httpCriterionConfigBodyParameter = $criterion->getTypeIdent() . '_role_id';
117
118 $gui = $criterion->ui($this->lng);
119
120 $this->assertInstanceOf(ilTermsOfServiceUserHasGlobalRoleCriterionGUI::class, $gui);
121
122 $form = $this->buildForm($gui, $httpCriterionSelectionBodyParameter);
123
124 $roleSelection = $form->getItemByPostVar($httpCriterionConfigBodyParameter);
125 $this->assertInstanceOf(ilSelectInputGUI::class, $roleSelection);
126 $this->assertEquals($roleSelection->getValue(), $this->expectedInitialValue);
127
128 return $criterion;
129 }
buildForm(ilTermsOfServiceCriterionTypeGUI $gui, string $httpCriterionSelectionBodyParameter)
getTypeIdent()
Returns a unique id of the criterion type.string

◆ testInstanceCanBeCreated()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testInstanceCanBeCreated ( )
Returns
ilTermsOfServiceUserHasGlobalRoleCriterion
Exceptions
ReflectionException

Definition at line 67 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

68 {
69 $criterion = $this->getInstance();
70
71 $this->assertEquals('usr_global_role', $criterion->getTypeIdent());
72 $this->assertEquals(false, $criterion->hasUniqueNature());
73
74 return $criterion;
75 }

References getInstance().

+ Here is the call graph for this function:

◆ testTypeIdentPresentationIsANonEmptyString()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testTypeIdentPresentationIsANonEmptyString ( ilTermsOfServiceUserHasGlobalRoleCriterion  $criterion)

@depends testFormUserInterfaceElementsAreProperlyBuilt

Parameters
ilTermsOfServiceUserHasGlobalRoleCriterion$criterion

Definition at line 165 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

167 : void {
168 $gui = $criterion->ui($this->lng);
169
170 $actual = $gui->getIdentPresentation();
171
172 $this->assertIsString($actual);
173 $this->assertNotEmpty($actual);
174 }

◆ testValuesFromFormUserInterfaceElementsCanBeRetrieved()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testValuesFromFormUserInterfaceElementsCanBeRetrieved ( ilTermsOfServiceUserHasGlobalRoleCriterion  $criterion)

@depends testFormUserInterfaceElementsAreProperlyBuilt

Parameters
ilTermsOfServiceUserHasGlobalRoleCriterion$criterion
Exceptions
ReflectionException

Definition at line 136 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

138 : void {
139 $httpCriterionSelectionBodyParameter = 'criterion';
140 $httpCriterionConfigBodyParameter = $criterion->getTypeIdent() . '_role_id';
141
142 $gui = $criterion->ui($this->lng);
143
144 $form = $this->buildForm($gui, $httpCriterionSelectionBodyParameter);
145
146 $form
147 ->expects($this->once())
148 ->method('getInput')
149 ->with($httpCriterionConfigBodyParameter)
150 ->will($this->returnCallback(function () {
152 }));
153
154 $value = $gui->getConfigByForm($form);
155
156 $this->assertInstanceOf(ilTermsOfServiceCriterionConfig::class, $value);
157 $this->assertEquals($this->expectedAfterFormSubmitValue, $value['role_id']);
158 $this->assertEquals($this->getCriterionConfig(['role_id' => $this->expectedAfterFormSubmitValue]), $value);
159 }

Field Documentation

◆ $adminRoleTitle

ilTermsOfServiceUserHasGlobalRoleCriterionTest::$adminRoleTitle = 'Administrator'
protected

◆ $expectedAfterFormSubmitValue

ilTermsOfServiceUserHasGlobalRoleCriterionTest::$expectedAfterFormSubmitValue = 4
protected

◆ $expectedInitialValue

ilTermsOfServiceUserHasGlobalRoleCriterionTest::$expectedInitialValue = 2
protected

◆ $lng

ilTermsOfServiceUserHasGlobalRoleCriterionTest::$lng
protected

◆ $rbacReview

ilTermsOfServiceUserHasGlobalRoleCriterionTest::$rbacReview
protected

◆ $userRoleTitle

ilTermsOfServiceUserHasGlobalRoleCriterionTest::$userRoleTitle = 'User'
protected

The documentation for this class was generated from the following file: