1<?
php declare(strict_types=1);
6use PHPUnit\Framework\MockObject\MockObject;
42 ->expects($this->any())
44 ->willReturn(
'dummy');
71 $this->assertEquals(
'usr_global_role', $criterion->getTypeIdent());
72 $this->assertEquals(
false, $criterion->hasUniqueNature());
85 string $httpCriterionSelectionBodyParameter
92 ->expects($this->any())
93 ->method(
'getPostVar')
94 ->willReturn($httpCriterionSelectionBodyParameter);
96 $form->addItem($radioGroup);
115 $httpCriterionSelectionBodyParameter =
'criterion';
116 $httpCriterionConfigBodyParameter = $criterion->
getTypeIdent() .
'_role_id';
118 $gui = $criterion->
ui($this->lng);
120 $this->assertInstanceOf(ilTermsOfServiceUserHasGlobalRoleCriterionGUI::class, $gui);
122 $form = $this->buildForm($gui, $httpCriterionSelectionBodyParameter);
124 $roleSelection = $form->getItemByPostVar($httpCriterionConfigBodyParameter);
125 $this->assertInstanceOf(ilSelectInputGUI::class, $roleSelection);
126 $this->assertEquals($roleSelection->getValue(), $this->expectedInitialValue);
139 $httpCriterionSelectionBodyParameter =
'criterion';
140 $httpCriterionConfigBodyParameter = $criterion->
getTypeIdent() .
'_role_id';
142 $gui = $criterion->
ui($this->lng);
144 $form = $this->buildForm($gui, $httpCriterionSelectionBodyParameter);
147 ->expects($this->once())
149 ->with($httpCriterionConfigBodyParameter)
150 ->will($this->returnCallback(
function () {
151 return $this->expectedAfterFormSubmitValue;
156 $this->assertInstanceOf(ilTermsOfServiceCriterionConfig::class, $value);
157 $this->assertEquals($this->expectedAfterFormSubmitValue, $value[
'role_id']);
158 $this->assertEquals($this->getCriterionConfig([
'role_id' => $this->expectedAfterFormSubmitValue]), $value);
168 $gui = $criterion->
ui($this->lng);
172 $this->assertIsString($actual);
173 $this->assertNotEmpty($actual);
182 'Administrator Role Id' => [$this->expectedInitialValue, $this->adminRoleTitle],
183 'User Role Id' => [$this->expectedAfterFormSubmitValue, $this->userRoleTitle],
184 'Invalid Role Id' => [-1,
''],
194 public function testValuePresentationMatchesExpectation(
int $roleId,
string $roleTitle) : void
196 $rbacReview = $this->getRbacReviewMock();
197 $objectDataCache = $this->getObjectDataCacheMock();
200 ->expects($this->any())
201 ->method(
'lookupTitle')
203 ->willReturn($roleTitle);
206 $gui = $criterion->
ui($this->lng);
210 $this->getCriterionConfig([
'role_id' => $roleId]),
211 $this->getUiFactoryMock()
214 $this->assertInstanceOf(Component::class, $actual);
215 $this->assertInstanceOf(Legacy::class, $actual);
216 $this->assertEquals($roleTitle, $actual->getContent());
225 $criterion = $this->getInstance();
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' => [
234 $this->getCriterionConfig([
'another_config_key' =>
true])
236 'Empty Configuration' => [$criterion, $this->getCriterionConfig()],
250 $user = $this->getUserMock();
260 $user = $this->getUserMock();
261 $criterion = $this->getInstance();
264 ->expects($this->once())
265 ->method(
'isGlobalRole')
269 $criterion->
evaluate($user, $this->getCriterionConfig([
'role_id' => $this->expectedAfterFormSubmitValue]))
278 $user = $this->getUserMock();
279 $criterion = $this->getInstance();
282 ->expects($this->once())
283 ->method(
'isGlobalRole')
287 ->expects($this->once())
288 ->method(
'isAssigned')
292 $criterion->
evaluate($user, $this->getCriterionConfig([
'role_id' => $this->expectedAfterFormSubmitValue]))
301 $user = $this->getUserMock();
302 $criterion = $this->getInstance();
305 ->expects($this->once())
306 ->method(
'isGlobalRole')
310 ->expects($this->once())
311 ->method(
'isAssigned')
315 $criterion->
evaluate($user, $this->getCriterionConfig([
'role_id' => $this->expectedAfterFormSubmitValue]))
An exception for terminatinating execution or to throw for unit testing.
Class ilTermsOfServiceCriterionBaseTest.
Class ilTermsOfServiceCriterionConfig.
Class ilTermsOfServiceUserHasGlobalRoleCriterionTest.
$expectedAfterFormSubmitValue
testEvaluationSucceedsIfUserIsAssignedToDefinedGlobalRole()
testTypeIdentPresentationIsANonEmptyString(ilTermsOfServiceUserHasGlobalRoleCriterion $criterion)
@depends testFormUserInterfaceElementsAreProperlyBuilt
testEvaluationFailsIfConfiguredRoleIsNotAGlobalRole()
buildForm(ilTermsOfServiceCriterionTypeGUI $gui, string $httpCriterionSelectionBodyParameter)
testInstanceCanBeCreated()
testFormUserInterfaceElementsAreProperlyBuilt(ilTermsOfServiceUserHasGlobalRoleCriterion $criterion)
testEvaluationFailsIfConfiguredRoleDoesNotMatchTheExpectedFormat(ilTermsOfServiceUserHasGlobalRoleCriterion $criterion, ilTermsOfServiceCriterionConfig $config)
testEvaluationFailsIfUserIsNotAssignedToConfiguredGlobalRole()
testValuesFromFormUserInterfaceElementsCanBeRetrieved(ilTermsOfServiceUserHasGlobalRoleCriterion $criterion)
@depends testFormUserInterfaceElementsAreProperlyBuilt
Class ilTermsOfServiceUserHasGlobalRoleCriterion.
evaluate(ilObjUser $user, ilTermsOfServiceCriterionConfig $config)
bool
ui(ilLanguage $lng)
ilTermsOfServiceCriterionTypeGUI
getTypeIdent()
Returns a unique id of the criterion type.string
A component is the most general form of an entity in the UI.
Interface ilTermsOfServiceCriterionTypeGUI.
getConfigByForm(ilPropertyFormGUI $form)
getValuePresentation(ilTermsOfServiceCriterionConfig $config, Factory $uiFactory)
appendOption(ilRadioGroupInputGUI $option, ilTermsOfServiceCriterionConfig $config)