41 ->expects($this->any())
43 ->willReturn(
'dummy');
53 $criterion = new \ilTermsOfServiceUserHasGlobalRoleCriterion(
68 $this->assertEquals(
'usr_global_role', $criterion->getTypeIdent());
69 $this->assertEquals(
false, $criterion->hasUniqueNature());
81 string $httpCriterionSelectionBodyParameter
88 ->expects($this->any())
89 ->method(
'getPostVar')
90 ->willReturn($httpCriterionSelectionBodyParameter);
92 $form->addItem($radioGroup);
110 $httpCriterionSelectionBodyParameter =
'criterion';
111 $httpCriterionConfigBodyParameter = $criterion->
getTypeIdent() .
'_role_id';
113 $gui = $criterion->
ui($this->lng);
115 $this->assertInstanceOf(\ilTermsOfServiceUserHasGlobalRoleCriterionGUI::class, $gui);
117 $form = $this->buildForm($gui, $httpCriterionSelectionBodyParameter);
119 $roleSelection =
$form->getItemByPostVar($httpCriterionConfigBodyParameter);
120 $this->assertInstanceOf(\ilSelectInputGUI::class, $roleSelection);
121 $this->assertEquals($roleSelection->getValue(), $this->expectedInitialValue);
133 $httpCriterionSelectionBodyParameter =
'criterion';
134 $httpCriterionConfigBodyParameter = $criterion->
getTypeIdent() .
'_role_id';
136 $gui = $criterion->
ui($this->lng);
138 $form = $this->buildForm($gui, $httpCriterionSelectionBodyParameter);
141 ->expects($this->
once())
143 ->with($httpCriterionConfigBodyParameter)
144 ->will($this->returnCallback(
function () {
145 return $this->expectedAfterFormSubmitValue;
150 $this->assertInstanceOf(\ilTermsOfServiceCriterionConfig::class, $value);
151 $this->assertEquals($this->expectedAfterFormSubmitValue, $value[
'role_id']);
152 $this->assertEquals($this->getCriterionConfig([
'role_id' => $this->expectedAfterFormSubmitValue]), $value);
161 $gui = $criterion->
ui($this->lng);
165 $this->assertInternalType(
'string', $actual);
166 $this->assertNotEmpty($actual);
175 [$this->expectedInitialValue, $this->adminRoleTitle],
176 [$this->expectedAfterFormSubmitValue, $this->userRoleTitle],
186 public function testValuePresentationMatchesExpectation(
int $roleId,
string $roleTitle)
188 $rbacReview = $this->getRbacReviewMock();
189 $objectDataCache = $this->getObjectDataCacheMock();
192 ->expects($this->any())
193 ->method(
'lookupTitle')
195 ->willReturn($roleTitle);
197 $criterion = new \ilTermsOfServiceUserHasGlobalRoleCriterion($rbacReview, $objectDataCache);
198 $gui = $criterion->ui($this->lng);
202 $this->getCriterionConfig([
'role_id' => $roleId]),
203 $this->dic->ui()->factory()
206 $this->assertInstanceOf(Component::class, $actual);
207 $this->assertInstanceOf(Legacy::class, $actual);
208 $this->assertEquals($roleTitle, $actual->getContent());
216 $criterion = $this->getInstance();
219 [$criterion, $this->getCriterionConfig([
'role_id' => []])],
220 [$criterion, $this->getCriterionConfig([
'role_id' =>
new stdClass()])],
221 [$criterion, $this->getCriterionConfig([
'role_id' => 1.424])],
222 [$criterion, $this->getCriterionConfig([
'role_id' =>
'phpunit'])],
223 [$criterion, $this->getCriterionConfig([
'another_config_key' =>
true])],
224 [$criterion, $this->getCriterionConfig()],
237 $user = $this->getUserMock();
247 $user = $this->getUserMock();
248 $criterion = $this->getInstance();
251 ->expects($this->
once())
252 ->method(
'isGlobalRole')
256 $criterion->evaluate(
$user, $this->getCriterionConfig([
'role_id' => $this->expectedAfterFormSubmitValue]))
265 $user = $this->getUserMock();
266 $criterion = $this->getInstance();
269 ->expects($this->
once())
270 ->method(
'isGlobalRole')
274 ->expects($this->
once())
275 ->method(
'isAssigned')
279 $criterion->evaluate(
$user, $this->getCriterionConfig([
'role_id' => $this->expectedAfterFormSubmitValue]))
288 $user = $this->getUserMock();
289 $criterion = $this->getInstance();
292 ->expects($this->
once())
293 ->method(
'isGlobalRole')
297 ->expects($this->
once())
298 ->method(
'isAssigned')
302 $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
buildForm(\ilTermsOfServiceCriterionTypeGUI $gui, string $httpCriterionSelectionBodyParameter)
testEvaluationSucceedsIfUserIsAssignedToDefinedGlobalRole()
testValuesFromFormUserInterfaceElementsCanBeRetrieved(\ilTermsOfServiceUserHasGlobalRoleCriterion $criterion)
@depends testFormUserInterfaceElementsAreProperlyBuilt
testEvaluationFailsIfConfiguredRoleIsNotAGlobalRole()
testTypeIdentPresentationIsANonEmptyString(\ilTermsOfServiceUserHasGlobalRoleCriterion $criterion)
@depends testFormUserInterfaceElementsAreProperlyBuilt
testInstanceCanBeCreated()
testFormUserInterfaceElementsAreProperlyBuilt(\ilTermsOfServiceUserHasGlobalRoleCriterion $criterion)
testEvaluationFailsIfConfiguredRoleDoesNotMatchTheExpectedFormat(\ilTermsOfServiceUserHasGlobalRoleCriterion $criterion, \ilTermsOfServiceCriterionConfig $config)
testEvaluationFailsIfUserIsNotAssignedToConfiguredGlobalRole()
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.
appendOption(\ilRadioGroupInputGUI $option, \ilTermsOfServiceCriterionConfig $config)
getValuePresentation(\ilTermsOfServiceCriterionConfig $config, Factory $uiFactory)
getConfigByForm(\ilPropertyFormGUI $form)
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
if(isset($_POST['submit'])) $form