ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ProvideHistoryTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
36 use ilObjUser;
38 use ilLanguage;
39 use stdClass;
40 use ilCtrl;
41 
42 require_once __DIR__ . '/../ContainerMock.php';
43 
44 class 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::class);
57 
58  $table = $this->mockMethod(LegacyTable::class, 'getHTML', [], 'table html');
59 
60  $container = $this->mockTree(Container::class, [
61  'ctrl' => $this->mock(ilCtrl::class),
62  'language' => $this->mock(ilLanguage::class),
63  'ui' => [
64  'factory' => $this->mockMethod(UIFactory::class, 'legacy', ['table html'], $legacy),
65  'mainTemplate' => $this->mock(ilGlobalTemplateInterface::class)
66  ],
67  ]);
68 
69  $create_table_gui = function (object $gui, string $command, TableInterface $t) use ($dummy_gui, $table): LegacyTable {
70  $this->assertSame($dummy_gui, $gui);
71  $this->assertSame('dummy command', $command);
72  $this->assertInstanceOf(HistoryTable::class, $t);
73  return $table;
74  };
75 
76  $instance = new ProvideHistory('foo', $this->mock(HistoryRepository::class), $this->mock(ProvideDocument::class), $container, $create_table_gui);
77 
78  $this->assertSame($legacy, $instance->table($dummy_gui, 'dummy command', 'reset command', 'auto complete command'));
79  }
80 
81  public function testAcceptDocument(): void
82  {
83  $user = $this->mock(ilObjUser::class);
84  $document = $this->mock(Document::class);
85 
86  $repository = $this->mock(HistoryRepository::class);
87  $repository->expects(self::once())->method('acceptDocument')->with($user, $document);
88 
89  $instance = new ProvideHistory('foo', $repository, $this->mock(ProvideDocument::class), $this->mock(Container::class));
90  $instance->acceptDocument($user, $document);
91  }
92 
93  public function testAlreadyAccepted(): void
94  {
95  $user = $this->mock(ilObjUser::class);
96  $document = $this->mock(Document::class);
97 
98  $repository = $this->mockMethod(HistoryRepository::class, 'alreadyAccepted', [$user, $document], true);
99 
100  $instance = new ProvideHistory('foo', $repository, $this->mock(ProvideDocument::class), $this->mock(Container::class));
101  $this->assertTrue($instance->alreadyAccepted($user, $document));
102  }
103 
104  public function testAcceptedVersion(): void
105  {
106  $user = $this->mock(ilObjUser::class);
107 
108  $result = $this->mock(Result::class);
109 
110  $repository = $this->mockMethod(HistoryRepository::class, 'acceptedVersion', [$user], $result);
111 
112  $instance = new ProvideHistory('foo', $repository, $this->mock(ProvideDocument::class), $this->mock(Container::class));
113  $this->assertSame($result, $instance->acceptedVersion($user));
114  }
115 
116  public function testCurrentDocumentOfAcceptedVersion(): void
117  {
118  $user = $this->mock(ilObjUser::class);
119  $result = $this->mock(Result::class);
120  $repository = $this->mockMethod(HistoryRepository::class, 'currentDocumentOfAcceptedVersion', [$user], $result);
121  $instance = new ProvideHistory('foo', $repository, $this->mock(ProvideDocument::class), $this->mock(Container::class));
122 
123  $this->assertSame($result, $instance->currentDocumentOfAcceptedVersion($user));
124  }
125 }
$container
Definition: wac.php:14