ILIAS  release_7 Revision v7.30-3-g800a261c036
ilTermsOfServiceUserHasCountryCriterionTest Class Reference

Class ilTermsOfServiceUserHasCountryCriterionTest. More...

+ Inheritance diagram for ilTermsOfServiceUserHasCountryCriterionTest:
+ Collaboration diagram for ilTermsOfServiceUserHasCountryCriterionTest:

Public Member Functions

 setUp ()
 @inheritDoc More...
 
 testInstanceCanBeCreated ()
 
 testFormUserInterfaceElementsAreProperlyBuilt (ilTermsOfServiceUserHasCountryCriterion $criterion)
 
 testValuesFromFormUserInterfaceElementsCanBeRetrieved (ilTermsOfServiceUserHasCountryCriterion $criterion)
 @depends testFormUserInterfaceElementsAreProperlyBuilt More...
 
 testTypeIdentPresentationIsANonEmptyString (ilTermsOfServiceUserHasCountryCriterion $criterion)
 @depends testFormUserInterfaceElementsAreProperlyBuilt More...
 
 countryProvider ()
 
 failingConfigProvider ()
 
 succeedingConfigProvider ()
 
 testEvaluationFailsIfUserCountryDoesNotMatchDefinedLanguage (ilTermsOfServiceUserHasCountryCriterion $criterion, ilTermsOfServiceCriterionConfig $config)
 
 testEvaluationSucceedsIfUserCountryDoesMatchDefinedLanguage (ilTermsOfServiceUserHasCountryCriterion $criterion, ilTermsOfServiceCriterionConfig $config)
 

Protected Member Functions

 getInstance ()
 
 buildForm (ilTermsOfServiceCriterionTypeGUI $gui, string $httpCriterionSelectionBodyParameter)
 
- Protected Member Functions inherited from ilTermsOfServiceCriterionBaseTest
 getRbacReviewMock ()
 
 getObjectDataCacheMock ()
 
 getRadioGroupMock ()
 
 getFormMock ()
 
 getUserMock ()
 
- Protected Member Functions inherited from ilTermsOfServiceBaseTest
 setUp ()
 
 getLanguageMock ()
 
 getUiFactoryMock ()
 
 setGlobalVariable (string $name, $value)
 
 getCriterionConfig ($value=null)
 

Protected Attributes

 $lng
 
 $expectedInitialValue = 'EN'
 
 $expectedAfterFormSubmitValue = 'DE'
 
 $englishLanguageTranslation = 'English'
 
 $germanLanguageTranslation = 'German'
 
 $countries = []
 
- Protected Attributes inherited from ilTermsOfServiceBaseTest
 $dic
 

Detailed Description

Member Function Documentation

◆ buildForm()

ilTermsOfServiceUserHasCountryCriterionTest::buildForm ( ilTermsOfServiceCriterionTypeGUI  $gui,
string  $httpCriterionSelectionBodyParameter 
)
protected
Parameters
ilTermsOfServiceCriterionTypeGUI$gui
string$httpCriterionSelectionBodyParameter
Returns
MockObject|ilPropertyFormGUI
Exceptions
ReflectionException

Definition at line 75 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

79 $form = $this->getFormMock();
80
81 $radioGroup = $this->getRadioGroupMock();
82
83 $radioGroup
84 ->expects($this->any())
85 ->method('getPostVar')
86 ->willReturn($httpCriterionSelectionBodyParameter);
87
88 $form->addItem($radioGroup);
89
90 $gui->appendOption($radioGroup, $this->getCriterionConfig(['country' => $this->expectedInitialValue]));
91
92 return $form;
93 }
This class represents a property form user interface.
appendOption(ilRadioGroupInputGUI $option, ilTermsOfServiceCriterionConfig $config)

◆ countryProvider()

◆ failingConfigProvider()

ilTermsOfServiceUserHasCountryCriterionTest::failingConfigProvider ( )
Returns
array

Definition at line 210 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

210 : array
211 {
212 $criterion = $this->getInstance();
213
214 return [
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' => [
221 $criterion,
222 $this->getCriterionConfig(['another_config_key' => true])
223 ],
224 'Empty Configuration' => [$criterion, $this->getCriterionConfig()],
225 ];
226 }

