ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilTermsOfServiceUserHasGlobalRoleCriterionTest Class Reference

Class ilTermsOfServiceUserHasGlobalRoleCriterionTest. More...

+ Inheritance diagram for ilTermsOfServiceUserHasGlobalRoleCriterionTest:
+ Collaboration diagram for ilTermsOfServiceUserHasGlobalRoleCriterionTest:

Public Member Functions

 setUp ()
 
 testInstanceCanBeCreated ()
 
 testFormUserInterfaceElementsAreProperlyBuilt (\ilTermsOfServiceUserHasGlobalRoleCriterion $criterion)
 
 testValuesFromFormUserInterfaceElementsCanBeRetrieved (\ilTermsOfServiceUserHasGlobalRoleCriterion $criterion)
 testFormUserInterfaceElementsAreProperlyBuilt More...
 
 testTypeIdentPresentationIsANonEmptyString (\ilTermsOfServiceUserHasGlobalRoleCriterion $criterion)
 testFormUserInterfaceElementsAreProperlyBuilt More...
 
 objectCacheProvider ()
 
 failingConfigProvider ()
 
 testEvaluationFailsIfConfiguredRoleDoesNotMatchTheExpectedFormat (\ilTermsOfServiceUserHasGlobalRoleCriterion $criterion, \ilTermsOfServiceCriterionConfig $config)
 
 testEvaluationFailsIfConfiguredRoleIsNotAGlobalRole ()
 
 testEvaluationFailsIfUserIsNotAssignedToConfiguredGlobalRole ()
 
 testEvaluationSucceedsIfUserIsAssignedToDefinedGlobalRole ()
 

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 ()
 
 setGlobalVariable (string $name, $value)
 
 assertException (string $exceptionClass)
 
 getCriterionConfig ($value=null)
 

Protected Attributes

 $rbacReview
 
 $lng
 
 $expectedInitialValue = 2
 
 $expectedAfterFormSubmitValue = 4
 
 $userRoleTitle = 'User'
 
 $adminRoleTitle = 'Administrator'
 
- Protected Attributes inherited from ilTermsOfServiceBaseTest
 $dic
 

Detailed Description

Member Function Documentation

◆ buildForm()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::buildForm ( \ilTermsOfServiceCriterionTypeGUI  $gui,
string  $httpCriterionSelectionBodyParameter 
)
protected
Parameters
\ilTermsOfServiceCriterionTypeGUI$gui
string$httpCriterionSelectionBodyParameter
Returns
PHPUnit_Framework_MockObject_MockObject|

Definition at line 79 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

References $form, ilTermsOfServiceCriterionTypeGUI\appendOption(), ilTermsOfServiceCriterionBaseTest\getFormMock(), and ilTermsOfServiceCriterionBaseTest\getRadioGroupMock().

Referenced by testFormUserInterfaceElementsAreProperlyBuilt(), and testValuesFromFormUserInterfaceElementsCanBeRetrieved().

83  $form = $this->getFormMock();
84 
85  $radioGroup = $this->getRadioGroupMock();
86 
87  $radioGroup
88  ->expects($this->any())
89  ->method('getPostVar')
90  ->willReturn($httpCriterionSelectionBodyParameter);
91 
92  $form->addItem($radioGroup);
93 
94  $gui->appendOption(
95  $radioGroup,
96  new \ilTermsOfServiceCriterionConfig(['role_id' => $this->expectedInitialValue])
97  );
98 
99  return $form;
100  }
This class represents a property form user interface.
Class ilTermsOfServiceCriterionConfig.
if(isset($_POST['submit'])) $form
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ failingConfigProvider()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::failingConfigProvider ( )
Returns
array

Definition at line 214 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

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

214  : array
215  {
216  $criterion = $this->getInstance();
217 
218  return [
219  [$criterion, $this->getCriterionConfig(['role_id' => []])],
220  [$criterion, $this->getCriterionConfig(['role_id' => new stdClass()])],
221  [$criterion, $this->getCriterionConfig(['role_id' => 1.424])],
222  [$criterion, $this->getCriterionConfig(['role_id' => 'phpunit'])],
223  [$criterion, $this->getCriterionConfig(['another_config_key' => true])],
224  [$criterion, $this->getCriterionConfig()],
225  ];
226  }
+ Here is the call graph for this function:

◆ getInstance()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::getInstance ( )
protected
Returns

Definition at line 49 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

References ilTermsOfServiceCriterionBaseTest\getObjectDataCacheMock(), and ilTermsOfServiceCriterionBaseTest\getRbacReviewMock().

Referenced by failingConfigProvider(), testEvaluationFailsIfConfiguredRoleIsNotAGlobalRole(), testEvaluationFailsIfUserIsNotAssignedToConfiguredGlobalRole(), testEvaluationSucceedsIfUserIsAssignedToDefinedGlobalRole(), and testInstanceCanBeCreated().

