ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ProvideTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
33 use ilCtrl;
34 use ilAuthSession;
35 
36 require_once __DIR__ . '/ContainerMock.php';
37 
38 class ProvideTest extends TestCase
39 {
40  use ContainerMock;
41 
42  public function testConstruct(): void
43  {
44  $this->assertInstanceOf(Provide::class, new Provide('foo', $this->mock(Internal::class), $this->mock(Container::class)));
45  }
46 
47  public function testWithdrawal(): void
48  {
49  $container = $this->mockTree(Container::class, ['ctrl' => $this->mock(ilCtrl::class)]);
50  $container->expects(self::once())->method('offsetGet')->with('ilAuthSession')->willReturn($this->mock(ilAuthSession::class));
51 
52  $instance = new Provide('foo', $this->mockMethod(Internal::class, 'get', ['withdraw'], 'foo'), $container);
53 
54  $this->assertInstanceOf(ProvideWithdrawal::class, $instance->withdrawal());
55  }
56 
57  public function testPublicPage(): void
58  {
59  $container = $this->mockTree(Container::class, ['ctrl' => $this->mock(ilCtrl::class)]);
60 
61  $this->assertInstanceOf(ProvidePublicPage::class, (new Provide('foo', $this->mockMethod(
62  Internal::class,
63  'get',
64  ['public-page', 'foo'],
65  true
66  ), $container))->publicPage());
67  }
68 
69  public function testDocument(): void
70  {
71  $document = $this->mock(ProvideDocument::class);
72  $internal = $this->mockMethod(Internal::class, 'get', ['document', 'foo'], $document);
73 
74  $instance = new Provide('foo', $internal, $this->mock(Container::class));
75  $this->assertSame($document, $instance->document());
76  }
77 
78  public function testHistory(): void
79  {
80  $history = $this->mock(ProvideHistory::class);
81  $internal = $this->mockMethod(Internal::class, 'get', ['history', 'foo'], $history);
82 
83  $instance = new Provide('foo', $internal, $this->mock(Container::class));
84  $this->assertSame($history, $instance->history());
85  }
86 
87  public function testAllowEditing(): void
88  {
89  $document = $this->mock(ProvideDocument::class);
90 
91  $internal = $this->mock(Internal::class);
92  $internal->expects(self::exactly(2))->method('get')->withConsecutive(['document', 'foo'], ['writable-document', 'foo'])->willReturn($document);
93 
94  $instance = new Provide('foo', $internal, $this->mock(Container::class));
95  $instance->document();
96  $instance->allowEditing()->document();
97  }
98 
99  public function testPublicApi(): void
100  {
101  $public_api = $this->mock(PublicApi::class);
102  $internal = $this->mockMethod(Internal::class, 'get', ['public-api', 'foo'], $public_api);
103 
104  $instance = new Provide('foo', $internal, $this->mock(Container::class));
105 
106  $this->assertSame($public_api, $instance->publicApi());
107  }
108 
109  public function testId(): void
110  {
111  $this->assertSame('foo', (new Provide('foo', $this->mock(Internal::class), $this->mock(Container::class)))->id());
112  }
113 }
$container
Definition: wac.php:14