|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ApplicationTest\Repository; |
|
6
|
|
|
|
|
7
|
|
|
use Application\Model\Card; |
|
8
|
|
|
use Application\Model\Collection; |
|
9
|
|
|
use Application\Repository\CollectionRepository; |
|
10
|
|
|
use ApplicationTest\Repository\Traits\LimitedAccessSubQuery; |
|
11
|
|
|
|
|
12
|
|
|
class CollectionRepositoryTest extends AbstractRepositoryTest |
|
13
|
|
|
{ |
|
14
|
|
|
use LimitedAccessSubQuery; |
|
15
|
|
|
|
|
16
|
|
|
private CollectionRepository $repository; |
|
17
|
|
|
|
|
18
|
|
|
protected function setUp(): void |
|
19
|
|
|
{ |
|
20
|
|
|
parent::setUp(); |
|
21
|
|
|
$this->repository = _em()->getRepository(Collection::class); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function providerGetAccessibleSubQuery(): iterable |
|
25
|
|
|
{ |
|
26
|
|
|
yield ['anonymous', []]; |
|
27
|
|
|
yield ['student', [2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008]]; |
|
28
|
|
|
yield ['junior', [2001, 2002, 2004, 2005, 2007]]; |
|
29
|
|
|
yield ['senior', [2001, 2002, 2004, 2005, 2007]]; |
|
30
|
|
|
yield ['administrator', [2001, 2002, 2004, 2005, 2007]]; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @dataProvider providerGetCopyrights |
|
35
|
|
|
*/ |
|
36
|
|
|
public function testGetCopyrights(int $input, string $expected): void |
|
37
|
|
|
{ |
|
38
|
|
|
$card = $this->createMock(Card::class); |
|
39
|
|
|
$card->expects(self::once())->method('getId')->willReturn($input); |
|
40
|
|
|
|
|
41
|
|
|
$actual = $this->repository->getCopyrights($card); |
|
42
|
|
|
self::assertSame($expected, $actual); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function providerGetCopyrights(): iterable |
|
46
|
|
|
{ |
|
47
|
|
|
yield [6000, '© ACME (Only if you ask nicely)']; |
|
48
|
|
|
yield [6001, '']; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testGetSelfAndDescendantsSubQuery(): void |
|
52
|
|
|
{ |
|
53
|
|
|
$expected = [ |
|
54
|
|
|
['id' => 2000], |
|
55
|
|
|
['id' => 2006], |
|
56
|
|
|
]; |
|
57
|
|
|
|
|
58
|
|
|
$sql = $this->repository->getSelfAndDescendantsSubQuery(2000); |
|
59
|
|
|
$actual = _em()->getConnection()->fetchAllAssociative($sql); |
|
60
|
|
|
self::assertSame($expected, $actual); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|