ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
RoleTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
31 use ilRbacReview;
32 use ilObjUser;
33 
34 require_once __DIR__ . '/../ContainerMock.php';
35 
36 class RoleTest extends TestCase
37 {
38  use ContainerMock;
39 
40  public function testConstruct(): void
41  {
42  $this->assertInstanceOf(Role::class, new Role(
43  $this->mock(CriterionContent::class),
44  $this->mock(RoleDefinition::class),
45  $this->mock(UIFactory::class),
46  $this->mock(ilRbacReview::class)
47  ));
48  }
49 
50  public function testAsComponent(): void
51  {
52  $legacy = $this->mock(Legacy\Content::class);
53  $legacy_factory = $this->mock(Legacy\Factory::class);
54  $legacy_factory
55  ->expects($this->once())
56  ->method('content')
57  ->willReturn($legacy);
58 
59  $this->assertSame($legacy, (new Role(
60  $this->mockTree(CriterionContent::class, ['arguments' => ['role_id' => 78]]),
61  $this->mock(RoleDefinition::class),
62  $this->mockTree(UIFactory::class, ['legacy' => $legacy_factory]),
63  $this->mock(ilRbacReview::class)
64  ))->asComponent());
65  }
66 
67  public function testEval(): void
68  {
69  $rbac = $this->mockMethod(ilRbacReview::class, 'isAssigned', [45, 78], true);
70 
71  $instance = new Role(
72  $this->mockTree(CriterionContent::class, ['arguments' => ['role_id' => 78]]),
73  $this->mock(RoleDefinition::class),
74  $this->mock(UIFactory::class),
75  $rbac
76  );
77 
78  $this->assertTrue($instance->eval($this->mockTree(ilObjUser::class, ['getId' => 45])));
79  }
80 
81  public function testDefinition(): void
82  {
83  $definition = $this->mock(RoleDefinition::class);
84 
85  $instance = new Role(
86  $this->mock(CriterionContent::class),
87  $definition,
88  $this->mock(UIFactory::class),
89  $this->mock(ilRbacReview::class)
90  );
91 
92  $this->assertSame($definition, $instance->definition());
93  }
94 
95  public function testKnownToNeverMatchWith(): void
96  {
97  $instance = new Role(
98  $this->mock(CriterionContent::class),
99  $this->mock(RoleDefinition::class),
100  $this->mock(UIFactory::class),
101  $this->mock(ilRbacReview::class)
102  );
103 
104  $this->assertFalse($instance->knownToNeverMatchWith($this->mock(Condition::class)));
105  }
106 }