ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ReadableTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Modules\Test\test;
22 
26 use ilAccessHandler;
27 
28 class ReadableTest extends TestCase
29 {
30  public function testConstruct(): void
31  {
32  $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock();
33 
34  $this->assertInstanceOf(Readable::class, new Readable($container));
35  }
36 
37  public function testReferences(): void
38  {
39  $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock();
40  $access = $this->getMockBuilder(ilAccessHandler::class)->disableOriginalConstructor()->getMock();
41 
42  $container->method('access')->willReturn($access);
43  $access->method('checkAccess')->with('read', '', 123)->willReturn(true);
44 
45  $this->assertTrue((new Readable($container))->references([123]));
46  }
47 
48  public function testObjectId(): void
49  {
50  $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock();
51  $access = $this->getMockBuilder(ilAccessHandler::class)->disableOriginalConstructor()->getMock();
52 
53  $container->method('access')->willReturn($access);
54  $access->method('checkAccess')->with('read', '', 456)->willReturn(true);
55 
56  $references_of = fn (int $object_id) => $this->assertSame(123, $object_id) ?: [456];
57 
58  $this->assertTrue((new Readable($container, $references_of))->objectId(123));
59  }
60 }
$container
Definition: wac.php:14