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