ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ProvideTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
30use PHPUnit\Framework\TestCase;
32use ilCtrl;
34
35require_once __DIR__ . '/ContainerMock.php';
36
37class ProvideTest extends TestCase
38{
39 use ContainerMock;
40
41 public function testConstruct(): void
42 {
43 $this->assertInstanceOf(Provide::class, new Provide('foo', $this->mock(Internal::class), $this->mock(Container::class)));
44 }
45
46 public function testWithdrawal(): void
47 {
48 $container = $this->mockTree(Container::class, ['ctrl' => $this->mock(ilCtrl::class)]);
49 $container->expects(self::once())->method('offsetGet')->with('ilAuthSession')->willReturn($this->mock(ilAuthSession::class));
50
51 $instance = new Provide('foo', $this->mockMethod(Internal::class, 'get', ['withdraw'], 'foo'), $container);
52
53 $this->assertInstanceOf(ProvideWithdrawal::class, $instance->withdrawal());
54 }
55
56 public function testPublicPage(): void
57 {
58 $container = $this->mockTree(Container::class, ['ctrl' => $this->mock(ilCtrl::class)]);
59
60 $this->assertInstanceOf(ProvidePublicPage::class, (new Provide('foo', $this->mockMethod(
61 Internal::class,
62 'get',
63 ['public-page', 'foo'],
64 true
65 ), $container))->publicPage());
66 }
67
68 public function testDocument(): void
69 {
70 $document = $this->mock(ProvideDocument::class);
71 $internal = $this->mockMethod(Internal::class, 'get', ['document', 'foo'], $document);
72
73 $instance = new Provide('foo', $internal, $this->mock(Container::class));
74 $this->assertSame($document, $instance->document());
75 }
76
77 public function testHistory(): void
78 {
79 $history = $this->mock(ProvideHistory::class);
80 $internal = $this->mockMethod(Internal::class, 'get', ['history', 'foo'], $history);
81
82 $instance = new Provide('foo', $internal, $this->mock(Container::class));
83 $this->assertSame($history, $instance->history());
84 }
85
86 public function testAllowEditing(): void
87 {
88 $document = $this->mock(ProvideDocument::class);
89
90 $internal = $this->mock(Internal::class);
91 $consecutive = [
92 ['document', 'foo'],
93 ['writable-document', 'foo']
94 ];
95 $internal
96 ->expects(self::exactly(2))
97 ->method('get')
98 ->willReturnCallback(
99 function ($a, $b) use (&$consecutive, $document) {
100 [$ea, $eb] = array_shift($consecutive);
101 $this->assertEquals($ea, $a);
102 $this->assertEquals($eb, $b);
103 return $document;
104 }
105 );
106
107 $instance = new Provide('foo', $internal, $this->mock(Container::class));
108 $instance->document();
109 $instance->allowEditing()->document();
110 }
111
112 public function testPublicApi(): void
113 {
114 $public_api = $this->mock(PublicApi::class);
115 $internal = $this->mockMethod(Internal::class, 'get', ['public-api', 'foo'], $public_api);
116
117 $instance = new Provide('foo', $internal, $this->mock(Container::class));
118
119 $this->assertSame($public_api, $instance->publicApi());
120 }
121
122 public function testId(): void
123 {
124 $this->assertSame('foo', (new Provide('foo', $this->mock(Internal::class), $this->mock(Container::class)))->id());
125 }
126}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
Class ilCtrl provides processing control methods.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
$container
@noRector
Definition: wac.php:37