ILIAS  release_8 Revision v8.24
ilTermsOfServiceUserHasGlobalRoleCriterionTest Class Reference

Class ilTermsOfServiceUserHasGlobalRoleCriterionTest. More...

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

Public Member Functions

 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

 setUp ()
 
 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

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

Detailed Description

Member Function Documentation

◆ buildForm()

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

Definition at line 84 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

88 $form = $this->getFormMock();
89
90 $radioGroup = $this->getRadioGroupMock();
91
92 $radioGroup
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 $group, ilTermsOfServiceCriterionConfig $config)

◆ failingConfigProvider()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::failingConfigProvider ( )

Definition at line 212 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

212 : array
213 {
214 $criterion = $this->getInstance();
215
216 return [
217 'Array' => [$criterion, $this->getCriterionConfig(['role_id' => []])],
218 'Object' => [$criterion, $this->getCriterionConfig(['role_id' => new stdClass()])],
219 'Double' => [$criterion, $this->getCriterionConfig(['role_id' => 1.424])],
220 'String' => [$criterion, $this->getCriterionConfig(['role_id' => 'phpunit'])],
221 'Wrong Key Provided for Extracting Role' => [
222 $criterion,
223 $this->getCriterionConfig(['another_config_key' => true])
224 ],
225 'Empty Configuration' => [$criterion, $this->getCriterionConfig()],
226 ];
227 }

◆ getInstance()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::getInstance ( )
protected
Returns
ilTermsOfServiceUserHasGlobalRoleCriterion

Definition at line 54 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

55 {
56 $this->rbacReview = $this->getRbacReviewMock();
57
59 $this->rbacReview,
61 );
62
63 return $criterion;
64 }

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 ( )
protected

Reimplemented from ilTermsOfServiceBaseTest.

Definition at line 40 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

40 : void
41 {
42 parent::setUp();
43
44 $this->lng = $this->getLanguageMock();
45
46 $this->lng
47 ->method('txt')
48 ->willReturn('dummy');
49 }

References ilTermsOfServiceBaseTest\getLanguageMock(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ testEvaluationFailsIfConfiguredRoleDoesNotMatchTheExpectedFormat()

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

Definition at line 234 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

237 : void {
238 $user = $this->getUserMock();
239
240 $this->assertFalse($criterion->evaluate($user, $config));
241 }
evaluate(ilObjUser $user, ilTermsOfServiceCriterionConfig $config)
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85

◆ testEvaluationFailsIfConfiguredRoleIsNotAGlobalRole()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testEvaluationFailsIfConfiguredRoleIsNotAGlobalRole ( )

Definition at line 243 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

243 : void
244 {
245 $user = $this->getUserMock();
246 $criterion = $this->getInstance();
247
248 $this->rbacReview
249 ->expects($this->once())
250 ->method('isGlobalRole')
251 ->willReturn(false);
252
253 $this->assertFalse(
254 $criterion->evaluate($user, $this->getCriterionConfig(['role_id' => $this->expectedAfterFormSubmitValue]))
255 );
256 }

References ilTermsOfServiceUserHasGlobalRoleCriterion\evaluate().

+ Here is the call graph for this function:

◆ testEvaluationFailsIfUserIsNotAssignedToConfiguredGlobalRole()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testEvaluationFailsIfUserIsNotAssignedToConfiguredGlobalRole ( )

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(true);
267
268 $this->rbacReview
269 ->expects($this->once())
270 ->method('isAssigned')
271 ->willReturn(false);
272
273 $this->assertFalse(
274 $criterion->evaluate($user, $this->getCriterionConfig(['role_id' => $this->expectedAfterFormSubmitValue]))
275 );
276 }

References ilTermsOfServiceUserHasGlobalRoleCriterion\evaluate().

+ Here is the call graph for this function:

◆ testEvaluationSucceedsIfUserIsAssignedToDefinedGlobalRole()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testEvaluationSucceedsIfUserIsAssignedToDefinedGlobalRole ( )

Definition at line 278 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

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

References ilTermsOfServiceUserHasGlobalRoleCriterion\evaluate().

+ Here is the call graph for this function:

◆ testFormUserInterfaceElementsAreProperlyBuilt()

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

Definition at line 111 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

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

◆ testInstanceCanBeCreated()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testInstanceCanBeCreated ( )
Returns
ilTermsOfServiceUserHasGlobalRoleCriterion

Definition at line 69 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

70 {
71 $criterion = $this->getInstance();
72
73 $this->assertSame('usr_global_role', $criterion->getTypeIdent());
74 $this->assertFalse($criterion->hasUniqueNature());
75
76 return $criterion;
77 }

References getInstance().

+ Here is the call graph for this function:

◆ testTypeIdentPresentationIsANonEmptyString()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testTypeIdentPresentationIsANonEmptyString ( ilTermsOfServiceUserHasGlobalRoleCriterion  $criterion)

@depends testFormUserInterfaceElementsAreProperlyBuilt

Parameters
ilTermsOfServiceUserHasGlobalRoleCriterion$criterion

Definition at line 163 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

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

◆ testValuesFromFormUserInterfaceElementsCanBeRetrieved()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testValuesFromFormUserInterfaceElementsCanBeRetrieved ( ilTermsOfServiceUserHasGlobalRoleCriterion  $criterion)

@depends testFormUserInterfaceElementsAreProperlyBuilt

Parameters
ilTermsOfServiceUserHasGlobalRoleCriterion$criterion

Definition at line 134 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

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

Field Documentation

◆ $adminRoleTitle

string ilTermsOfServiceUserHasGlobalRoleCriterionTest::$adminRoleTitle = 'Administrator'
protected

◆ $expectedAfterFormSubmitValue

int ilTermsOfServiceUserHasGlobalRoleCriterionTest::$expectedAfterFormSubmitValue = 4
protected

◆ $expectedInitialValue

int ilTermsOfServiceUserHasGlobalRoleCriterionTest::$expectedInitialValue = 2
protected

◆ $lng

ilLanguage ilTermsOfServiceUserHasGlobalRoleCriterionTest::$lng
protected

◆ $rbacReview

ilRbacReview ilTermsOfServiceUserHasGlobalRoleCriterionTest::$rbacReview
protected

◆ $userRoleTitle

string ilTermsOfServiceUserHasGlobalRoleCriterionTest::$userRoleTitle = 'User'
protected

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