ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilTermsOfServiceUserHasCountryCriterionTest Class Reference

Class ilTermsOfServiceUserHasCountryCriterionTest. More...

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

Public Member Functions

 setUp ()
 
 testInstanceCanBeCreated ()
 
 testFormUserInterfaceElementsAreProperlyBuilt (ilTermsOfServiceUserHasCountryCriterion $criterion)
 
 testValuesFromFormUserInterfaceElementsCanBeRetrieved (ilTermsOfServiceUserHasCountryCriterion $criterion)
 testFormUserInterfaceElementsAreProperlyBuilt More...
 
 testTypeIdentPresentationIsANonEmptyString (ilTermsOfServiceUserHasCountryCriterion $criterion)
 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.

References ilTermsOfServiceCriterionTypeGUI\appendOption(), ilTermsOfServiceBaseTest\getCriterionConfig(), ilTermsOfServiceCriterionBaseTest\getFormMock(), and ilTermsOfServiceCriterionBaseTest\getRadioGroupMock().

Referenced by testFormUserInterfaceElementsAreProperlyBuilt(), and testValuesFromFormUserInterfaceElementsCanBeRetrieved().

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)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ countryProvider()

◆ failingConfigProvider()

ilTermsOfServiceUserHasCountryCriterionTest::failingConfigProvider ( )
Returns
array

Definition at line 210 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

References ilTermsOfServiceBaseTest\getCriterionConfig(), and getInstance().

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  }
+ Here is the call graph for this function:

◆ getInstance()

ilTermsOfServiceUserHasCountryCriterionTest::getInstance ( )
protected
Returns
ilTermsOfServiceUserHasCountryCriterion

Definition at line 51 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

Referenced by failingConfigProvider(), succeedingConfigProvider(), and testInstanceCanBeCreated().

52  {
53  return new ilTermsOfServiceUserHasCountryCriterion($this->countries);
54  }
+ Here is the caller graph for this function:

◆ setUp()

ilTermsOfServiceUserHasCountryCriterionTest::setUp ( )

Definition at line 34 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

References ilTermsOfServiceBaseTest\getLanguageMock().

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  }
+ Here is the call graph for this function:

◆ succeedingConfigProvider()

ilTermsOfServiceUserHasCountryCriterionTest::succeedingConfigProvider ( )
Returns
array

Definition at line 231 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

References ilTermsOfServiceBaseTest\getCriterionConfig(), and getInstance().

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  }
+ Here is the call graph for this function:

◆ testEvaluationFailsIfUserCountryDoesNotMatchDefinedLanguage()

ilTermsOfServiceUserHasCountryCriterionTest::testEvaluationFailsIfUserCountryDoesNotMatchDefinedLanguage ( ilTermsOfServiceUserHasCountryCriterion  $criterion,
ilTermsOfServiceCriterionConfig  $config 
)
Parameters
ilTermsOfServiceUserHasCountryCriterion$criterion
ilTermsOfServiceCriterionConfig$configfailingConfigProvider
Exceptions
ReflectionException

Definition at line 247 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

References ilTermsOfServiceUserHasCountryCriterion\evaluate(), and ilTermsOfServiceCriterionBaseTest\getUserMock().

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
+ Here is the call graph for this function:

◆ testEvaluationSucceedsIfUserCountryDoesMatchDefinedLanguage()

ilTermsOfServiceUserHasCountryCriterionTest::testEvaluationSucceedsIfUserCountryDoesMatchDefinedLanguage ( ilTermsOfServiceUserHasCountryCriterion  $criterion,
ilTermsOfServiceCriterionConfig  $config 
)
Parameters
ilTermsOfServiceUserHasCountryCriterion$criterion
ilTermsOfServiceCriterionConfig$configsucceedingConfigProvider
Exceptions
ReflectionException

Definition at line 267 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

References ilTermsOfServiceUserHasCountryCriterion\evaluate(), and ilTermsOfServiceCriterionBaseTest\getUserMock().

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  }
evaluate(ilObjUser $user, ilTermsOfServiceCriterionConfig $config)
bool
+ Here is the call graph for this function:

◆ testFormUserInterfaceElementsAreProperlyBuilt()

