19 declare(strict_types=1);
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 () {
152 $value = $gui->getConfigByForm($form);
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);
168 $actual = $gui->getIdentPresentation();
170 $this->assertIsString($actual);
171 $this->assertNotEmpty($actual);
179 'Invalid Role Id' => [-1,
''],
188 public function testValuePresentationMatchesExpectation(
int $roleId,
string $roleTitle):
void 194 ->method(
'lookupTitle')
196 ->willReturn($roleTitle);
199 $gui = $criterion->ui($this->
lng);
202 $actual = $gui->getValuePresentation(
207 $this->assertInstanceOf(Component::class, $actual);
208 $this->assertInstanceOf(Legacy::class, $actual);
209 $this->assertSame($roleTitle, $actual->getContent());
221 'Wrong Key Provided for Extracting Role' => [
240 $this->assertFalse($criterion->
evaluate($user, $config));
249 ->expects($this->once())
250 ->method(
'isGlobalRole')
254 $criterion->evaluate($user, $this->getCriterionConfig([
'role_id' => $this->expectedAfterFormSubmitValue]))
264 ->expects($this->once())
265 ->method(
'isGlobalRole')
269 ->expects($this->once())
270 ->method(
'isAssigned')
274 $criterion->evaluate($user, $this->getCriterionConfig([
'role_id' => $this->expectedAfterFormSubmitValue]))
284 ->expects($this->once())
285 ->method(
'isGlobalRole')
289 ->expects($this->once())
290 ->method(
'isAssigned')
294 $criterion->evaluate($user, $this->getCriterionConfig([
'role_id' => $this->expectedAfterFormSubmitValue]))
getTypeIdent()
Returns a unique id of the criterion type.
Interface ilTermsOfServiceCriterionTypeGUI.
testEvaluationFailsIfConfiguredRoleDoesNotMatchTheExpectedFormat(ilTermsOfServiceUserHasGlobalRoleCriterion $criterion, ilTermsOfServiceCriterionConfig $config)
Class ilTermsOfServiceUserHasGlobalRoleCriterion.
testEvaluationSucceedsIfUserIsAssignedToDefinedGlobalRole()
testEvaluationFailsIfUserIsNotAssignedToConfiguredGlobalRole()
Class ilTermsOfServiceCriterionBaseTest.
buildForm(ilTermsOfServiceCriterionTypeGUI $gui, string $httpCriterionSelectionBodyParameter)
Class ilTermsOfServiceUserHasGlobalRoleCriterionTest.
testFormUserInterfaceElementsAreProperlyBuilt(ilTermsOfServiceUserHasGlobalRoleCriterion $criterion)
Class ilTermsOfServiceCriterionConfig.
testTypeIdentPresentationIsANonEmptyString(ilTermsOfServiceUserHasGlobalRoleCriterion $criterion)
testFormUserInterfaceElementsAreProperlyBuilt
getCriterionConfig($value=null)
evaluate(ilObjUser $user, ilTermsOfServiceCriterionConfig $config)
testEvaluationFailsIfConfiguredRoleIsNotAGlobalRole()
appendOption(ilRadioGroupInputGUI $group, ilTermsOfServiceCriterionConfig $config)
int $expectedInitialValue
testValuesFromFormUserInterfaceElementsCanBeRetrieved(ilTermsOfServiceUserHasGlobalRoleCriterion $criterion)
testFormUserInterfaceElementsAreProperlyBuilt
int $expectedAfterFormSubmitValue
testInstanceCanBeCreated()