ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
CollectionRepositoryTest.php
Go to the documentation of this file.
1<?php
2
20
21use PHPUnit\Framework\MockObject\MockObject;
22
23require_once(__DIR__ . '/../DummyIDGenerator.php');
24
25use PHPUnit\Framework\TestCase;
31
36class CollectionRepositoryTest extends TestCase
37{
38 private const string TEST_RCID = 'test_rcid';
39 private MockObject $db_mock;
42
43 protected function setUp(): void
44 {
45 $this->db_mock = $this->createMock(\ilDBInterface::class);
46 $this->repo = new CollectionDBRepository($this->db_mock);
47 $this->rcid_generator = new DummyIDGenerator(self::TEST_RCID);
48 }
49
50 public function testStore(): void
51 {
52 $collection = $this->repo->blank($this->rcid_generator->getUniqueResourceCollectionIdentification());
53 $this->assertSame(0, $collection->count());
54
55 $rid_one = 'rid_one';
56 $collection->add(new ResourceIdentification($rid_one));
57 $rid_two = 'rid_two';
58 $collection->add(new ResourceIdentification($rid_two));
59
60 $rids_given = [$rid_one, $rid_two];
61 $this->db_mock->expects($this->once())
62 ->method('in')
63 ->with('rid', $rids_given, true, 'text')
64 ->willReturn('rid NOT IN("rid_one", "rid_one")');
65
66 $this->db_mock->expects($this->once())
67 ->method('manipulateF')
68 ->with('DELETE FROM il_resource_rca WHERE rcid = %s AND rid NOT IN("rid_one", "rid_one")');
69
70 $this->db_mock->expects($this->once())
71 ->method('manipulateF')
72 ->with('DELETE FROM il_resource_rca WHERE rcid = %s AND rid NOT IN("rid_one", "rid_one")');
73
74 $called_table_names = [
75 'il_resource_rca',
76 'il_resource_rca',
77 'il_resource_rc',
78 ];
79
80 $this->db_mock->expects($this->exactly(3))
81 ->method('insert')
82 ->willReturnCallback(
83 function ($table_name) use (&$called_table_names): int {
84 $expected_table_name = array_shift($called_table_names);
85 TestCase::assertSame($expected_table_name, $table_name);
86 return 1;
87 }
88 );
89
90 $event_data_container = new DataContainer();
91 $this->repo->update($collection, $event_data_container);
92 $this->assertCount(2, $event_data_container->get());
93 foreach ($event_data_container->get() as $event_data) {
94 $this->assertInstanceOf(CollectionData::class, $event_data);
95 $this->assertContains($event_data->getRid(), $rids_given);
96 $this->assertSame(self::TEST_RCID, $event_data->getRcid());
97 }
98 }
99
100}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...