19declare(strict_types=1);
23use PHPUnit\Framework\MockObject\MockObject;
38 protected function setUp(): void
46 ->willReturn(
'dummy');
49 ->method(
'getInstalledLanguages')
50 ->willReturn([$this->expectedAfterFormSubmitValue, $this->expectedInitialValue]);
62 $this->assertSame(
'usr_language', $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() .
'_lng';
103 $gui = $criterion->
ui($this->
lng);
105 $this->assertInstanceOf(ilTermsOfServiceUserHasLanguageCriterionGUI::class, $gui);
107 $form = $this->buildForm($gui, $httpCriterionSelectionBodyParameter);
109 $languageSelection = $form->getItemByPostVar($httpCriterionConfigBodyParameter);
110 $this->assertInstanceOf(ilSelectInputGUI::class, $languageSelection);
111 $this->assertSame($languageSelection->getValue(), $this->expectedInitialValue);
123 $httpCriterionSelectionBodyParameter =
'criterion';
124 $httpCriterionConfigBodyParameter = $criterion->
getTypeIdent() .
'_lng';
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[
'lng']);
142 $this->assertEquals($this->getCriterionConfig([
'lng' => $this->expectedAfterFormSubmitValue]), $value);
152 $gui = $criterion->
ui($this->
lng);
156 $this->assertIsString($actual);
157 $this->assertNotEmpty($actual);
163 'English Language' => [$this->expectedInitialValue, $this->englishLanguageTranslation],
164 'German Language' => [$this->expectedAfterFormSubmitValue, $this->germanLanguageTranslation],
165 'Invalid Languages' => [
'invalid_lng',
''],
174 public function testValuePresentationMatchesExpectation(
string $lng,
string $translation): void
176 $language = $this->getLanguageMock();
180 ->with(
'meta_l_' .
$lng,
'')
181 ->willReturn($translation);
184 $gui = $criterion->
ui($language);
188 $this->getCriterionConfig([
'lng' =>
$lng]),
189 $this->getUiFactoryMock()
192 $this->assertInstanceOf(Component::class, $actual);
193 $this->assertInstanceOf(Legacy::class, $actual);
194 $this->assertSame($translation, $actual->getContent());
199 $criterion = $this->getInstance();
202 'English Language where German is Expected' => [$criterion, $this->getCriterionConfig([
'lng' =>
'en'])],
203 'Array' => [$criterion, $this->getCriterionConfig([
'lng' => []])],
204 'Object' => [$criterion, $this->getCriterionConfig([
'lng' =>
new stdClass()])],
205 'Double' => [$criterion, $this->getCriterionConfig([
'lng' => 1.0])],
206 'Integer' => [$criterion, $this->getCriterionConfig([
'lng' => 1])],
207 'Wrong Key Provided for Extracting Language' => [
209 $this->getCriterionConfig([
'another_config_key' =>
true])
211 'Empty Configuration' => [$criterion, $this->getCriterionConfig()],
217 $criterion = $this->getInstance();
220 'German Language' => [$criterion, $this->getCriterionConfig([
'lng' =>
'de'])],
221 'German Language Uppercase' => [$criterion, $this->getCriterionConfig([
'lng' =>
'DE'])],
234 $user = $this->getUserMock();
237 ->method(
'getLanguage')
252 $user = $this->getUserMock();
255 ->method(
'getLanguage')
getCriterionConfig($value=null)
Class ilTermsOfServiceCriterionBaseTest.
Class ilTermsOfServiceCriterionConfig.
Class ilTermsOfServiceUserHasLanguageCriterionTest.
succeedingConfigProvider()
testValuesFromFormUserInterfaceElementsCanBeRetrieved(ilTermsOfServiceUserHasLanguageCriterion $criterion)
@depends testFormUserInterfaceElementsAreProperlyBuilt
testEvaluationFailsIfUserLanguageDoesNotMatchDefinedLanguage(ilTermsOfServiceUserHasLanguageCriterion $criterion, ilTermsOfServiceCriterionConfig $config)
testTypeIdentPresentationIsANonEmptyString(ilTermsOfServiceUserHasLanguageCriterion $criterion)
@depends testFormUserInterfaceElementsAreProperlyBuilt
buildForm(ilTermsOfServiceCriterionTypeGUI $gui, string $httpCriterionSelectionBodyParameter)
string $englishLanguageTranslation
string $expectedInitialValue
string $expectedAfterFormSubmitValue
testFormUserInterfaceElementsAreProperlyBuilt(ilTermsOfServiceUserHasLanguageCriterion $criterion)
testInstanceCanBeCreated()
string $germanLanguageTranslation
testEvaluationSucceedsIfUserLanguageDoesMatchDefinedLanguage(ilTermsOfServiceUserHasLanguageCriterion $criterion, ilTermsOfServiceCriterionConfig $config)
Class ilTermsOfServiceUserHasLanguageCriterion.
evaluate(ilObjUser $user, ilTermsOfServiceCriterionConfig $config)
getTypeIdent()
Returns a unique id of the criterion type.
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)