19 declare(strict_types=1);
40 protected function setUp(): void
48 ->willReturn(
'dummy');
50 $this->countries = [
'EN',
'DE'];
62 $this->assertSame(
'usr_country', $criterion->getTypeIdent());
63 $this->assertTrue($criterion->hasUniqueNature());
75 string $httpCriterionSelectionBodyParameter
82 ->method(
'getPostVar')
83 ->willReturn($httpCriterionSelectionBodyParameter);
85 $form->addItem($radioGroup);
100 $httpCriterionSelectionBodyParameter =
'criterion';
101 $httpCriterionConfigBodyParameter = $criterion->
getTypeIdent() .
'_country';
103 $gui = $criterion->
ui($this->
lng);
105 $this->assertInstanceOf(ilTermsOfServiceUserHasCountryCriterionGUI::class, $gui);
107 $form = $this->
buildForm($gui, $httpCriterionSelectionBodyParameter);
109 $countrySelection = $form->getItemByPostVar($httpCriterionConfigBodyParameter);
110 $this->assertInstanceOf(ilSelectInputGUI::class, $countrySelection);
123 $httpCriterionSelectionBodyParameter =
'criterion';
124 $httpCriterionConfigBodyParameter = $criterion->
getTypeIdent() .
'_country';
126 $gui = $criterion->
ui($this->
lng);
128 $form = $this->
buildForm($gui, $httpCriterionSelectionBodyParameter);
131 ->expects($this->once())
133 ->with($httpCriterionConfigBodyParameter)
134 ->willReturnCallback(
function () {
138 $value = $gui->getConfigByForm($form);
140 $this->assertInstanceOf(ilTermsOfServiceCriterionConfig::class, $value);
141 $this->assertSame($this->expectedAfterFormSubmitValue, $value[
'country']);
142 $this->assertEquals($this->
getCriterionConfig([
'country' => $this->expectedAfterFormSubmitValue]), $value);
152 $gui = $criterion->
ui($this->
lng);
154 $actual = $gui->getIdentPresentation();
156 $this->assertIsString($actual);
157 $this->assertNotEmpty($actual);
168 'Invalid Languages' => [
'invalid_country',
''],
177 public function testValuePresentationMatchesExpectation(
string $country,
string $translation):
void 183 ->with(
'meta_c_' . $country,
'')
184 ->willReturn($translation);
187 $gui = $criterion->ui($language);
190 $actual = $gui->getValuePresentation(
195 $this->assertInstanceOf(Component::class, $actual);
196 $this->assertInstanceOf(Legacy::class, $actual);
197 $this->assertSame($translation, $actual->getContent());
205 'English Language where German is Expected' => [$criterion, $this->
getCriterionConfig([
'country' =>
'en'])],
210 'Wrong Key Provided for Extracting Language' => [
224 'German Language Uppercase' => [$criterion, $this->
getCriterionConfig([
'country' =>
'DE'])],
240 ->method(
'getSelectedCountry')
243 $this->assertFalse($criterion->
evaluate($user, $config));
258 ->method(
'getSelectedCountry')
261 $this->assertTrue($criterion->
evaluate($user, $config));
Class ilTermsOfServiceUserHasCountryCriterionTest.
Interface ilTermsOfServiceCriterionTypeGUI.
testInstanceCanBeCreated()
Class ilTermsOfServiceCriterionBaseTest.
Class ilTermsOfServiceCriterionConfig.
getTypeIdent()
Returns a unique id of the criterion type.
string $expectedInitialValue
getCriterionConfig($value=null)
testValuesFromFormUserInterfaceElementsCanBeRetrieved(ilTermsOfServiceUserHasCountryCriterion $criterion)
testFormUserInterfaceElementsAreProperlyBuilt
testEvaluationFailsIfUserCountryDoesNotMatchDefinedLanguage(ilTermsOfServiceUserHasCountryCriterion $criterion, ilTermsOfServiceCriterionConfig $config)
string $germanLanguageTranslation
appendOption(ilRadioGroupInputGUI $group, ilTermsOfServiceCriterionConfig $config)
string $expectedAfterFormSubmitValue
Class ilTermsOfServiceUserHasCountryCriterion.
buildForm(ilTermsOfServiceCriterionTypeGUI $gui, string $httpCriterionSelectionBodyParameter)
testEvaluationSucceedsIfUserCountryDoesMatchDefinedLanguage(ilTermsOfServiceUserHasCountryCriterion $criterion, ilTermsOfServiceCriterionConfig $config)
testFormUserInterfaceElementsAreProperlyBuilt(ilTermsOfServiceUserHasCountryCriterion $criterion)
testTypeIdentPresentationIsANonEmptyString(ilTermsOfServiceUserHasCountryCriterion $criterion)
testFormUserInterfaceElementsAreProperlyBuilt
evaluate(ilObjUser $user, ilTermsOfServiceCriterionConfig $config)
succeedingConfigProvider()
string $englishLanguageTranslation