50  {
51  $this->rbacReview = $this->getRbacReviewMock();
52 
53  $criterion = new \ilTermsOfServiceUserHasGlobalRoleCriterion(
54  $this->rbacReview,
55  $this->getObjectDataCacheMock()
56  );
57 
58  return $criterion;
59  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ objectCacheProvider()

◆ setUp()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::setUp ( )

Definition at line 34 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

References ilTermsOfServiceBaseTest\getLanguageMock().

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

◆ testEvaluationFailsIfConfiguredRoleDoesNotMatchTheExpectedFormat()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testEvaluationFailsIfConfiguredRoleDoesNotMatchTheExpectedFormat ( \ilTermsOfServiceUserHasGlobalRoleCriterion  $criterion,
\ilTermsOfServiceCriterionConfig  $config 
)
Parameters
\ilTermsOfServiceUserHasGlobalRoleCriterion$criterion
\ilTermsOfServiceCriterionConfig$configfailingConfigProvider

Definition at line 233 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

References $user, ilTermsOfServiceUserHasGlobalRoleCriterion\evaluate(), and ilTermsOfServiceCriterionBaseTest\getUserMock().

236  {
237  $user = $this->getUserMock();
238 
239  $this->assertFalse($criterion->evaluate($user, $config));
240  }
$config
Definition: bootstrap.php:15
$user
Definition: migrateto20.php:57
+ Here is the call graph for this function:

◆ testEvaluationFailsIfConfiguredRoleIsNotAGlobalRole()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testEvaluationFailsIfConfiguredRoleIsNotAGlobalRole ( )

Definition at line 245 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

References $user, getInstance(), ilTermsOfServiceCriterionBaseTest\getUserMock(), and Sabre\Event\once().

246  {
247  $user = $this->getUserMock();
248  $criterion = $this->getInstance();
249 
250  $this->rbacReview
251  ->expects($this->once())
252  ->method('isGlobalRole')
253  ->willReturn(false);
254 
255  $this->assertFalse(
256  $criterion->evaluate($user, $this->getCriterionConfig(['role_id' => $this->expectedAfterFormSubmitValue]))
257  );
258  }
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
$user
Definition: migrateto20.php:57
+ Here is the call graph for this function:

◆ testEvaluationFailsIfUserIsNotAssignedToConfiguredGlobalRole()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testEvaluationFailsIfUserIsNotAssignedToConfiguredGlobalRole ( )

Definition at line 263 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

References $user, getInstance(), ilTermsOfServiceCriterionBaseTest\getUserMock(), and Sabre\Event\once().

264  {
265  $user = $this->getUserMock();
266  $criterion = $this->getInstance();
267 
268  $this->rbacReview
269  ->expects($this->once())
270  ->method('isGlobalRole')
271  ->willReturn(true);
272 
273  $this->rbacReview
274  ->expects($this->once())
275  ->method('isAssigned')
276  ->willReturn(false);
277 
278  $this->assertFalse(
279  $criterion->evaluate($user, $this->getCriterionConfig(['role_id' => $this->expectedAfterFormSubmitValue]))
280  );
281  }
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
$user
Definition: migrateto20.php:57
+ Here is the call graph for this function:

◆ testEvaluationSucceedsIfUserIsAssignedToDefinedGlobalRole()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testEvaluationSucceedsIfUserIsAssignedToDefinedGlobalRole ( )

Definition at line 286 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

References $user, getInstance(), ilTermsOfServiceCriterionBaseTest\getUserMock(), and Sabre\Event\once().

287  {
288  $user = $this->getUserMock();
289  $criterion = $this->getInstance();
290 
291  $this->rbacReview
292  ->expects($this->once())
293  ->method('isGlobalRole')
294  ->willReturn(true);
295 
296  $this->rbacReview
297  ->expects($this->once())
298  ->method('isAssigned')
299  ->willReturn(true);
300 
301  $this->assertTrue(
302  $criterion->evaluate($user, $this->getCriterionConfig(['role_id' => $this->expectedAfterFormSubmitValue]))
303  );
304  }
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
$user
Definition: migrateto20.php:57
+ Here is the call graph for this function:

◆ testFormUserInterfaceElementsAreProperlyBuilt()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testFormUserInterfaceElementsAreProperlyBuilt ( \ilTermsOfServiceUserHasGlobalRoleCriterion  $criterion)
Parameters
\ilTermsOfServiceUserHasGlobalRoleCriterion$criteriontestInstanceCanBeCreated
Returns

Definition at line 107 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

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

109  {
110  $httpCriterionSelectionBodyParameter = 'criterion';
111  $httpCriterionConfigBodyParameter = $criterion->getTypeIdent() . '_role_id';
112 
113  $gui = $criterion->ui($this->lng);
114 
115  $this->assertInstanceOf(\ilTermsOfServiceUserHasGlobalRoleCriterionGUI::class, $gui);
116 
117  $form = $this->buildForm($gui, $httpCriterionSelectionBodyParameter);
118 
119  $roleSelection = $form->getItemByPostVar($httpCriterionConfigBodyParameter);
120  $this->assertInstanceOf(\ilSelectInputGUI::class, $roleSelection);
121  $this->assertEquals($roleSelection->getValue(), $this->expectedInitialValue);
122 
123  return $criterion;
124  }
if(isset($_POST['submit'])) $form
buildForm(\ilTermsOfServiceCriterionTypeGUI $gui, string $httpCriterionSelectionBodyParameter)
+ Here is the call graph for this function:

◆ testInstanceCanBeCreated()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testInstanceCanBeCreated ( )
Returns

Definition at line 64 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

References getInstance().

65  {
66  $criterion = $this->getInstance();
67 
68  $this->assertEquals('usr_global_role', $criterion->getTypeIdent());
69  $this->assertEquals(false, $criterion->hasUniqueNature());
70 
71  return $criterion;
72  }
+ Here is the call graph for this function:

◆ testTypeIdentPresentationIsANonEmptyString()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testTypeIdentPresentationIsANonEmptyString ( \ilTermsOfServiceUserHasGlobalRoleCriterion  $criterion)

testFormUserInterfaceElementsAreProperlyBuilt

Parameters
\ilTermsOfServiceUserHasGlobalRoleCriterion$criterion

Definition at line 159 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

References ilTermsOfServiceUserHasGlobalRoleCriterion\ui().

160  {
161  $gui = $criterion->ui($this->lng);
162 
163  $actual = $gui->getIdentPresentation();
164 
165  $this->assertInternalType('string', $actual);
166  $this->assertNotEmpty($actual);
167  }
+ Here is the call graph for this function:

◆ testValuesFromFormUserInterfaceElementsCanBeRetrieved()

ilTermsOfServiceUserHasGlobalRoleCriterionTest::testValuesFromFormUserInterfaceElementsCanBeRetrieved ( \ilTermsOfServiceUserHasGlobalRoleCriterion  $criterion)

testFormUserInterfaceElementsAreProperlyBuilt

Parameters
\ilTermsOfServiceUserHasGlobalRoleCriterion$criterion

Definition at line 130 of file ilTermsOfServiceUserHasGlobalRoleCriterionTest.php.

References $expectedAfterFormSubmitValue, $form, buildForm(), ilTermsOfServiceBaseTest\getCriterionConfig(), ilTermsOfServiceUserHasGlobalRoleCriterion\getTypeIdent(), Sabre\Event\once(), and ilTermsOfServiceUserHasGlobalRoleCriterion\ui().

132  {
133  $httpCriterionSelectionBodyParameter = 'criterion';
134  $httpCriterionConfigBodyParameter = $criterion->getTypeIdent() . '_role_id';
135 
136  $gui = $criterion->ui($this->lng);
137 
138  $form = $this->buildForm($gui, $httpCriterionSelectionBodyParameter);
139 
140  $form
141  ->expects($this->once())
142  ->method('getInput')
143  ->with($httpCriterionConfigBodyParameter)
144  ->will($this->returnCallback(function () {
146  }));
147 
148  $value = $gui->getConfigByForm($form);
149 
150  $this->assertInstanceOf(\ilTermsOfServiceCriterionConfig::class, $value);
151  $this->assertEquals($this->expectedAfterFormSubmitValue, $value['role_id']);
152  $this->assertEquals($this->getCriterionConfig(['role_id' => $this->expectedAfterFormSubmitValue]), $value);
153  }
if(isset($_POST['submit'])) $form
buildForm(\ilTermsOfServiceCriterionTypeGUI $gui, string $httpCriterionSelectionBodyParameter)
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

Field Documentation

◆ $adminRoleTitle

ilTermsOfServiceUserHasGlobalRoleCriterionTest::$adminRoleTitle = 'Administrator'
protected

◆ $expectedAfterFormSubmitValue

ilTermsOfServiceUserHasGlobalRoleCriterionTest::$expectedAfterFormSubmitValue = 4
protected

◆ $expectedInitialValue

ilTermsOfServiceUserHasGlobalRoleCriterionTest::$expectedInitialValue = 2
protected

◆ $lng

ilTermsOfServiceUserHasGlobalRoleCriterionTest::$lng
protected

◆ $rbacReview

ilTermsOfServiceUserHasGlobalRoleCriterionTest::$rbacReview
protected

◆ $userRoleTitle

ilTermsOfServiceUserHasGlobalRoleCriterionTest::$userRoleTitle = 'User'
protected

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