1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace eZ\Bundle\EzPublishCoreBundle\Tests\SiteAccess; |
10
|
|
|
|
11
|
|
|
use eZ\Bundle\EzPublishCoreBundle\SiteAccess\Matcher; |
12
|
|
|
use eZ\Bundle\EzPublishCoreBundle\SiteAccess\SiteAccessMatcherRegistry; |
13
|
|
|
use eZ\Publish\API\Repository\Exceptions\NotFoundException; |
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
|
16
|
|
|
class SiteAccessMatcherRegistryTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
private const MATCHER_NAME = 'test_matcher'; |
19
|
|
|
|
20
|
|
|
public function testGetMatcher(): void |
21
|
|
|
{ |
22
|
|
|
$matcher = $this->getMatcherMock(); |
23
|
|
|
$registry = new SiteAccessMatcherRegistry([self::MATCHER_NAME => $matcher]); |
24
|
|
|
|
25
|
|
|
$this->assertSame($matcher, $registry->getMatcher(self::MATCHER_NAME)); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testSetMatcher(): void |
29
|
|
|
{ |
30
|
|
|
$matcher = $this->getMatcherMock(); |
31
|
|
|
$registry = new SiteAccessMatcherRegistry(); |
32
|
|
|
|
33
|
|
|
$registry->setMatcher(self::MATCHER_NAME, $matcher); |
34
|
|
|
|
35
|
|
|
$this->assertSame($matcher, $registry->getMatcher(self::MATCHER_NAME)); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testSetMatcherOverride(): void |
39
|
|
|
{ |
40
|
|
|
$matcher = $this->getMatcherMock(); |
41
|
|
|
$newMatcher = $this->getMatcherMock(); |
42
|
|
|
$registry = new SiteAccessMatcherRegistry([self::MATCHER_NAME, $matcher]); |
43
|
|
|
|
44
|
|
|
$registry->setMatcher(self::MATCHER_NAME, $newMatcher); |
45
|
|
|
|
46
|
|
|
$this->assertSame($newMatcher, $registry->getMatcher(self::MATCHER_NAME)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testGetMatcherNotFound(): void |
50
|
|
|
{ |
51
|
|
|
$this->expectException(NotFoundException::class); |
52
|
|
|
$registry = new SiteAccessMatcherRegistry(); |
53
|
|
|
|
54
|
|
|
$registry->getMatcher(self::MATCHER_NAME); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function getMatcherMock(): Matcher |
58
|
|
|
{ |
59
|
|
|
return $this->createMock(Matcher::class); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|