ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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;
40 
41  protected function setUp(): void
42  {
43  $this->db_mock = $this->createMock(\ilDBInterface::class);
44  $this->repo = new CollectionDBRepository($this->db_mock);
45  $this->rcid_generator = new DummyIDGenerator(self::TEST_RCID);
46  }
47 
48  public function testStore(): void
49  {
50  $collection = $this->repo->blank($this->rcid_generator->getUniqueResourceCollectionIdentification());
51  $this->assertEquals(0, $collection->count());
52 
53  $rid_one = 'rid_one';
54  $collection->add(new ResourceIdentification($rid_one));
55  $rid_two = 'rid_two';
56  $collection->add(new ResourceIdentification($rid_two));
57 
58  $rids_given = [$rid_one, $rid_two];
59  $this->db_mock->expects($this->once())
60  ->method('in')
61  ->with('rid', $rids_given, true, 'text')
62  ->willReturn('rid NOT IN("rid_one", "rid_one")');
63 
64  $this->db_mock->expects($this->once())
65  ->method('manipulateF')
66  ->with('DELETE FROM il_resource_rca WHERE rcid = %s AND rid NOT IN("rid_one", "rid_one")');
67 
68  $this->db_mock->expects($this->once())
69  ->method('manipulateF')
70  ->with('DELETE FROM il_resource_rca WHERE rcid = %s AND rid NOT IN("rid_one", "rid_one")');
71 
72  $this->db_mock->expects($this->exactly(3))
73  ->method('insert')
74  ->will(
75  $this->onConsecutiveCalls(
76  $this->returnCallback(function ($table, $fields) {
77  $this->assertEquals('il_resource_rca', $table);
78  return 1;
79  }),
80  $this->returnCallback(function ($table, $fields) {
81  $this->assertEquals('il_resource_rca', $table);
82  return 1;
83  }),
84  $this->returnCallback(function ($table, $fields) {
85  $this->assertEquals('il_resource_rc', $table);
86  return 1;
87  })
88  )
89  );
90 
91  $event_data_container = new DataContainer();
92  $this->repo->update($collection, $event_data_container);
93 
94  $rids = [];
95  $this->assertCount(2, $event_data_container->get());
96  foreach ($event_data_container->get() as $event_data) {
97  $this->assertInstanceOf(CollectionData::class, $event_data);
98  $this->assertContains($event_data->getRid(), $rids_given);
99  $this->assertEquals(self::TEST_RCID, $event_data->getRcid());
100  }
101  }
102 
103 }
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...