1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the eZ Publish Kernel package. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Bundle\EzPublishCoreBundle\Tests\Imagine; |
10
|
|
|
|
11
|
|
|
use eZ\Bundle\EzPublishCoreBundle\Imagine\PlaceholderProvider; |
12
|
|
|
use eZ\Bundle\EzPublishCoreBundle\Imagine\PlaceholderProviderRegistry; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
|
15
|
|
|
class PlaceholderProviderRegistryTest extends TestCase |
16
|
|
|
{ |
17
|
|
View Code Duplication |
public function testConstructor() |
18
|
|
|
{ |
19
|
|
|
$providers = [ |
20
|
|
|
'foo' => $this->getPlaceholderProviderMock(), |
21
|
|
|
'bar' => $this->getPlaceholderProviderMock(), |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
$registry = new PlaceholderProviderRegistry($providers); |
25
|
|
|
|
26
|
|
|
$this->assertAttributeSame($providers, 'providers', $registry); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
View Code Duplication |
public function testAddProvider() |
30
|
|
|
{ |
31
|
|
|
$provider = $this->getPlaceholderProviderMock(); |
32
|
|
|
|
33
|
|
|
$registry = new PlaceholderProviderRegistry(); |
34
|
|
|
$registry->addProvider('foo', $provider); |
35
|
|
|
|
36
|
|
|
$this->assertAttributeSame(['foo' => $provider], 'providers', $registry); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testSupports() |
40
|
|
|
{ |
41
|
|
|
$registry = new PlaceholderProviderRegistry([ |
42
|
|
|
'supported' => $this->getPlaceholderProviderMock(), |
43
|
|
|
]); |
44
|
|
|
|
45
|
|
|
$this->assertTrue($registry->supports('supported')); |
46
|
|
|
$this->assertFalse($registry->supports('unsupported')); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testGetProviderKnown() |
50
|
|
|
{ |
51
|
|
|
$provider = $this->getPlaceholderProviderMock(); |
52
|
|
|
|
53
|
|
|
$registry = new PlaceholderProviderRegistry([ |
54
|
|
|
'foo' => $provider, |
55
|
|
|
]); |
56
|
|
|
|
57
|
|
|
$this->assertEquals($provider, $registry->getProvider('foo')); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @expectedException \InvalidArgumentException |
62
|
|
|
*/ |
63
|
|
|
public function testGetProviderUnknown() |
64
|
|
|
{ |
65
|
|
|
$registry = new PlaceholderProviderRegistry([ |
66
|
|
|
'foo' => $this->getPlaceholderProviderMock(), |
67
|
|
|
]); |
68
|
|
|
|
69
|
|
|
$registry->getProvider('bar'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
private function getPlaceholderProviderMock(): PlaceholderProvider |
73
|
|
|
{ |
74
|
|
|
return $this->createMock(PlaceholderProvider::class); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|