1<?
php declare(strict_types=1);
5use PHPUnit\Framework\MockObject\MockObject;
38 ->expects($this->any())
40 ->willReturn(
'dummy');
43 ->expects($this->any())
44 ->method(
'getInstalledLanguages')
45 ->willReturn([$this->expectedAfterFormSubmitValue, $this->expectedInitialValue]);
63 $this->assertEquals(
'usr_language', $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() .
'_lng';
107 $gui = $criterion->
ui($this->lng);
109 $this->assertInstanceOf(ilTermsOfServiceUserHasLanguageCriterionGUI::class, $gui);
111 $form = $this->buildForm($gui, $httpCriterionSelectionBodyParameter);
113 $languageSelection = $form->getItemByPostVar($httpCriterionConfigBodyParameter);
114 $this->assertInstanceOf(ilSelectInputGUI::class, $languageSelection);
115 $this->assertEquals($languageSelection->getValue(), $this->expectedInitialValue);
128 $httpCriterionSelectionBodyParameter =
'criterion';
129 $httpCriterionConfigBodyParameter = $criterion->
getTypeIdent() .
'_lng';
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[
'lng']);
147 $this->assertEquals($this->getCriterionConfig([
'lng' => $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_lng',
''],
183 public function testValuePresentationMatchesExpectation(
string $lng,
string $translation) : void
185 $language = $this->getLanguageMock();
188 ->expects($this->any())
190 ->with(
'meta_l_' .
$lng,
'')
191 ->willReturn($translation);
194 $gui = $criterion->
ui($language);
198 $this->getCriterionConfig([
'lng' =>
$lng]),
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([
'lng' =>
'en'])],
216 'Array' => [$criterion, $this->getCriterionConfig([
'lng' => []])],
217 'Object' => [$criterion, $this->getCriterionConfig([
'lng' =>
new stdClass()])],
218 'Double' => [$criterion, $this->getCriterionConfig([
'lng' => 1.0])],
219 'Integer' => [$criterion, $this->getCriterionConfig([
'lng' => 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([
'lng' =>
'de'])],
237 'German Language Uppercase' => [$criterion, $this->getCriterionConfig([
'lng' =>
'DE'])],
251 $user = $this->getUserMock();
254 ->expects($this->any())
255 ->method(
'getLanguage')
271 $user = $this->getUserMock();
274 ->expects($this->any())
275 ->method(
'getLanguage')
An exception for terminatinating execution or to throw for unit testing.
getCriterionConfig($value=null)
Class ilTermsOfServiceCriterionBaseTest.
Class ilTermsOfServiceCriterionConfig.
Class ilTermsOfServiceUserHasLanguageCriterionTest.
succeedingConfigProvider()
$englishLanguageTranslation
$expectedAfterFormSubmitValue
testValuesFromFormUserInterfaceElementsCanBeRetrieved(ilTermsOfServiceUserHasLanguageCriterion $criterion)
@depends testFormUserInterfaceElementsAreProperlyBuilt
$germanLanguageTranslation
testEvaluationFailsIfUserLanguageDoesNotMatchDefinedLanguage(ilTermsOfServiceUserHasLanguageCriterion $criterion, ilTermsOfServiceCriterionConfig $config)
testTypeIdentPresentationIsANonEmptyString(ilTermsOfServiceUserHasLanguageCriterion $criterion)
@depends testFormUserInterfaceElementsAreProperlyBuilt
buildForm(ilTermsOfServiceCriterionTypeGUI $gui, string $httpCriterionSelectionBodyParameter)
testFormUserInterfaceElementsAreProperlyBuilt(ilTermsOfServiceUserHasLanguageCriterion $criterion)
testInstanceCanBeCreated()
testEvaluationSucceedsIfUserLanguageDoesMatchDefinedLanguage(ilTermsOfServiceUserHasLanguageCriterion $criterion, ilTermsOfServiceCriterionConfig $config)
Class ilTermsOfServiceUserHasLanguageCriterion.
ui(ilLanguage $lng)
ilTermsOfServiceCriterionTypeGUI
evaluate(ilObjUser $user, ilTermsOfServiceCriterionConfig $config)
bool
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.
getConfigByForm(ilPropertyFormGUI $form)
getValuePresentation(ilTermsOfServiceCriterionConfig $config, Factory $uiFactory)
appendOption(ilRadioGroupInputGUI $option, ilTermsOfServiceCriterionConfig $config)