19declare(strict_types=1);
23use PHPUnit\Framework\MockObject\MockObject;
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);
111 $this->assertSame($countrySelection->getValue(), $this->expectedInitialValue);
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 () {
135 return $this->expectedAfterFormSubmitValue;
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);
156 $this->assertIsString($actual);
157 $this->assertNotEmpty($actual);
166 'English Language' => [$this->expectedInitialValue, $this->englishLanguageTranslation],
167 'German Language' => [$this->expectedAfterFormSubmitValue, $this->germanLanguageTranslation],
168 'Invalid Languages' => [
'invalid_country',
''],
177 public function testValuePresentationMatchesExpectation(
string $country,
string $translation): void
179 $language = $this->getLanguageMock();
183 ->with(
'meta_c_' . $country,
'')
184 ->willReturn($translation);
187 $gui = $criterion->
ui($language);
191 $this->getCriterionConfig([
'country' => $country]),
192 $this->getUiFactoryMock()
195 $this->assertInstanceOf(Component::class, $actual);
196 $this->assertInstanceOf(Legacy::class, $actual);
197 $this->assertSame($translation, $actual->getContent());
202 $criterion = $this->getInstance();
205 'English Language where German is Expected' => [$criterion, $this->getCriterionConfig([
'country' =>
'en'])],
206 'Array' => [$criterion, $this->getCriterionConfig([
'country' => []])],
207 'Object' => [$criterion, $this->getCriterionConfig([
'country' =>
new stdClass()])],
208 'Double' => [$criterion, $this->getCriterionConfig([
'country' => 1.0])],
209 'Integer' => [$criterion, $this->getCriterionConfig([
'country' => 1])],
210 'Wrong Key Provided for Extracting Language' => [
212 $this->getCriterionConfig([
'another_config_key' =>
true])
214 'Empty Configuration' => [$criterion, $this->getCriterionConfig()],
220 $criterion = $this->getInstance();
223 'German Language' => [$criterion, $this->getCriterionConfig([
'country' =>
'de'])],
224 'German Language Uppercase' => [$criterion, $this->getCriterionConfig([
'country' =>
'DE'])],
237 $user = $this->getUserMock();
240 ->method(
'getSelectedCountry')
255 $user = $this->getUserMock();
258 ->method(
'getSelectedCountry')
getCriterionConfig($value=null)
Class ilTermsOfServiceCriterionBaseTest.
Class ilTermsOfServiceCriterionConfig.
Class ilTermsOfServiceUserHasCountryCriterionTest.
string $expectedAfterFormSubmitValue
string $expectedInitialValue
testTypeIdentPresentationIsANonEmptyString(ilTermsOfServiceUserHasCountryCriterion $criterion)
@depends testFormUserInterfaceElementsAreProperlyBuilt
string $englishLanguageTranslation
testInstanceCanBeCreated()
testEvaluationSucceedsIfUserCountryDoesMatchDefinedLanguage(ilTermsOfServiceUserHasCountryCriterion $criterion, ilTermsOfServiceCriterionConfig $config)
buildForm(ilTermsOfServiceCriterionTypeGUI $gui, string $httpCriterionSelectionBodyParameter)
testEvaluationFailsIfUserCountryDoesNotMatchDefinedLanguage(ilTermsOfServiceUserHasCountryCriterion $criterion, ilTermsOfServiceCriterionConfig $config)
testValuesFromFormUserInterfaceElementsCanBeRetrieved(ilTermsOfServiceUserHasCountryCriterion $criterion)
@depends testFormUserInterfaceElementsAreProperlyBuilt
succeedingConfigProvider()
testFormUserInterfaceElementsAreProperlyBuilt(ilTermsOfServiceUserHasCountryCriterion $criterion)
string $germanLanguageTranslation
Class ilTermsOfServiceUserHasCountryCriterion.
getTypeIdent()
Returns a unique id of the criterion type.
evaluate(ilObjUser $user, ilTermsOfServiceCriterionConfig $config)
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)