◆ getInstance()

ilTermsOfServiceUserHasCountryCriterionTest::getInstance ( )
protected
Returns
ilTermsOfServiceUserHasCountryCriterion

Definition at line 51 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

Referenced by testInstanceCanBeCreated().

+ Here is the caller graph for this function:

◆ setUp()

ilTermsOfServiceUserHasCountryCriterionTest::setUp ( )

@inheritDoc

Reimplemented from ilTermsOfServiceBaseTest.

Definition at line 34 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

34 : void
35 {
36 parent::setUp();
37
38 $this->lng = $this->getLanguageMock();
39
40 $this->lng
41 ->expects($this->any())
42 ->method('txt')
43 ->willReturn('dummy');
44
45 $this->countries = ['EN', 'DE'];
46 }

References ilTermsOfServiceBaseTest\getLanguageMock().

+ Here is the call graph for this function:

◆ succeedingConfigProvider()

ilTermsOfServiceUserHasCountryCriterionTest::succeedingConfigProvider ( )
Returns
array

Definition at line 231 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

231 : array
232 {
233 $criterion = $this->getInstance();
234
235 return [
236 'German Language' => [$criterion, $this->getCriterionConfig(['country' => 'de'])],
237 'German Language Uppercase' => [$criterion, $this->getCriterionConfig(['country' => 'DE'])],
238 ];
239 }

◆ testEvaluationFailsIfUserCountryDoesNotMatchDefinedLanguage()

ilTermsOfServiceUserHasCountryCriterionTest::testEvaluationFailsIfUserCountryDoesNotMatchDefinedLanguage ( ilTermsOfServiceUserHasCountryCriterion  $criterion,
ilTermsOfServiceCriterionConfig  $config 
)
Parameters
ilTermsOfServiceUserHasCountryCriterion$criterion
ilTermsOfServiceCriterionConfig$config@dataProvider failingConfigProvider
Exceptions
ReflectionException

Definition at line 247 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

250 : void {
251 $user = $this->getUserMock();
252
253 $user
254 ->expects($this->any())
255 ->method('getSelectedCountry')
256 ->willReturn('de');
257
258 $this->assertFalse($criterion->evaluate($user, $config));
259 }
evaluate(ilObjUser $user, ilTermsOfServiceCriterionConfig $config)
bool
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68

◆ testEvaluationSucceedsIfUserCountryDoesMatchDefinedLanguage()

ilTermsOfServiceUserHasCountryCriterionTest::testEvaluationSucceedsIfUserCountryDoesMatchDefinedLanguage ( ilTermsOfServiceUserHasCountryCriterion  $criterion,
ilTermsOfServiceCriterionConfig  $config 
)
Parameters
ilTermsOfServiceUserHasCountryCriterion$criterion
ilTermsOfServiceCriterionConfig$config@dataProvider succeedingConfigProvider
Exceptions
ReflectionException

Definition at line 267 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

270 : void {
271 $user = $this->getUserMock();
272
273 $user
274 ->expects($this->any())
275 ->method('getSelectedCountry')
276 ->willReturn('de');
277
278 $this->assertTrue($criterion->evaluate($user, $config));
279 }

◆ testFormUserInterfaceElementsAreProperlyBuilt()

ilTermsOfServiceUserHasCountryCriterionTest::testFormUserInterfaceElementsAreProperlyBuilt ( ilTermsOfServiceUserHasCountryCriterion  $criterion)
Parameters
ilTermsOfServiceUserHasCountryCriterion$criterion@depends testInstanceCanBeCreated
Returns
ilTermsOfServiceUserHasCountryCriterion
Exceptions
ReflectionException

Definition at line 101 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

