1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata Project package. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sonata\AdminBundle\Tests\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use JMS\DiExtraBundle\Metadata\ClassMetadata; |
15
|
|
|
use Sonata\AdminBundle\Annotation\Admin; |
16
|
|
|
use Sonata\AdminBundle\Tests\Helpers\PHPUnit_Framework_TestCase; |
17
|
|
|
|
18
|
|
|
class AnnotationCompilerPassTest extends PHPUnit_Framework_TestCase |
19
|
|
|
{ |
20
|
|
|
public function testInvalidAdminAnnotation() |
21
|
|
|
{ |
22
|
|
|
/* |
23
|
|
|
* @Admin(class="Sonata\AdminBundle\Tests\Fixtures\Foo") |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
$this->expectException( |
27
|
|
|
'LogicException', |
28
|
|
|
'Unable to generate admin group and label for class Sonata\AdminBundle\Tests\Fixtures\Foo.' |
29
|
|
|
); |
30
|
|
|
|
31
|
|
|
$annotation = new Admin(); |
32
|
|
|
$annotation->class = 'Sonata\AdminBundle\Tests\Fixtures\Foo'; |
33
|
|
|
|
34
|
|
|
$meta = new ClassMetadata('Sonata\AdminBundle\Tests\Fixtures\Entity\Foo'); |
35
|
|
|
|
36
|
|
|
$annotation->processMetadata($meta); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testEmbeddedAdmin() |
40
|
|
|
{ |
41
|
|
|
/* |
42
|
|
|
* @Admin( |
43
|
|
|
* class="Sonata\Admin\Entity\Tests\Fixtures\Foo", |
44
|
|
|
* showInDashboard=false |
45
|
|
|
* ) |
46
|
|
|
*/ |
47
|
|
|
$annotation = new Admin(); |
48
|
|
|
$annotation->class = 'Sonata\Admin\Entity\Tests\Fixtures\Foo'; |
49
|
|
|
$annotation->showInDashboard = false; |
50
|
|
|
|
51
|
|
|
$meta = new ClassMetadata('Sonata\AdminBundle\Tests\Fixtures\Entity\Foo'); |
52
|
|
|
|
53
|
|
|
$annotation->processMetadata($meta); |
54
|
|
|
|
55
|
|
|
$this->assertSame( |
56
|
|
|
array( |
57
|
|
|
'manager_type' => 'orm', |
58
|
|
|
'group' => 'Admin', |
59
|
|
|
'label' => 'Tests\Fixtures\Foo', |
60
|
|
|
'show_in_dashboard' => false, |
61
|
|
|
'keep_open' => false, |
62
|
|
|
'on_top' => false, |
63
|
|
|
), |
64
|
|
|
$meta->tags['sonata.admin'][0] |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testMinimalAdmin() |
69
|
|
|
{ |
70
|
|
|
/* |
71
|
|
|
* @Admin(class="Sonata\AdminBundle\Entity\Foo") |
72
|
|
|
*/ |
73
|
|
|
$annotation = new Admin(); |
74
|
|
|
$annotation->class = 'Sonata\AdminBundle\Entity\Foo'; |
75
|
|
|
|
76
|
|
|
$meta = new ClassMetadata('Sonata\AdminBundle\Tests\Fixtures\Entity\Foo'); |
77
|
|
|
|
78
|
|
|
$annotation->processMetadata($meta); |
79
|
|
|
|
80
|
|
|
$this->assertSame( |
81
|
|
|
array( |
82
|
|
|
'manager_type' => 'orm', |
83
|
|
|
'group' => 'Admin', |
84
|
|
|
'label' => 'Foo', |
85
|
|
|
'show_in_dashboard' => true, |
86
|
|
|
'keep_open' => false, |
87
|
|
|
'on_top' => false, |
88
|
|
|
), |
89
|
|
|
$meta->tags['sonata.admin'][0] |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function testIdForAdmin() |
94
|
|
|
{ |
95
|
|
|
/* |
96
|
|
|
* @Admin(class="Sonata\AdminBundle\Entity\Foo", id="my.id") |
97
|
|
|
*/ |
98
|
|
|
$annotation = new Admin(); |
99
|
|
|
$annotation->class = 'Sonata\AdminBundle\Entity\Foo'; |
100
|
|
|
|
101
|
|
|
$meta = new ClassMetadata('Sonata\AdminBundle\Tests\Fixtures\Entity\Foo'); |
102
|
|
|
$meta->id = 'my.id'; |
103
|
|
|
|
104
|
|
|
$annotation->processMetadata($meta); |
105
|
|
|
|
106
|
|
|
$this->assertSame('my.id', $meta->id); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function testAdmin() |
110
|
|
|
{ |
111
|
|
|
/* |
112
|
|
|
* @Admin( |
113
|
|
|
* class="Sonata\AdminBundle\Entity\Foo", |
114
|
|
|
* managerType="doctrine_mongodb", |
115
|
|
|
* group="myGroup", |
116
|
|
|
* label="myLabel", |
117
|
|
|
* translationDomain="OMG", |
118
|
|
|
* keepOpen=true, |
119
|
|
|
* onTop=true |
120
|
|
|
* ) |
121
|
|
|
*/ |
122
|
|
|
$annotation = new Admin(); |
123
|
|
|
$annotation->class = 'Sonata\AdminBundle\Entity\Foo'; |
124
|
|
|
$annotation->managerType = 'doctrine_mongodb'; |
125
|
|
|
$annotation->group = 'myGroup'; |
126
|
|
|
$annotation->label = 'myLabel'; |
127
|
|
|
$annotation->showInDashboard = false; |
128
|
|
|
$annotation->translationDomain = 'OMG'; |
129
|
|
|
$annotation->keepOpen = true; |
130
|
|
|
$annotation->onTop = true; |
131
|
|
|
|
132
|
|
|
$meta = new ClassMetadata('Sonata\AdminBundle\Tests\Fixtures\Entity\Foo'); |
133
|
|
|
|
134
|
|
|
$annotation->processMetadata($meta); |
135
|
|
|
|
136
|
|
|
$this->assertSame( |
137
|
|
|
array( |
138
|
|
|
'manager_type' => 'doctrine_mongodb', |
139
|
|
|
'group' => 'myGroup', |
140
|
|
|
'label' => 'myLabel', |
141
|
|
|
'show_in_dashboard' => false, |
142
|
|
|
'keep_open' => true, |
143
|
|
|
'on_top' => true, |
144
|
|
|
), |
145
|
|
|
$meta->tags['sonata.admin'][0] |
146
|
|
|
); |
147
|
|
|
|
148
|
|
|
$this->assertSame(array('setTranslationDomain', array('OMG')), $meta->methodCalls[0]); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|