ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
ILIAS\ResourceStorage\Resource\CollectionRepositoryTest Class Reference

Class CollectionTest. More...

+ Inheritance diagram for ILIAS\ResourceStorage\Resource\CollectionRepositoryTest:
+ Collaboration diagram for ILIAS\ResourceStorage\Resource\CollectionRepositoryTest:

Public Member Functions

 testStore ()
 

Protected Member Functions

 setUp ()
 

Private Attributes

const string TEST_RCID = 'test_rcid'
 
MockObject $db_mock
 
CollectionDBRepository $repo
 
DummyIDGenerator $rcid_generator
 

Detailed Description

Member Function Documentation

◆ setUp()

ILIAS\ResourceStorage\Resource\CollectionRepositoryTest::setUp ( )
protected

Definition at line 43 of file CollectionRepositoryTest.php.

43  : 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  }

◆ testStore()

ILIAS\ResourceStorage\Resource\CollectionRepositoryTest::testStore ( )

Definition at line 50 of file CollectionRepositoryTest.php.

50  : 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  }

Field Documentation

◆ $db_mock

MockObject ILIAS\ResourceStorage\Resource\CollectionRepositoryTest::$db_mock
private

Definition at line 39 of file CollectionRepositoryTest.php.

◆ $rcid_generator

DummyIDGenerator ILIAS\ResourceStorage\Resource\CollectionRepositoryTest::$rcid_generator
private

Definition at line 41 of file CollectionRepositoryTest.php.

◆ $repo

CollectionDBRepository ILIAS\ResourceStorage\Resource\CollectionRepositoryTest::$repo
private

Definition at line 40 of file CollectionRepositoryTest.php.

◆ TEST_RCID

const string ILIAS\ResourceStorage\Resource\CollectionRepositoryTest::TEST_RCID = 'test_rcid'
private

Definition at line 38 of file CollectionRepositoryTest.php.


The documentation for this class was generated from the following file: