ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ResourceDBRepositoryTest.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
21
24use PHPUnit\Framework\Attributes\DataProvider;
25use PHPUnit\Framework\TestCase;
26
30final class ResourceDBRepositoryTest extends TestCase
31{
32 #[DataProvider('confidentialProvider')]
33 public function testStoreWritesConfidentialFlag(bool $confidential): void
34 {
35 $resource = new StorableFileResource(new ResourceIdentification('rid'));
36 $resource->setStorageID('fsv2');
37 $resource->setConfidential($confidential);
38
39 $db = $this->createMock(\ilDBInterface::class);
40 $db->expects($this->once())
41 ->method('replace')
42 ->with(
43 'il_resource',
44 ['rid' => ['text', 'rid']],
45 [
46 'storage_id' => ['text', 'fsv2'],
47 'rtype' => ['integer', 1],
48 'confidential' => ['integer', (int) $confidential],
49 ]
50 );
51
52 (new ResourceDBRepository($db))->store($resource);
53 }
54
55 #[DataProvider('confidentialProvider')]
56 public function testGetReadsConfidentialFlag(bool $confidential): void
57 {
58 $db = $this->createStub(\ilDBInterface::class);
59 $db->method('queryF')->willReturn($this->createStub(\ilDBStatement::class));
60 $db->method('fetchObject')->willReturn((object) [
61 'storage_id' => 'fsv2',
62 'rtype' => '1',
63 'confidential' => $confidential ? '1' : '0',
64 ]);
65
66 $resource = (new ResourceDBRepository($db))->get(new ResourceIdentification('rid'));
67
68 $this->assertSame($confidential, $resource->isConfidential());
69 }
70
71 #[DataProvider('confidentialProvider')]
72 public function testPopulateFromArrayReadsConfidentialFlag(bool $confidential): void
73 {
74 $db = $this->createMock(\ilDBInterface::class);
75 $db->expects($this->never())->method('queryF');
76
77 $repository = new ResourceDBRepository($db);
78 $repository->populateFromArray([
79 'rid' => 'rid',
80 'storage_id' => 'fsv2',
81 'rtype' => '1',
82 'confidential' => $confidential ? '1' : '0',
83 ]);
84
85 $this->assertSame($confidential, $repository->get(new ResourceIdentification('rid'))->isConfidential());
86 }
87
89 {
90 $repository = new ResourceDBRepository($this->createStub(\ilDBInterface::class));
91 $repository->populateFromArray([
92 'rid' => 'rid',
93 'storage_id' => 'fsv2',
94 'rtype' => '1',
95 ]);
96
97 $this->assertFalse($repository->get(new ResourceIdentification('rid'))->isConfidential());
98 }
99
100 public static function confidentialProvider(): \Iterator
101 {
102 yield 'confidential' => [true];
103 yield 'not confidential' => [false];
104 }
105}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...