-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
AdminTest.php
98 lines (77 loc) · 2.98 KB
/
AdminTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\ClassificationBundle\Tests\Admin;
use PHPUnit\Framework\TestCase;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Admin\AdminExtensionInterface;
use Sonata\ClassificationBundle\Admin\ContextAdmin;
use Sonata\ClassificationBundle\Admin\ContextAwareAdmin;
use Sonata\ClassificationBundle\Model\ContextManagerInterface;
class AdminTest extends TestCase
{
/**
* @var ContextManagerInterface
*/
private $contextManager;
protected function setUp(): void
{
$this->contextManager = $this->createMock(ContextManagerInterface::class);
}
public function testAbstractAdminChildren(): void
{
$contextAwareAdmin = $this->createMock(ContextAwareAdmin::class);
$this->assertInstanceOf(AbstractAdmin::class, $contextAwareAdmin);
$contextAdmin = $this->createMock(ContextAdmin::class);
$this->assertInstanceOf(AbstractAdmin::class, $contextAdmin);
}
public function testGetPersistentParametersWithNoExtension(): void
{
$expected = [
'context' => '',
'hide_context' => 0,
];
$admin = $this->getMockForAbstractClass(ContextAwareAdmin::class, [
'admin.my_code', 'My\Class', 'MyBundle:ClassAdmin', $this->contextManager,
]);
$this->assertSame($expected, $admin->getPersistentParameters());
}
public function testGetPersistentParametersWithInvalidExtension(): void
{
$this->expectException(\RuntimeException::class);
$admin = $this->getMockForAbstractClass(ContextAwareAdmin::class, [
'admin.my_code', 'My\Class', 'MyBundle:ClassAdmin', $this->contextManager,
]);
$extension = $this->createMock(AdminExtensionInterface::class);
$extension->expects($this->once())->method('getPersistentParameters')->willReturn(null);
$admin->addExtension($extension);
$admin->getPersistentParameters();
}
public function testGetPersistentParametersWithValidExtension(): void
{
$expected = [
'tl' => 'de',
'abc' => 123,
'context' => '',
'hide_context' => 0,
];
$extensionParams = [
'tl' => 'de',
'abc' => 123,
];
$admin = $this->getMockForAbstractClass(ContextAwareAdmin::class, [
'admin.my_code', 'My\Class', 'MyBundle:ClassAdmin', $this->contextManager,
]);
$extension = $this->createMock(AdminExtensionInterface::class);
$extension->expects($this->once())->method('getPersistentParameters')->willReturn($extensionParams);
$admin->addExtension($extension);
$this->assertSame($expected, $admin->getPersistentParameters());
}
}