ilTermsOfServiceUserHasCountryCriterionTest::testFormUserInterfaceElementsAreProperlyBuilt ( ilTermsOfServiceUserHasCountryCriterion  $criterion)
Parameters
ilTermsOfServiceUserHasCountryCriterion$criteriontestInstanceCanBeCreated
Returns
ilTermsOfServiceUserHasCountryCriterion
Exceptions
ReflectionException

Definition at line 101 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

References $expectedInitialValue, buildForm(), ilTermsOfServiceUserHasCountryCriterion\getTypeIdent(), and ilTermsOfServiceUserHasCountryCriterion\ui().

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  }
ui(ilLanguage $lng)
ilTermsOfServiceCriterionTypeGUI
getTypeIdent()
Returns a unique id of the criterion type.string
buildForm(ilTermsOfServiceCriterionTypeGUI $gui, string $httpCriterionSelectionBodyParameter)
+ Here is the call graph for this function:

◆ testInstanceCanBeCreated()

ilTermsOfServiceUserHasCountryCriterionTest::testInstanceCanBeCreated ( )
Returns
ilTermsOfServiceUserHasCountryCriterion

Definition at line 59 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

References getInstance().

60  {
61  $criterion = $this->getInstance();
62 
63  $this->assertEquals('usr_country', $criterion->getTypeIdent());
64  $this->assertEquals(true, $criterion->hasUniqueNature());
65 
66  return $criterion;
67  }
+ Here is the call graph for this function:

◆ testTypeIdentPresentationIsANonEmptyString()

ilTermsOfServiceUserHasCountryCriterionTest::testTypeIdentPresentationIsANonEmptyString ( ilTermsOfServiceUserHasCountryCriterion  $criterion)

testFormUserInterfaceElementsAreProperlyBuilt

Parameters
ilTermsOfServiceUserHasCountryCriterion$criterion

Definition at line 154 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

References ilTermsOfServiceUserHasCountryCriterion\ui().

156  : void {
157  $gui = $criterion->ui($this->lng);
158 
159  $actual = $gui->getIdentPresentation();
160 
161  $this->assertIsString($actual);
162  $this->assertNotEmpty($actual);
163  }
ui(ilLanguage $lng)
ilTermsOfServiceCriterionTypeGUI
+ Here is the call graph for this function:

◆ testValuesFromFormUserInterfaceElementsCanBeRetrieved()

ilTermsOfServiceUserHasCountryCriterionTest::testValuesFromFormUserInterfaceElementsCanBeRetrieved ( ilTermsOfServiceUserHasCountryCriterion  $criterion)

testFormUserInterfaceElementsAreProperlyBuilt

Parameters
ilTermsOfServiceUserHasCountryCriterion$criterion
Exceptions
ReflectionException

Definition at line 125 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

References $expectedAfterFormSubmitValue, buildForm(), ilTermsOfServiceBaseTest\getCriterionConfig(), ilTermsOfServiceUserHasCountryCriterion\getTypeIdent(), and ilTermsOfServiceUserHasCountryCriterion\ui().

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  }
ui(ilLanguage $lng)
ilTermsOfServiceCriterionTypeGUI
getTypeIdent()
Returns a unique id of the criterion type.string
buildForm(ilTermsOfServiceCriterionTypeGUI $gui, string $httpCriterionSelectionBodyParameter)
+ Here is the call graph for this function:

Field Documentation

◆ $countries

ilTermsOfServiceUserHasCountryCriterionTest::$countries = []
protected

◆ $englishLanguageTranslation

ilTermsOfServiceUserHasCountryCriterionTest::$englishLanguageTranslation = 'English'
protected

Definition at line 23 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

Referenced by countryProvider().

◆ $expectedAfterFormSubmitValue

ilTermsOfServiceUserHasCountryCriterionTest::$expectedAfterFormSubmitValue = 'DE'
protected

◆ $expectedInitialValue

ilTermsOfServiceUserHasCountryCriterionTest::$expectedInitialValue = 'EN'
protected

◆ $germanLanguageTranslation

ilTermsOfServiceUserHasCountryCriterionTest::$germanLanguageTranslation = 'German'
protected

Definition at line 26 of file ilTermsOfServiceUserHasCountryCriterionTest.php.

Referenced by countryProvider().

◆ $lng

ilTermsOfServiceUserHasCountryCriterionTest::$lng
protected

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