ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
RoleDefinitionTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 use ilRbacReview;
33 
34 require_once __DIR__ . '/../../ContainerMock.php';
35 
36 class RoleDefinitionTest extends TestCase
37 {
38  use ContainerMock;
39 
40  public function testConstruct(): void
41  {
42  $this->assertInstanceOf(RoleDefinition::class, new RoleDefinition(
43  $this->mock(UI::class),
44  $this->mock(ilObjectDataCache::class),
45  $this->mock(ilRbacReview::class),
46  $this->fail(...)
47  ));
48  }
49 
50  public function testFormGroup(): void
51  {
52  if (!defined('SYSTEM_ROLE_ID')) {
53  define('SYSTEM_ROLE_ID', 2);
54  }
55 
56  $instance = new RoleDefinition(
57  $this->mock(UI::class),
58  $this->mock(ilObjectDataCache::class),
59  $this->mock(ilRbacReview::class),
60  fn() => $this->mock(Constraint::class)
61  );
62 
63  $this->assertInstanceOf(Group::class, $instance->formGroup());
64  }
65 
66  public function testTranslatedRole(): void
67  {
68  $instance = new RoleDefinition(
69  $this->mock(UI::class),
70  $this->mockMethod(ilObjectDataCache::class, 'lookupTitle', [87], 'foo'),
71  $this->mock(ilRbacReview::class),
72  $this->fail(...)
73  );
74 
75  $this->assertSame('foo', $instance->translatedRole(87));
76  }
77 
78  public function testTranslatedType(): void
79  {
80  $instance = new RoleDefinition(
81  $this->mockMethod(UI::class, 'txt', ['crit_type_usr_global_role'], 'foo'),
82  $this->mock(ilObjectDataCache::class),
83  $this->mock(ilRbacReview::class),
84  $this->fail(...)
85  );
86 
87  $this->assertSame('foo', $instance->translatedType());
88  }
89 
90  public function testWithCriterion(): void
91  {
92  $instance = new RoleDefinition(
93  $this->mock(UI::class),
94  $this->mock(ilObjectDataCache::class),
95  $this->mock(ilRbacReview::class),
96  $this->fail(...)
97  );
98 
99  $this->assertInstanceOf(Role::class, $instance->withCriterion($this->mock(CriterionContent::class)));
100  }
101 }