19declare(strict_types=1);
23use PHPUnit\Framework\MockObject\MockObject;
40 protected function setUp(): void
48 ->willReturn(
'dummy');
73 $this->assertSame(
'usr_global_role', $criterion->getTypeIdent());
74 $this->assertFalse($criterion->hasUniqueNature());
86 string $httpCriterionSelectionBodyParameter
93 ->method(
'getPostVar')
94 ->willReturn($httpCriterionSelectionBodyParameter);
96 $form->addItem($radioGroup);
114 $httpCriterionSelectionBodyParameter =
'criterion';
115 $httpCriterionConfigBodyParameter = $criterion->
getTypeIdent() .
'_role_id';
117 $gui = $criterion->
ui($this->
lng);
119 $this->assertInstanceOf(ilTermsOfServiceUserHasGlobalRoleCriterionGUI::class, $gui);
121 $form = $this->buildForm($gui, $httpCriterionSelectionBodyParameter);
123 $roleSelection = $form->getItemByPostVar($httpCriterionConfigBodyParameter);
124 $this->assertInstanceOf(ilSelectInputGUI::class, $roleSelection);
125 $this->assertEquals($roleSelection->getValue(), (
string) $this->expectedInitialValue);
137 $httpCriterionSelectionBodyParameter =
'criterion';
138 $httpCriterionConfigBodyParameter = $criterion->
getTypeIdent() .
'_role_id';
140 $gui = $criterion->
ui($this->
lng);
142 $form = $this->buildForm($gui, $httpCriterionSelectionBodyParameter);
145 ->expects($this->once())
147 ->with($httpCriterionConfigBodyParameter)
148 ->willReturnCallback(
function () {
149 return $this->expectedAfterFormSubmitValue;
154 $this->assertInstanceOf(ilTermsOfServiceCriterionConfig::class, $value);
155 $this->assertSame($this->expectedAfterFormSubmitValue, $value[
'role_id']);
156 $this->assertEquals($this->getCriterionConfig([
'role_id' => $this->expectedAfterFormSubmitValue]), $value);
166 $gui = $criterion->
ui($this->
lng);
170 $this->assertIsString($actual);
171 $this->assertNotEmpty($actual);
177 'Administrator Role Id' => [$this->expectedInitialValue, $this->adminRoleTitle],
178 'User Role Id' => [$this->expectedAfterFormSubmitValue, $this->userRoleTitle],
179 'Invalid Role Id' => [-1,
''],
188 public function testValuePresentationMatchesExpectation(
int $roleId,
string $roleTitle): void
190 $rbacReview = $this->getRbacReviewMock();
191 $objectDataCache = $this->getObjectDataCacheMock();
194 ->method(
'lookupTitle')
196 ->willReturn($roleTitle);
199 $gui = $criterion->
ui($this->
lng);
203 $this->getCriterionConfig([
'role_id' => $roleId]),
204 $this->getUiFactoryMock()
207 $this->assertInstanceOf(Component::class, $actual);
208 $this->assertInstanceOf(Legacy::class, $actual);
209 $this->assertSame($roleTitle, $actual->getContent());
214 $criterion = $this->getInstance();
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' => [
223 $this->getCriterionConfig([
'another_config_key' =>
true])
225 'Empty Configuration' => [$criterion, $this->getCriterionConfig()],
238 $user = $this->getUserMock();
245 $user = $this->getUserMock();
246 $criterion = $this->getInstance();
249 ->expects($this->once())
250 ->method(
'isGlobalRole')
254 $criterion->
evaluate($user, $this->getCriterionConfig([
'role_id' => $this->expectedAfterFormSubmitValue]))
260 $user = $this->getUserMock();
261 $criterion = $this->getInstance();
264 ->expects($this->once())
265 ->method(
'isGlobalRole')
269 ->expects($this->once())
270 ->method(
'isAssigned')
274 $criterion->
evaluate($user, $this->getCriterionConfig([
'role_id' => $this->expectedAfterFormSubmitValue]))
280 $user = $this->getUserMock();
281 $criterion = $this->getInstance();
284 ->expects($this->once())
285 ->method(
'isGlobalRole')
289 ->expects($this->once())
290 ->method(
'isAssigned')
294 $criterion->
evaluate($user, $this->getCriterionConfig([
'role_id' => $this->expectedAfterFormSubmitValue]))
class ilRbacReview Contains Review functions of core Rbac.
Class ilTermsOfServiceCriterionBaseTest.
Class ilTermsOfServiceCriterionConfig.
Class ilTermsOfServiceUserHasGlobalRoleCriterionTest.
testEvaluationSucceedsIfUserIsAssignedToDefinedGlobalRole()
testTypeIdentPresentationIsANonEmptyString(ilTermsOfServiceUserHasGlobalRoleCriterion $criterion)
@depends testFormUserInterfaceElementsAreProperlyBuilt
testEvaluationFailsIfConfiguredRoleIsNotAGlobalRole()
buildForm(ilTermsOfServiceCriterionTypeGUI $gui, string $httpCriterionSelectionBodyParameter)
testInstanceCanBeCreated()
int $expectedInitialValue
testFormUserInterfaceElementsAreProperlyBuilt(ilTermsOfServiceUserHasGlobalRoleCriterion $criterion)
testEvaluationFailsIfConfiguredRoleDoesNotMatchTheExpectedFormat(ilTermsOfServiceUserHasGlobalRoleCriterion $criterion, ilTermsOfServiceCriterionConfig $config)
int $expectedAfterFormSubmitValue
testEvaluationFailsIfUserIsNotAssignedToConfiguredGlobalRole()
testValuesFromFormUserInterfaceElementsCanBeRetrieved(ilTermsOfServiceUserHasGlobalRoleCriterion $criterion)
@depends testFormUserInterfaceElementsAreProperlyBuilt
Class ilTermsOfServiceUserHasGlobalRoleCriterion.
evaluate(ilObjUser $user, ilTermsOfServiceCriterionConfig $config)
getTypeIdent()
Returns a unique id of the criterion type.
A component is the most general form of an entity in the UI.
Interface ilTermsOfServiceCriterionTypeGUI.
appendOption(ilRadioGroupInputGUI $group, ilTermsOfServiceCriterionConfig $config)
getConfigByForm(ilPropertyFormGUI $form)
getValuePresentation(ilTermsOfServiceCriterionConfig $config, Factory $uiFactory)