ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ProvideHistoryTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use ILIAS\LegalDocuments\Legacy\Table as LegacyTable;
28use ILIAS\UI\Factory as UIFactory;
31use ILIAS\LegalDocuments\test\ContainerMock;
34use PHPUnit\Framework\TestCase;
36use ilObjUser;
38use ilLanguage;
39use stdClass;
40use ilCtrl;
41
42require_once __DIR__ . '/../ContainerMock.php';
43
44class ProvideHistoryTest extends TestCase
45{
46 use ContainerMock;
47
48 public function testConstruct(): void
49 {
50 $this->assertInstanceOf(ProvideHistory::class, new ProvideHistory('foo', $this->mock(HistoryRepository::class), $this->mock(ProvideDocument::class), $this->mock(Container::class)));
51 }
52
53 public function testTable(): void
54 {
55 $dummy_gui = new stdClass();
56 $legacy = $this->mock(Legacy\Content::class);
57 $legacy_factory = $this->mock(Legacy\Factory::class);
58 $legacy_factory
59 ->expects($this->once())
60 ->method('content')
61 ->willReturn($legacy);
62
63 $table = $this->mockMethod(LegacyTable::class, 'getHTML', [], 'table html');
64
65 $container = $this->mockTree(Container::class, [
66 'ctrl' => $this->mock(ilCtrl::class),
67 'language' => $this->mock(ilLanguage::class),
68 'ui' => [
69 'factory' => $this->mockMethod(UIFactory::class, 'legacy', [], $legacy_factory),
70 'mainTemplate' => $this->mock(ilGlobalTemplateInterface::class)
71 ],
72 ]);
73
74 $create_table_gui = function (object $gui, string $command, TableInterface $t) use ($dummy_gui, $table): LegacyTable {
75 $this->assertSame($dummy_gui, $gui);
76 $this->assertSame('dummy command', $command);
77 $this->assertInstanceOf(HistoryTable::class, $t);
78 return $table;
79 };
80
81 $instance = new ProvideHistory('foo', $this->mock(HistoryRepository::class), $this->mock(ProvideDocument::class), $container, $create_table_gui);
82
83 $this->assertSame($legacy, $instance->table($dummy_gui, 'dummy command', 'reset command', 'auto complete command'));
84 }
85
86 public function testAcceptDocument(): void
87 {
88 $user = $this->mock(ilObjUser::class);
89 $document = $this->mock(Document::class);
90
91 $repository = $this->mock(HistoryRepository::class);
92 $repository->expects(self::once())->method('acceptDocument')->with($user, $document);
93
94 $instance = new ProvideHistory('foo', $repository, $this->mock(ProvideDocument::class), $this->mock(Container::class));
95 $instance->acceptDocument($user, $document);
96 }
97
98 public function testAlreadyAccepted(): void
99 {
100 $user = $this->mock(ilObjUser::class);
101 $document = $this->mock(Document::class);
102
103 $repository = $this->mockMethod(HistoryRepository::class, 'alreadyAccepted', [$user, $document], true);
104
105 $instance = new ProvideHistory('foo', $repository, $this->mock(ProvideDocument::class), $this->mock(Container::class));
106 $this->assertTrue($instance->alreadyAccepted($user, $document));
107 }
108
109 public function testAcceptedVersion(): void
110 {
111 $user = $this->mock(ilObjUser::class);
112
113 $result = $this->mock(Result::class);
114
115 $repository = $this->mockMethod(HistoryRepository::class, 'acceptedVersion', [$user], $result);
116
117 $instance = new ProvideHistory('foo', $repository, $this->mock(ProvideDocument::class), $this->mock(Container::class));
118 $this->assertSame($result, $instance->acceptedVersion($user));
119 }
120
122 {
123 $user = $this->mock(ilObjUser::class);
124 $result = $this->mock(Result::class);
125 $repository = $this->mockMethod(HistoryRepository::class, 'currentDocumentOfAcceptedVersion', [$user], $result);
126 $instance = new ProvideHistory('foo', $repository, $this->mock(ProvideDocument::class), $this->mock(Container::class));
127
128 $this->assertSame($result, $instance->currentDocumentOfAcceptedVersion($user));
129 }
130}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Class ilCtrl provides processing control methods.
language handling
User class.
$container
@noRector
Definition: wac.php:37