104 $httpCriterionSelectionBodyParameter = 'criterion';
105 $httpCriterionConfigBodyParameter = $criterion->getTypeIdent() . '_country';
106
107 $gui = $criterion->ui($this->lng);
108
109 $this->assertInstanceOf(ilTermsOfServiceUserHasCountryCriterionGUI::class, $gui);
110
111 $form = $this->buildForm($gui, $httpCriterionSelectionBodyParameter);
112
113 $countrySelection = $form->getItemByPostVar($httpCriterionConfigBodyParameter);
114 $this->assertInstanceOf(ilSelectInputGUI::class, $countrySelection);
115 $this->assertEquals($countrySelection->getValue(), $this->expectedInitialValue);
116
117 return $criterion;
118 }
buildForm(ilTermsOfServiceCriterionTypeGUI $gui, string $httpCriterionSelectionBodyParameter)
ui(ilLanguage $lng)
ilTermsOfServiceCriterionTypeGUI
getTypeIdent()
Returns a unique id of the criterion type.string

◆ testInstanceCanBeCreated()

ilTermsOfServiceUserHasCountryCriterionTest::testInstanceCanBeCreated ( )
Returns
ilTermsOfServiceUserHasCountryCriterion

Definition at line 59 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

60 {
61 $criterion = $this->getInstance();
62
63 $this->assertEquals('usr_country', $criterion->getTypeIdent());
64 $this->assertEquals(true, $criterion->hasUniqueNature());
65
66 return $criterion;
67 }

References getInstance().

+ Here is the call graph for this function:

◆ testTypeIdentPresentationIsANonEmptyString()

ilTermsOfServiceUserHasCountryCriterionTest::testTypeIdentPresentationIsANonEmptyString ( ilTermsOfServiceUserHasCountryCriterion  $criterion)

@depends testFormUserInterfaceElementsAreProperlyBuilt

Parameters
ilTermsOfServiceUserHasCountryCriterion$criterion

Definition at line 154 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

156 : void {
157 $gui = $criterion->ui($this->lng);
158
159 $actual = $gui->getIdentPresentation();
160
161 $this->assertIsString($actual);
162 $this->assertNotEmpty($actual);
163 }

◆ testValuesFromFormUserInterfaceElementsCanBeRetrieved()

ilTermsOfServiceUserHasCountryCriterionTest::testValuesFromFormUserInterfaceElementsCanBeRetrieved ( ilTermsOfServiceUserHasCountryCriterion  $criterion)

@depends testFormUserInterfaceElementsAreProperlyBuilt

Parameters
ilTermsOfServiceUserHasCountryCriterion$criterion
Exceptions
ReflectionException

Definition at line 125 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

127 : void {
128 $httpCriterionSelectionBodyParameter = 'criterion';
129 $httpCriterionConfigBodyParameter = $criterion->getTypeIdent() . '_country';
130
131 $gui = $criterion->ui($this->lng);
132
133 $form = $this->buildForm($gui, $httpCriterionSelectionBodyParameter);
134
135 $form
136 ->expects($this->once())
137 ->method('getInput')
138 ->with($httpCriterionConfigBodyParameter)
139 ->will($this->returnCallback(function () {
141 }));
142
143 $value = $gui->getConfigByForm($form);
144
145 $this->assertInstanceOf(ilTermsOfServiceCriterionConfig::class, $value);
146 $this->assertEquals($this->expectedAfterFormSubmitValue, $value['country']);
147 $this->assertEquals($this->getCriterionConfig(['country' => $this->expectedAfterFormSubmitValue]), $value);
148 }

Field Documentation

◆ $countries

ilTermsOfServiceUserHasCountryCriterionTest::$countries = []
protected

◆ $englishLanguageTranslation

ilTermsOfServiceUserHasCountryCriterionTest::$englishLanguageTranslation = 'English'
protected

◆ $expectedAfterFormSubmitValue

ilTermsOfServiceUserHasCountryCriterionTest::$expectedAfterFormSubmitValue = 'DE'
protected

◆ $expectedInitialValue

ilTermsOfServiceUserHasCountryCriterionTest::$expectedInitialValue = 'EN'
protected

◆ $germanLanguageTranslation

ilTermsOfServiceUserHasCountryCriterionTest::$germanLanguageTranslation = 'German'
protected

◆ $lng

ilTermsOfServiceUserHasCountryCriterionTest::$lng
protected

The documentation for this class was generated from the following file: