1<?
php declare(strict_types=1);
5use PHPUnit\Framework\MockObject\MockObject;
41 ->expects($this->any())
43 ->willReturn(
'dummy');
45 $this->countries = [
'EN',
'DE'];
63 $this->assertEquals(
'usr_country', $criterion->getTypeIdent());
64 $this->assertEquals(
true, $criterion->hasUniqueNature());
77 string $httpCriterionSelectionBodyParameter
84 ->expects($this->any())
85 ->method(
'getPostVar')
86 ->willReturn($httpCriterionSelectionBodyParameter);
88 $form->addItem($radioGroup);
104 $httpCriterionSelectionBodyParameter =
'criterion';
105 $httpCriterionConfigBodyParameter = $criterion->
getTypeIdent() .
'_country';
107 $gui = $criterion->
ui($this->lng);
109 $this->assertInstanceOf(ilTermsOfServiceUserHasCountryCriterionGUI::class, $gui);
111 $form = $this->buildForm($gui, $httpCriterionSelectionBodyParameter);
113 $countrySelection = $form->getItemByPostVar($httpCriterionConfigBodyParameter);
114 $this->assertInstanceOf(ilSelectInputGUI::class, $countrySelection);
115 $this->assertEquals($countrySelection->getValue(), $this->expectedInitialValue);
128 $httpCriterionSelectionBodyParameter =
'criterion';
129 $httpCriterionConfigBodyParameter = $criterion->
getTypeIdent() .
'_country';
131 $gui = $criterion->
ui($this->lng);
133 $form = $this->buildForm($gui, $httpCriterionSelectionBodyParameter);
136 ->expects($this->once())
138 ->with($httpCriterionConfigBodyParameter)
139 ->will($this->returnCallback(
function () {
140 return $this->expectedAfterFormSubmitValue;
145 $this->assertInstanceOf(ilTermsOfServiceCriterionConfig::class, $value);
146 $this->assertEquals($this->expectedAfterFormSubmitValue, $value[
'country']);
147 $this->assertEquals($this->getCriterionConfig([
'country' => $this->expectedAfterFormSubmitValue]), $value);
157 $gui = $criterion->
ui($this->lng);
161 $this->assertIsString($actual);
162 $this->assertNotEmpty($actual);
171 'English Language' => [$this->expectedInitialValue, $this->englishLanguageTranslation],
172 'German Language' => [$this->expectedAfterFormSubmitValue, $this->germanLanguageTranslation],
173 'Invalid Languages' => [
'invalid_country',
''],
183 public function testValuePresentationMatchesExpectation(
string $country,
string $translation) : void
185 $language = $this->getLanguageMock();
188 ->expects($this->any())
190 ->with(
'meta_c_' . $country,
'')
191 ->willReturn($translation);
194 $gui = $criterion->
ui($language);
198 $this->getCriterionConfig([
'country' => $country]),
199 $this->getUiFactoryMock()
202 $this->assertInstanceOf(Component::class, $actual);
203 $this->assertInstanceOf(Legacy::class, $actual);
204 $this->assertEquals($translation, $actual->getContent());
212 $criterion = $this->getInstance();
215 'English Language where German is Expected' => [$criterion, $this->getCriterionConfig([
'country' =>
'en'])],
216 'Array' => [$criterion, $this->getCriterionConfig([
'country' => []])],
217 'Object' => [$criterion, $this->getCriterionConfig([
'country' =>
new stdClass()])],
218 'Double' => [$criterion, $this->getCriterionConfig([
'country' => 1.0])],
219 'Integer' => [$criterion, $this->getCriterionConfig([
'country' => 1])],
220 'Wrong Key Provided for Extracting Language' => [
222 $this->getCriterionConfig([
'another_config_key' =>
true])
224 'Empty Configuration' => [$criterion, $this->getCriterionConfig()],
233 $criterion = $this->getInstance();
236 'German Language' => [$criterion, $this->getCriterionConfig([
'country' =>
'de'])],
237 'German Language Uppercase' => [$criterion, $this->getCriterionConfig([
'country' =>
'DE'])],
251 $user = $this->getUserMock();
254 ->expects($this->any())
255 ->method(
'getSelectedCountry')
271 $user = $this->getUserMock();
274 ->expects($this->any())
275 ->method(
'getSelectedCountry')
An exception for terminatinating execution or to throw for unit testing.
getCriterionConfig($value=null)
Class ilTermsOfServiceCriterionBaseTest.
Class ilTermsOfServiceCriterionConfig.
Class ilTermsOfServiceUserHasCountryCriterionTest.
$germanLanguageTranslation
$englishLanguageTranslation
testTypeIdentPresentationIsANonEmptyString(ilTermsOfServiceUserHasCountryCriterion $criterion)
@depends testFormUserInterfaceElementsAreProperlyBuilt
$expectedAfterFormSubmitValue
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)
Class ilTermsOfServiceUserHasCountryCriterion.
ui(ilLanguage $lng)
ilTermsOfServiceCriterionTypeGUI
getTypeIdent()
Returns a unique id of the criterion type.string
evaluate(ilObjUser $user, ilTermsOfServiceCriterionConfig $config)
bool
A component is the most general form of an entity in the UI.
Interface ilTermsOfServiceCriterionTypeGUI.
getConfigByForm(ilPropertyFormGUI $form)
getValuePresentation(ilTermsOfServiceCriterionConfig $config, Factory $uiFactory)
appendOption(ilRadioGroupInputGUI $option, ilTermsOfServiceCriterionConfig $config)