|
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 JMS\DiExtraBundle\Metadata\ClassMetadata; |
|
17
|
|
|
use PHPUnit\Framework\TestCase; |
|
18
|
|
|
use Sonata\AdminBundle\Annotation\Admin; |
|
19
|
|
|
|
|
20
|
|
|
class AnnotationCompilerPassTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @group legacy |
|
24
|
|
|
* |
|
25
|
|
|
* @expectedDeprecation The Sonata\AdminBundle\Annotation\Admin class is deprecated since sonata-project/admin-bundle 3.46 and will be removed in 4.0. Use autoconfiguration instead, see https://github.com/kunicmarko20/SonataAutoConfigureBundle. |
|
26
|
|
|
*/ |
|
27
|
|
|
public function testInvalidAdminAnnotation(): void |
|
28
|
|
|
{ |
|
29
|
|
|
/* |
|
30
|
|
|
* @Admin(class="Sonata\AdminBundle\Tests\Fixtures\Foo") |
|
31
|
|
|
*/ |
|
32
|
|
|
|
|
33
|
|
|
$this->expectException(\LogicException::class); |
|
34
|
|
|
$this->expectExceptionMessage( |
|
35
|
|
|
'Unable to generate admin group and label for class Sonata\AdminBundle\Tests\Fixtures\Foo.' |
|
36
|
|
|
); |
|
37
|
|
|
|
|
38
|
|
|
$annotation = new Admin(); |
|
|
|
|
|
|
39
|
|
|
$annotation->class = \Sonata\AdminBundle\Tests\Fixtures\Foo::class; |
|
40
|
|
|
|
|
41
|
|
|
$meta = new ClassMetadata(\Sonata\AdminBundle\Tests\Fixtures\Entity\Foo::class); |
|
42
|
|
|
|
|
43
|
|
|
$annotation->processMetadata($meta); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testEmbeddedAdmin(): void |
|
47
|
|
|
{ |
|
48
|
|
|
/* |
|
49
|
|
|
* @Admin( |
|
50
|
|
|
* class="Sonata\Admin\Entity\Tests\Fixtures\Foo", |
|
51
|
|
|
* showInDashboard=false |
|
52
|
|
|
* ) |
|
53
|
|
|
*/ |
|
54
|
|
|
$annotation = new Admin(); |
|
|
|
|
|
|
55
|
|
|
$annotation->class = \Sonata\Admin\Entity\Tests\Fixtures\Foo::class; |
|
56
|
|
|
$annotation->showInDashboard = false; |
|
57
|
|
|
|
|
58
|
|
|
$meta = new ClassMetadata(\Sonata\AdminBundle\Tests\Fixtures\Entity\Foo::class); |
|
59
|
|
|
|
|
60
|
|
|
$annotation->processMetadata($meta); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertSame( |
|
63
|
|
|
[ |
|
64
|
|
|
'manager_type' => 'orm', |
|
65
|
|
|
'group' => 'Admin', |
|
66
|
|
|
'label' => 'Tests\Fixtures\Foo', |
|
67
|
|
|
'show_in_dashboard' => false, |
|
68
|
|
|
'keep_open' => false, |
|
69
|
|
|
'on_top' => false, |
|
70
|
|
|
], |
|
71
|
|
|
$meta->tags['sonata.admin'][0] |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function testMinimalAdmin(): void |
|
76
|
|
|
{ |
|
77
|
|
|
/* |
|
78
|
|
|
* @Admin(class="Sonata\AdminBundle\Entity\Foo") |
|
79
|
|
|
*/ |
|
80
|
|
|
$annotation = new Admin(); |
|
|
|
|
|
|
81
|
|
|
$annotation->class = \Sonata\AdminBundle\Entity\Foo::class; |
|
82
|
|
|
|
|
83
|
|
|
$meta = new ClassMetadata(\Sonata\AdminBundle\Tests\Fixtures\Entity\Foo::class); |
|
84
|
|
|
|
|
85
|
|
|
$annotation->processMetadata($meta); |
|
86
|
|
|
|
|
87
|
|
|
$this->assertSame( |
|
88
|
|
|
[ |
|
89
|
|
|
'manager_type' => 'orm', |
|
90
|
|
|
'group' => 'Admin', |
|
91
|
|
|
'label' => 'Foo', |
|
92
|
|
|
'show_in_dashboard' => true, |
|
93
|
|
|
'keep_open' => false, |
|
94
|
|
|
'on_top' => false, |
|
95
|
|
|
], |
|
96
|
|
|
$meta->tags['sonata.admin'][0] |
|
97
|
|
|
); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function testIdForAdmin(): void |
|
101
|
|
|
{ |
|
102
|
|
|
/* |
|
103
|
|
|
* @Admin(class="Sonata\AdminBundle\Entity\Foo", id="my.id") |
|
104
|
|
|
*/ |
|
105
|
|
|
$annotation = new Admin(); |
|
|
|
|
|
|
106
|
|
|
$annotation->class = \Sonata\AdminBundle\Entity\Foo::class; |
|
107
|
|
|
$annotation->id = 'my.id'; |
|
108
|
|
|
|
|
109
|
|
|
$meta = new ClassMetadata(\Sonata\AdminBundle\Tests\Fixtures\Entity\Foo::class); |
|
110
|
|
|
|
|
111
|
|
|
$annotation->processMetadata($meta); |
|
112
|
|
|
|
|
113
|
|
|
$this->assertSame('my.id', $meta->id); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function testAdmin(): void |
|
117
|
|
|
{ |
|
118
|
|
|
/* |
|
119
|
|
|
* @Admin( |
|
120
|
|
|
* class="Sonata\AdminBundle\Entity\Foo", |
|
121
|
|
|
* managerType="doctrine_mongodb", |
|
122
|
|
|
* group="myGroup", |
|
123
|
|
|
* label="myLabel", |
|
124
|
|
|
* translationDomain="OMG", |
|
125
|
|
|
* keepOpen=true, |
|
126
|
|
|
* onTop=true |
|
127
|
|
|
* ) |
|
128
|
|
|
*/ |
|
129
|
|
|
$annotation = new Admin(); |
|
|
|
|
|
|
130
|
|
|
$annotation->class = \Sonata\AdminBundle\Entity\Foo::class; |
|
131
|
|
|
$annotation->managerType = 'doctrine_mongodb'; |
|
132
|
|
|
$annotation->group = 'myGroup'; |
|
133
|
|
|
$annotation->label = 'myLabel'; |
|
134
|
|
|
$annotation->showInDashboard = false; |
|
135
|
|
|
$annotation->translationDomain = 'OMG'; |
|
136
|
|
|
$annotation->keepOpen = true; |
|
137
|
|
|
$annotation->onTop = true; |
|
138
|
|
|
|
|
139
|
|
|
$meta = new ClassMetadata(\Sonata\AdminBundle\Tests\Fixtures\Entity\Foo::class); |
|
140
|
|
|
|
|
141
|
|
|
$annotation->processMetadata($meta); |
|
142
|
|
|
|
|
143
|
|
|
$this->assertSame( |
|
144
|
|
|
[ |
|
145
|
|
|
'manager_type' => 'doctrine_mongodb', |
|
146
|
|
|
'group' => 'myGroup', |
|
147
|
|
|
'label' => 'myLabel', |
|
148
|
|
|
'show_in_dashboard' => false, |
|
149
|
|
|
'keep_open' => true, |
|
150
|
|
|
'on_top' => true, |
|
151
|
|
|
], |
|
152
|
|
|
$meta->tags['sonata.admin'][0] |
|
153
|
|
|
); |
|
154
|
|
|
|
|
155
|
|
|
$this->assertSame(['setTranslationDomain', ['OMG']], $meta->methodCalls[0]); |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.