1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\AdminBundle\Tests\DependencyInjection\Compiler; |
15
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
17
|
|
|
use Sonata\AdminBundle\Admin\Pool; |
18
|
|
|
use Sonata\AdminBundle\Command\GenerateObjectAclCommand; |
19
|
|
|
use Sonata\AdminBundle\DependencyInjection\Compiler\ObjectAclManipulatorCompilerPass; |
20
|
|
|
use Sonata\AdminBundle\Util\ObjectAclManipulator; |
21
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @author Olivier Rey <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class ObjectAclManipulatorCompilerPassTest extends TestCase |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @dataProvider containerDataProvider |
30
|
|
|
*/ |
31
|
|
|
public function testAvailableManager(ContainerBuilder $containerBuilder, string $serviceId): void |
32
|
|
|
{ |
33
|
|
|
$objectAclManipulatorCompilerPass = new ObjectAclManipulatorCompilerPass(); |
34
|
|
|
|
35
|
|
|
$objectAclManipulatorCompilerPass->process($containerBuilder); |
36
|
|
|
|
37
|
|
|
$availableManagers = $containerBuilder->getDefinition(GenerateObjectAclCommand::class)->getArgument(1); |
38
|
|
|
|
39
|
|
|
$this->assertArrayHasKey($serviceId, $availableManagers); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function containerDataProvider(): iterable |
43
|
|
|
{ |
44
|
|
|
$serviceId = 'sonata.admin.manipulator.acl.object.orm'; |
45
|
|
|
$container = $this->createContainer(); |
46
|
|
|
$container |
47
|
|
|
->register($serviceId) |
48
|
|
|
->setClass(ObjectAclManipulator::class); |
49
|
|
|
|
50
|
|
|
yield [$container, $serviceId]; |
51
|
|
|
|
52
|
|
|
$parameterName = 'sonata.admin.manipulator.acl.object.orm.class'; |
53
|
|
|
$container = $this->createContainer(); |
54
|
|
|
$container->setParameter($parameterName, ObjectAclManipulator::class); |
55
|
|
|
|
56
|
|
|
$container |
57
|
|
|
->register($serviceId) |
58
|
|
|
->setClass('%'.$parameterName.'%'); |
59
|
|
|
|
60
|
|
|
yield [$container, $serviceId]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
private function createContainer(): ContainerBuilder |
64
|
|
|
{ |
65
|
|
|
$pool = $this->createStub(Pool::class); |
66
|
|
|
$container = new ContainerBuilder(); |
67
|
|
|
$container |
68
|
|
|
->register(GenerateObjectAclCommand::class) |
69
|
|
|
->setClass(GenerateObjectAclCommand::class) |
70
|
|
|
->setArguments([$pool, []]); |
71
|
|
|
|
72
|
|
|
return $container; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|