AdminTest.php 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Tests\Admin;
  11. use Sonata\AdminBundle\Admin\AbstractAdmin;
  12. use Sonata\AdminBundle\Admin\AdminInterface;
  13. use Sonata\AdminBundle\Admin\Pool;
  14. use Sonata\AdminBundle\Route\DefaultRouteGenerator;
  15. use Sonata\AdminBundle\Route\RoutesCache;
  16. use Sonata\AdminBundle\Tests\Fixtures\Admin\CommentAdmin;
  17. use Sonata\AdminBundle\Tests\Fixtures\Admin\CommentWithCustomRouteAdmin;
  18. use Sonata\AdminBundle\Tests\Fixtures\Admin\FieldDescription;
  19. use Sonata\AdminBundle\Tests\Fixtures\Admin\FilteredAdmin;
  20. use Sonata\AdminBundle\Tests\Fixtures\Admin\ModelAdmin;
  21. use Sonata\AdminBundle\Tests\Fixtures\Admin\PostAdmin;
  22. use Sonata\AdminBundle\Tests\Fixtures\Admin\PostWithCustomRouteAdmin;
  23. use Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\Comment;
  24. use Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\Post;
  25. use Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\Tag;
  26. use Sonata\AdminBundle\Tests\Fixtures\Entity\FooToString;
  27. use Sonata\AdminBundle\Tests\Fixtures\Entity\FooToStringNull;
  28. use Sonata\AdminBundle\Tests\Helpers\PHPUnit_Framework_TestCase;
  29. use Sonata\CoreBundle\Model\Adapter\AdapterInterface;
  30. use Symfony\Component\DependencyInjection\Container;
  31. use Symfony\Component\HttpFoundation\Request;
  32. use Symfony\Component\PropertyAccess\PropertyAccess;
  33. class AdminTest extends PHPUnit_Framework_TestCase
  34. {
  35. protected $cacheTempFolder;
  36. public function setUp()
  37. {
  38. $this->cacheTempFolder = sys_get_temp_dir().'/sonata_test_route';
  39. exec('rm -rf '.$this->cacheTempFolder);
  40. }
  41. /**
  42. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::__construct
  43. */
  44. public function testConstructor()
  45. {
  46. $class = 'Application\Sonata\NewsBundle\Entity\Post';
  47. $baseControllerName = 'SonataNewsBundle:PostAdmin';
  48. $admin = new PostAdmin('sonata.post.admin.post', $class, $baseControllerName);
  49. $this->assertInstanceOf('Sonata\AdminBundle\Admin\AbstractAdmin', $admin);
  50. $this->assertSame($class, $admin->getClass());
  51. $this->assertSame($baseControllerName, $admin->getBaseControllerName());
  52. }
  53. public function testGetClass()
  54. {
  55. $class = 'Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\Post';
  56. $baseControllerName = 'SonataNewsBundle:PostAdmin';
  57. $admin = new PostAdmin('sonata.post.admin.post', $class, $baseControllerName);
  58. $admin->setSubject(new \Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\BlogPost());
  59. $this->assertSame(
  60. 'Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\BlogPost',
  61. $admin->getClass()
  62. );
  63. $admin->setSubClasses(array('foo'));
  64. $this->assertSame(
  65. 'Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\BlogPost',
  66. $admin->getClass()
  67. );
  68. $admin->setSubject(null);
  69. $admin->setSubClasses(array());
  70. $this->assertSame($class, $admin->getClass());
  71. $admin->setSubClasses(array('foo' => 'bar'));
  72. $admin->setRequest(new Request(array('subclass' => 'foo')));
  73. $this->assertSame('bar', $admin->getClass());
  74. }
  75. /**
  76. * @expectedException \RuntimeException
  77. * @expectedExceptionMessage Feature not implemented: an embedded admin cannot have subclass
  78. */
  79. public function testGetClassException()
  80. {
  81. $class = 'Application\Sonata\NewsBundle\Entity\Post';
  82. $baseControllerName = 'SonataNewsBundle:PostAdmin';
  83. $admin = new PostAdmin('sonata.post.admin.post', $class, $baseControllerName);
  84. $admin->setParentFieldDescription(new FieldDescription());
  85. $admin->setSubClasses(array('foo' => 'bar'));
  86. $admin->setRequest(new Request(array('subclass' => 'foo')));
  87. $admin->getClass();
  88. }
  89. public function testCheckAccessThrowsExceptionOnMadeUpAction()
  90. {
  91. $admin = new PostAdmin(
  92. 'sonata.post.admin.post',
  93. 'Application\Sonata\NewsBundle\Entity\Post',
  94. 'SonataNewsBundle:PostAdmin'
  95. );
  96. $this->setExpectedException(
  97. '\InvalidArgumentException',
  98. 'Action "made-up" could not be found'
  99. );
  100. $admin->checkAccess('made-up');
  101. }
  102. public function testCheckAccessThrowsAccessDeniedException()
  103. {
  104. $admin = new PostAdmin(
  105. 'sonata.post.admin.post',
  106. 'Application\Sonata\NewsBundle\Entity\Post',
  107. 'SonataNewsBundle:PostAdmin'
  108. );
  109. $securityHandler = $this->prophesize(
  110. 'Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface'
  111. );
  112. $securityHandler->isGranted($admin, 'CUSTOM_ROLE', $admin)->willReturn(true);
  113. $securityHandler->isGranted($admin, 'EXTRA_CUSTOM_ROLE', $admin)->willReturn(false);
  114. $customExtension = $this->prophesize(
  115. 'Sonata\AdminBundle\Admin\AbstractAdminExtension'
  116. );
  117. $customExtension->getAccessMapping($admin)->willReturn(
  118. array('custom_action' => array('CUSTOM_ROLE', 'EXTRA_CUSTOM_ROLE'))
  119. );
  120. $admin->addExtension($customExtension->reveal());
  121. $admin->setSecurityHandler($securityHandler->reveal());
  122. $this->setExpectedException(
  123. 'Symfony\Component\Security\Core\Exception\AccessDeniedException',
  124. 'Access Denied to the action custom_action and role EXTRA_CUSTOM_ROLE'
  125. );
  126. $admin->checkAccess('custom_action');
  127. }
  128. public function testHasAccessOnMadeUpAction()
  129. {
  130. $admin = new PostAdmin(
  131. 'sonata.post.admin.post',
  132. 'Application\Sonata\NewsBundle\Entity\Post',
  133. 'SonataNewsBundle:PostAdmin'
  134. );
  135. $this->assertFalse($admin->hasAccess('made-up'));
  136. }
  137. public function testHasAccess()
  138. {
  139. $admin = new PostAdmin(
  140. 'sonata.post.admin.post',
  141. 'Application\Sonata\NewsBundle\Entity\Post',
  142. 'SonataNewsBundle:PostAdmin'
  143. );
  144. $securityHandler = $this->prophesize(
  145. 'Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface'
  146. );
  147. $securityHandler->isGranted($admin, 'CUSTOM_ROLE', $admin)->willReturn(true);
  148. $securityHandler->isGranted($admin, 'EXTRA_CUSTOM_ROLE', $admin)->willReturn(false);
  149. $customExtension = $this->prophesize(
  150. 'Sonata\AdminBundle\Admin\AbstractAdminExtension'
  151. );
  152. $customExtension->getAccessMapping($admin)->willReturn(
  153. array('custom_action' => array('CUSTOM_ROLE', 'EXTRA_CUSTOM_ROLE'))
  154. );
  155. $admin->addExtension($customExtension->reveal());
  156. $admin->setSecurityHandler($securityHandler->reveal());
  157. $this->assertFalse($admin->hasAccess('custom_action'));
  158. }
  159. public function testHasAccessAllowsAccess()
  160. {
  161. $admin = new PostAdmin(
  162. 'sonata.post.admin.post',
  163. 'Application\Sonata\NewsBundle\Entity\Post',
  164. 'SonataNewsBundle:PostAdmin'
  165. );
  166. $securityHandler = $this->prophesize(
  167. 'Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface'
  168. );
  169. $securityHandler->isGranted($admin, 'CUSTOM_ROLE', $admin)->willReturn(true);
  170. $securityHandler->isGranted($admin, 'EXTRA_CUSTOM_ROLE', $admin)->willReturn(true);
  171. $customExtension = $this->prophesize(
  172. 'Sonata\AdminBundle\Admin\AbstractAdminExtension'
  173. );
  174. $customExtension->getAccessMapping($admin)->willReturn(
  175. array('custom_action' => array('CUSTOM_ROLE', 'EXTRA_CUSTOM_ROLE'))
  176. );
  177. $admin->addExtension($customExtension->reveal());
  178. $admin->setSecurityHandler($securityHandler->reveal());
  179. $this->assertTrue($admin->hasAccess('custom_action'));
  180. }
  181. public function testHasAccessAllowsAccessEditAction()
  182. {
  183. $admin = new PostAdmin(
  184. 'sonata.post.admin.post',
  185. 'Application\Sonata\NewsBundle\Entity\Post',
  186. 'SonataNewsBundle:PostAdmin'
  187. );
  188. $securityHandler = $this->prophesize(
  189. 'Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface'
  190. );
  191. $securityHandler->isGranted($admin, 'EDIT_ROLE', $admin)->willReturn(true);
  192. $customExtension = $this->prophesize(
  193. 'Sonata\AdminBundle\Admin\AbstractAdminExtension'
  194. );
  195. $customExtension->getAccessMapping($admin)->willReturn(
  196. array('edit_action' => array('EDIT_ROLE'))
  197. );
  198. $admin->addExtension($customExtension->reveal());
  199. $admin->setSecurityHandler($securityHandler->reveal());
  200. $this->assertTrue($admin->hasAccess('edit_action'));
  201. }
  202. /**
  203. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasChild
  204. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::addChild
  205. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getChild
  206. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::isChild
  207. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasChildren
  208. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getChildren
  209. */
  210. public function testChildren()
  211. {
  212. $postAdmin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  213. $this->assertFalse($postAdmin->hasChildren());
  214. $this->assertFalse($postAdmin->hasChild('comment'));
  215. $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'SonataNewsBundle:CommentAdmin');
  216. $postAdmin->addChild($commentAdmin);
  217. $this->assertTrue($postAdmin->hasChildren());
  218. $this->assertTrue($postAdmin->hasChild('sonata.post.admin.comment'));
  219. $this->assertSame('sonata.post.admin.comment', $postAdmin->getChild('sonata.post.admin.comment')->getCode());
  220. $this->assertSame('sonata.post.admin.post|sonata.post.admin.comment', $postAdmin->getChild('sonata.post.admin.comment')->getBaseCodeRoute());
  221. $this->assertSame($postAdmin, $postAdmin->getChild('sonata.post.admin.comment')->getParent());
  222. $this->assertFalse($postAdmin->isChild());
  223. $this->assertTrue($commentAdmin->isChild());
  224. $this->assertSame(array('sonata.post.admin.comment' => $commentAdmin), $postAdmin->getChildren());
  225. }
  226. /**
  227. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::configure
  228. */
  229. public function testConfigure()
  230. {
  231. $admin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  232. $this->assertNotNull($admin->getUniqid());
  233. $admin->initialize();
  234. $this->assertNotNull($admin->getUniqid());
  235. $this->assertSame('Post', $admin->getClassnameLabel());
  236. $admin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'SonataNewsBundle:CommentAdmin');
  237. $admin->setClassnameLabel('postcomment');
  238. $admin->initialize();
  239. $this->assertSame('postcomment', $admin->getClassnameLabel());
  240. }
  241. public function testConfigureWithValidParentAssociationMapping()
  242. {
  243. $admin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  244. $admin->setParentAssociationMapping('Category');
  245. $admin->initialize();
  246. $this->assertSame('Category', $admin->getParentAssociationMapping());
  247. }
  248. public function provideGetBaseRoutePattern()
  249. {
  250. return array(
  251. array(
  252. 'Application\Sonata\NewsBundle\Entity\Post',
  253. '/sonata/news/post',
  254. ),
  255. array(
  256. 'Application\Sonata\NewsBundle\Document\Post',
  257. '/sonata/news/post',
  258. ),
  259. array(
  260. 'MyApplication\MyBundle\Entity\Post',
  261. '/myapplication/my/post',
  262. ),
  263. array(
  264. 'MyApplication\MyBundle\Entity\Post\Category',
  265. '/myapplication/my/post-category',
  266. ),
  267. array(
  268. 'MyApplication\MyBundle\Entity\Product\Category',
  269. '/myapplication/my/product-category',
  270. ),
  271. array(
  272. 'MyApplication\MyBundle\Entity\Other\Product\Category',
  273. '/myapplication/my/other-product-category',
  274. ),
  275. array(
  276. 'Symfony\Cmf\Bundle\FooBundle\Document\Menu',
  277. '/cmf/foo/menu',
  278. ),
  279. array(
  280. 'Symfony\Cmf\Bundle\FooBundle\Doctrine\Phpcr\Menu',
  281. '/cmf/foo/menu',
  282. ),
  283. array(
  284. 'Symfony\Bundle\BarBarBundle\Doctrine\Phpcr\Menu',
  285. '/symfony/barbar/menu',
  286. ),
  287. array(
  288. 'Symfony\Bundle\BarBarBundle\Doctrine\Phpcr\Menu\Item',
  289. '/symfony/barbar/menu-item',
  290. ),
  291. array(
  292. 'Symfony\Cmf\Bundle\FooBundle\Doctrine\Orm\Menu',
  293. '/cmf/foo/menu',
  294. ),
  295. array(
  296. 'Symfony\Cmf\Bundle\FooBundle\Doctrine\MongoDB\Menu',
  297. '/cmf/foo/menu',
  298. ),
  299. array(
  300. 'Symfony\Cmf\Bundle\FooBundle\Doctrine\CouchDB\Menu',
  301. '/cmf/foo/menu',
  302. ),
  303. array(
  304. 'AppBundle\Entity\User',
  305. '/app/user',
  306. ),
  307. array(
  308. 'App\Entity\User',
  309. '/app/user',
  310. ),
  311. );
  312. }
  313. /**
  314. * @dataProvider provideGetBaseRoutePattern
  315. */
  316. public function testGetBaseRoutePattern($objFqn, $expected)
  317. {
  318. $admin = new PostAdmin('sonata.post.admin.post', $objFqn, 'SonataNewsBundle:PostAdmin');
  319. $this->assertSame($expected, $admin->getBaseRoutePattern());
  320. }
  321. /**
  322. * @dataProvider provideGetBaseRoutePattern
  323. */
  324. public function testGetBaseRoutePatternWithChildAdmin($objFqn, $expected)
  325. {
  326. $postAdmin = new PostAdmin('sonata.post.admin.post', $objFqn, 'SonataNewsBundle:PostAdmin');
  327. $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'SonataNewsBundle:CommentAdmin');
  328. $commentAdmin->setParent($postAdmin);
  329. $this->assertSame($expected.'/{id}/comment', $commentAdmin->getBaseRoutePattern());
  330. }
  331. public function testGetBaseRoutePatternWithSpecifedPattern()
  332. {
  333. $postAdmin = new PostWithCustomRouteAdmin('sonata.post.admin.post_with_custom_route', 'Application\Sonata\NewsBundle\Entity\Post', 'SonataNewsBundle:PostWithCustomRouteAdmin');
  334. $this->assertSame('/post-custom', $postAdmin->getBaseRoutePattern());
  335. }
  336. public function testGetBaseRoutePatternWithChildAdminAndWithSpecifedPattern()
  337. {
  338. $postAdmin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  339. $commentAdmin = new CommentWithCustomRouteAdmin('sonata.post.admin.comment_with_custom_route', 'Application\Sonata\NewsBundle\Entity\Comment', 'SonataNewsBundle:CommentWithCustomRouteAdmin');
  340. $commentAdmin->setParent($postAdmin);
  341. $this->assertSame('/sonata/news/post/{id}/comment-custom', $commentAdmin->getBaseRoutePattern());
  342. }
  343. /**
  344. * @expectedException \RuntimeException
  345. */
  346. public function testGetBaseRoutePatternWithUnreconizedClassname()
  347. {
  348. $admin = new PostAdmin('sonata.post.admin.post', 'News\Thing\Post', 'SonataNewsBundle:PostAdmin');
  349. $admin->getBaseRoutePattern();
  350. }
  351. public function provideGetBaseRouteName()
  352. {
  353. return array(
  354. array(
  355. 'Application\Sonata\NewsBundle\Entity\Post',
  356. 'admin_sonata_news_post',
  357. ),
  358. array(
  359. 'Application\Sonata\NewsBundle\Document\Post',
  360. 'admin_sonata_news_post',
  361. ),
  362. array(
  363. 'MyApplication\MyBundle\Entity\Post',
  364. 'admin_myapplication_my_post',
  365. ),
  366. array(
  367. 'MyApplication\MyBundle\Entity\Post\Category',
  368. 'admin_myapplication_my_post_category',
  369. ),
  370. array(
  371. 'MyApplication\MyBundle\Entity\Product\Category',
  372. 'admin_myapplication_my_product_category',
  373. ),
  374. array(
  375. 'MyApplication\MyBundle\Entity\Other\Product\Category',
  376. 'admin_myapplication_my_other_product_category',
  377. ),
  378. array(
  379. 'Symfony\Cmf\Bundle\FooBundle\Document\Menu',
  380. 'admin_cmf_foo_menu',
  381. ),
  382. array(
  383. 'Symfony\Cmf\Bundle\FooBundle\Doctrine\Phpcr\Menu',
  384. 'admin_cmf_foo_menu',
  385. ),
  386. array(
  387. 'Symfony\Bundle\BarBarBundle\Doctrine\Phpcr\Menu',
  388. 'admin_symfony_barbar_menu',
  389. ),
  390. array(
  391. 'Symfony\Bundle\BarBarBundle\Doctrine\Phpcr\Menu\Item',
  392. 'admin_symfony_barbar_menu_item',
  393. ),
  394. array(
  395. 'Symfony\Cmf\Bundle\FooBundle\Doctrine\Orm\Menu',
  396. 'admin_cmf_foo_menu',
  397. ),
  398. array(
  399. 'Symfony\Cmf\Bundle\FooBundle\Doctrine\MongoDB\Menu',
  400. 'admin_cmf_foo_menu',
  401. ),
  402. array(
  403. 'Symfony\Cmf\Bundle\FooBundle\Doctrine\CouchDB\Menu',
  404. 'admin_cmf_foo_menu',
  405. ),
  406. array(
  407. 'AppBundle\Entity\User',
  408. 'admin_app_user',
  409. ),
  410. array(
  411. 'App\Entity\User',
  412. 'admin_app_user',
  413. ),
  414. );
  415. }
  416. /**
  417. * @dataProvider provideGetBaseRouteName
  418. */
  419. public function testGetBaseRouteName($objFqn, $expected)
  420. {
  421. $admin = new PostAdmin('sonata.post.admin.post', $objFqn, 'SonataNewsBundle:PostAdmin');
  422. $this->assertSame($expected, $admin->getBaseRouteName());
  423. }
  424. /**
  425. * @dataProvider provideGetBaseRouteName
  426. */
  427. public function testGetBaseRouteNameWithChildAdmin($objFqn, $expected)
  428. {
  429. $routeGenerator = new DefaultRouteGenerator(
  430. $this->createMock('Symfony\Component\Routing\RouterInterface'),
  431. new RoutesCache($this->cacheTempFolder, true)
  432. );
  433. $container = new Container();
  434. $pool = new Pool($container, 'Sonata Admin', '/path/to/pic.png');
  435. $pathInfo = new \Sonata\AdminBundle\Route\PathInfoBuilder($this->createMock('Sonata\AdminBundle\Model\AuditManagerInterface'));
  436. $postAdmin = new PostAdmin('sonata.post.admin.post', $objFqn, 'SonataNewsBundle:PostAdmin');
  437. $container->set('sonata.post.admin.post', $postAdmin);
  438. $postAdmin->setConfigurationPool($pool);
  439. $postAdmin->setRouteBuilder($pathInfo);
  440. $postAdmin->setRouteGenerator($routeGenerator);
  441. $postAdmin->initialize();
  442. $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'SonataNewsBundle:CommentAdmin');
  443. $container->set('sonata.post.admin.comment', $commentAdmin);
  444. $commentAdmin->setConfigurationPool($pool);
  445. $commentAdmin->setRouteBuilder($pathInfo);
  446. $commentAdmin->setRouteGenerator($routeGenerator);
  447. $commentAdmin->initialize();
  448. $postAdmin->addChild($commentAdmin);
  449. $pool->setAdminServiceIds(array('sonata.post.admin.post', 'sonata.post.admin.comment'));
  450. $this->assertSame($expected.'_comment', $commentAdmin->getBaseRouteName());
  451. $this->assertTrue($postAdmin->hasRoute('show'));
  452. $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.post.show'));
  453. $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.post|sonata.post.admin.comment.show'));
  454. $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.comment.list'));
  455. $this->assertFalse($postAdmin->hasRoute('sonata.post.admin.post|sonata.post.admin.comment.edit'));
  456. $this->assertFalse($commentAdmin->hasRoute('edit'));
  457. /*
  458. * Test the route name from request
  459. */
  460. $postListRequest = new Request(
  461. array(),
  462. array(),
  463. array(
  464. '_route' => $postAdmin->getBaseRouteName().'_list',
  465. )
  466. );
  467. $postAdmin->setRequest($postListRequest);
  468. $commentAdmin->setRequest($postListRequest);
  469. $this->assertTrue($postAdmin->isCurrentRoute('list'));
  470. $this->assertFalse($postAdmin->isCurrentRoute('create'));
  471. $this->assertFalse($commentAdmin->isCurrentRoute('list'));
  472. $this->assertTrue($commentAdmin->isCurrentRoute('list', 'sonata.post.admin.post'));
  473. $this->assertFalse($commentAdmin->isCurrentRoute('edit', 'sonata.post.admin.post'));
  474. }
  475. /**
  476. * @expectedException \RuntimeException
  477. */
  478. public function testGetBaseRouteNameWithUnreconizedClassname()
  479. {
  480. $admin = new PostAdmin('sonata.post.admin.post', 'News\Thing\Post', 'SonataNewsBundle:PostAdmin');
  481. $admin->getBaseRouteName();
  482. }
  483. public function testGetBaseRouteNameWithSpecifiedName()
  484. {
  485. $postAdmin = new PostWithCustomRouteAdmin('sonata.post.admin.post_with_custom_route', 'Application\Sonata\NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  486. $this->assertSame('post_custom', $postAdmin->getBaseRouteName());
  487. }
  488. public function testGetBaseRouteNameWithChildAdminAndWithSpecifiedName()
  489. {
  490. $postAdmin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  491. $commentAdmin = new CommentWithCustomRouteAdmin('sonata.post.admin.comment_with_custom_route', 'Application\Sonata\NewsBundle\Entity\Comment', 'SonataNewsBundle:CommentWithCustomRouteAdmin');
  492. $commentAdmin->setParent($postAdmin);
  493. $this->assertSame('admin_sonata_news_post_comment_custom', $commentAdmin->getBaseRouteName());
  494. }
  495. /**
  496. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::setUniqid
  497. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getUniqid
  498. */
  499. public function testUniqid()
  500. {
  501. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  502. $uniqid = uniqid();
  503. $admin->setUniqid($uniqid);
  504. $this->assertSame($uniqid, $admin->getUniqid());
  505. }
  506. public function testToString()
  507. {
  508. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  509. $s = new \stdClass();
  510. $this->assertNotEmpty($admin->toString($s));
  511. $s = new FooToString();
  512. $this->assertSame('salut', $admin->toString($s));
  513. // To string method is implemented, but returns null
  514. $s = new FooToStringNull();
  515. $this->assertNotEmpty($admin->toString($s));
  516. $this->assertSame('', $admin->toString(false));
  517. }
  518. public function testIsAclEnabled()
  519. {
  520. $postAdmin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  521. $this->assertFalse($postAdmin->isAclEnabled());
  522. $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'SonataNewsBundle:CommentAdmin');
  523. $commentAdmin->setSecurityHandler($this->createMock('Sonata\AdminBundle\Security\Handler\AclSecurityHandlerInterface'));
  524. $this->assertTrue($commentAdmin->isAclEnabled());
  525. }
  526. /**
  527. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getSubClasses
  528. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getSubClass
  529. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::setSubClasses
  530. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasSubClass
  531. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasActiveSubClass
  532. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getActiveSubClass
  533. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getActiveSubclassCode
  534. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getClass
  535. */
  536. public function testSubClass()
  537. {
  538. $admin = new PostAdmin(
  539. 'sonata.post.admin.post',
  540. 'Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\Post',
  541. 'SonataNewsBundle:PostAdmin'
  542. );
  543. $this->assertFalse($admin->hasSubClass('test'));
  544. $this->assertFalse($admin->hasActiveSubClass());
  545. $this->assertCount(0, $admin->getSubClasses());
  546. $this->assertNull($admin->getActiveSubClass());
  547. $this->assertNull($admin->getActiveSubclassCode());
  548. $this->assertSame(
  549. 'Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\Post',
  550. $admin->getClass()
  551. );
  552. // Just for the record, if there is no inheritance set, the getSubject is not used
  553. // the getSubject can also lead to some issue
  554. $admin->setSubject(new \Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\BlogPost());
  555. $this->assertSame(
  556. 'Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\BlogPost',
  557. $admin->getClass()
  558. );
  559. $admin->setSubClasses(array('extended1' => 'NewsBundle\Entity\PostExtended1', 'extended2' => 'NewsBundle\Entity\PostExtended2'));
  560. $this->assertFalse($admin->hasSubClass('test'));
  561. $this->assertTrue($admin->hasSubClass('extended1'));
  562. $this->assertFalse($admin->hasActiveSubClass());
  563. $this->assertCount(2, $admin->getSubClasses());
  564. $this->assertNull($admin->getActiveSubClass());
  565. $this->assertNull($admin->getActiveSubclassCode());
  566. $this->assertSame(
  567. 'Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\BlogPost',
  568. $admin->getClass()
  569. );
  570. $request = new \Symfony\Component\HttpFoundation\Request(array('subclass' => 'extended1'));
  571. $admin->setRequest($request);
  572. $this->assertFalse($admin->hasSubClass('test'));
  573. $this->assertTrue($admin->hasSubClass('extended1'));
  574. $this->assertTrue($admin->hasActiveSubClass());
  575. $this->assertCount(2, $admin->getSubClasses());
  576. $this->assertSame(
  577. 'Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\BlogPost',
  578. $admin->getActiveSubClass()
  579. );
  580. $this->assertSame('extended1', $admin->getActiveSubclassCode());
  581. $this->assertSame(
  582. 'Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\BlogPost',
  583. $admin->getClass()
  584. );
  585. $request->query->set('subclass', 'inject');
  586. $this->assertNull($admin->getActiveSubclassCode());
  587. }
  588. /**
  589. * @expectedException \RuntimeException
  590. */
  591. public function testNonExistantSubclass()
  592. {
  593. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  594. $admin->setRequest(new \Symfony\Component\HttpFoundation\Request(array('subclass' => 'inject')));
  595. $admin->setSubClasses(array('extended1' => 'NewsBundle\Entity\PostExtended1', 'extended2' => 'NewsBundle\Entity\PostExtended2'));
  596. $this->assertTrue($admin->hasActiveSubClass());
  597. $admin->getActiveSubClass();
  598. }
  599. /**
  600. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasActiveSubClass
  601. */
  602. public function testOnlyOneSubclassNeededToBeActive()
  603. {
  604. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  605. $admin->setSubClasses(array('extended1' => 'NewsBundle\Entity\PostExtended1'));
  606. $request = new \Symfony\Component\HttpFoundation\Request(array('subclass' => 'extended1'));
  607. $admin->setRequest($request);
  608. $this->assertTrue($admin->hasActiveSubClass());
  609. }
  610. public function testGetPerPageOptions()
  611. {
  612. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  613. $this->assertSame(array(16, 32, 64, 128, 192), $admin->getPerPageOptions());
  614. $admin->setPerPageOptions(array(500, 1000));
  615. $this->assertSame(array(500, 1000), $admin->getPerPageOptions());
  616. }
  617. public function testGetLabelTranslatorStrategy()
  618. {
  619. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  620. $this->assertNull($admin->getLabelTranslatorStrategy());
  621. $labelTranslatorStrategy = $this->createMock('Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface');
  622. $admin->setLabelTranslatorStrategy($labelTranslatorStrategy);
  623. $this->assertSame($labelTranslatorStrategy, $admin->getLabelTranslatorStrategy());
  624. }
  625. public function testGetRouteBuilder()
  626. {
  627. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  628. $this->assertNull($admin->getRouteBuilder());
  629. $routeBuilder = $this->createMock('Sonata\AdminBundle\Builder\RouteBuilderInterface');
  630. $admin->setRouteBuilder($routeBuilder);
  631. $this->assertSame($routeBuilder, $admin->getRouteBuilder());
  632. }
  633. public function testGetMenuFactory()
  634. {
  635. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  636. $this->assertNull($admin->getMenuFactory());
  637. $menuFactory = $this->createMock('Knp\Menu\FactoryInterface');
  638. $admin->setMenuFactory($menuFactory);
  639. $this->assertSame($menuFactory, $admin->getMenuFactory());
  640. }
  641. public function testGetExtensions()
  642. {
  643. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  644. $this->assertSame(array(), $admin->getExtensions());
  645. $adminExtension1 = $this->createMock('Sonata\AdminBundle\Admin\AdminExtensionInterface');
  646. $adminExtension2 = $this->createMock('Sonata\AdminBundle\Admin\AdminExtensionInterface');
  647. $admin->addExtension($adminExtension1);
  648. $admin->addExtension($adminExtension2);
  649. $this->assertSame(array($adminExtension1, $adminExtension2), $admin->getExtensions());
  650. }
  651. public function testGetFilterTheme()
  652. {
  653. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  654. $this->assertSame(array(), $admin->getFilterTheme());
  655. $admin->setFilterTheme(array('FooTheme'));
  656. $this->assertSame(array('FooTheme'), $admin->getFilterTheme());
  657. }
  658. public function testGetFormTheme()
  659. {
  660. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  661. $this->assertSame(array(), $admin->getFormTheme());
  662. $admin->setFormTheme(array('FooTheme'));
  663. $this->assertSame(array('FooTheme'), $admin->getFormTheme());
  664. }
  665. public function testGetValidator()
  666. {
  667. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  668. $this->assertNull($admin->getValidator());
  669. $validatorClass = '\Symfony\Component\Validator\ValidatorInterface';
  670. if (interface_exists('Symfony\Component\Validator\Validator\ValidatorInterface')) {
  671. $validatorClass = 'Symfony\Component\Validator\Validator\ValidatorInterface';
  672. }
  673. $validator = $this->getMockForAbstractClass($validatorClass);
  674. $admin->setValidator($validator);
  675. $this->assertSame($validator, $admin->getValidator());
  676. }
  677. public function testGetSecurityHandler()
  678. {
  679. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  680. $this->assertNull($admin->getSecurityHandler());
  681. $securityHandler = $this->createMock('Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface');
  682. $admin->setSecurityHandler($securityHandler);
  683. $this->assertSame($securityHandler, $admin->getSecurityHandler());
  684. }
  685. public function testGetSecurityInformation()
  686. {
  687. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  688. $this->assertSame(array(), $admin->getSecurityInformation());
  689. $securityInformation = array(
  690. 'GUEST' => array('VIEW', 'LIST'),
  691. 'STAFF' => array('EDIT', 'LIST', 'CREATE'),
  692. );
  693. $admin->setSecurityInformation($securityInformation);
  694. $this->assertSame($securityInformation, $admin->getSecurityInformation());
  695. }
  696. public function testGetManagerType()
  697. {
  698. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  699. $this->assertNull($admin->getManagerType());
  700. $admin->setManagerType('foo_orm');
  701. $this->assertSame('foo_orm', $admin->getManagerType());
  702. }
  703. public function testGetModelManager()
  704. {
  705. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  706. $this->assertNull($admin->getModelManager());
  707. $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
  708. $admin->setModelManager($modelManager);
  709. $this->assertSame($modelManager, $admin->getModelManager());
  710. }
  711. public function testGetBaseCodeRoute()
  712. {
  713. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  714. $this->assertSame('', $admin->getBaseCodeRoute());
  715. $admin->setBaseCodeRoute('foo');
  716. $this->assertSame('foo', $admin->getBaseCodeRoute());
  717. }
  718. public function testGetRouteGenerator()
  719. {
  720. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  721. $this->assertNull($admin->getRouteGenerator());
  722. $routeGenerator = $this->createMock('Sonata\AdminBundle\Route\RouteGeneratorInterface');
  723. $admin->setRouteGenerator($routeGenerator);
  724. $this->assertSame($routeGenerator, $admin->getRouteGenerator());
  725. }
  726. public function testGetConfigurationPool()
  727. {
  728. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  729. $this->assertNull($admin->getConfigurationPool());
  730. $pool = $this->getMockBuilder('Sonata\AdminBundle\Admin\Pool')
  731. ->disableOriginalConstructor()
  732. ->getMock();
  733. $admin->setConfigurationPool($pool);
  734. $this->assertSame($pool, $admin->getConfigurationPool());
  735. }
  736. public function testGetShowBuilder()
  737. {
  738. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  739. $this->assertNull($admin->getShowBuilder());
  740. $showBuilder = $this->createMock('Sonata\AdminBundle\Builder\ShowBuilderInterface');
  741. $admin->setShowBuilder($showBuilder);
  742. $this->assertSame($showBuilder, $admin->getShowBuilder());
  743. }
  744. public function testGetListBuilder()
  745. {
  746. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  747. $this->assertNull($admin->getListBuilder());
  748. $listBuilder = $this->createMock('Sonata\AdminBundle\Builder\ListBuilderInterface');
  749. $admin->setListBuilder($listBuilder);
  750. $this->assertSame($listBuilder, $admin->getListBuilder());
  751. }
  752. public function testGetDatagridBuilder()
  753. {
  754. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  755. $this->assertNull($admin->getDatagridBuilder());
  756. $datagridBuilder = $this->createMock('Sonata\AdminBundle\Builder\DatagridBuilderInterface');
  757. $admin->setDatagridBuilder($datagridBuilder);
  758. $this->assertSame($datagridBuilder, $admin->getDatagridBuilder());
  759. }
  760. public function testGetFormContractor()
  761. {
  762. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  763. $this->assertNull($admin->getFormContractor());
  764. $formContractor = $this->createMock('Sonata\AdminBundle\Builder\FormContractorInterface');
  765. $admin->setFormContractor($formContractor);
  766. $this->assertSame($formContractor, $admin->getFormContractor());
  767. }
  768. public function testGetRequest()
  769. {
  770. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  771. $this->assertFalse($admin->hasRequest());
  772. $request = new Request();
  773. $admin->setRequest($request);
  774. $this->assertSame($request, $admin->getRequest());
  775. $this->assertTrue($admin->hasRequest());
  776. }
  777. public function testGetRequestWithException()
  778. {
  779. $this->setExpectedException('RuntimeException', 'The Request object has not been set');
  780. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  781. $admin->getRequest();
  782. }
  783. public function testGetTranslationDomain()
  784. {
  785. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  786. $this->assertSame('messages', $admin->getTranslationDomain());
  787. $admin->setTranslationDomain('foo');
  788. $this->assertSame('foo', $admin->getTranslationDomain());
  789. }
  790. /**
  791. * @group legacy
  792. */
  793. public function testGetTranslator()
  794. {
  795. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  796. $this->assertNull($admin->getTranslator());
  797. $translator = $this->createMock('Symfony\Component\Translation\TranslatorInterface');
  798. $admin->setTranslator($translator);
  799. $this->assertSame($translator, $admin->getTranslator());
  800. }
  801. public function testGetShowGroups()
  802. {
  803. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  804. $this->assertSame(false, $admin->getShowGroups());
  805. $groups = array('foo', 'bar', 'baz');
  806. $admin->setShowGroups($groups);
  807. $this->assertSame($groups, $admin->getShowGroups());
  808. }
  809. public function testGetFormGroups()
  810. {
  811. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  812. $this->assertSame(false, $admin->getFormGroups());
  813. $groups = array('foo', 'bar', 'baz');
  814. $admin->setFormGroups($groups);
  815. $this->assertSame($groups, $admin->getFormGroups());
  816. }
  817. public function testGetMaxPageLinks()
  818. {
  819. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  820. $this->assertSame(25, $admin->getMaxPageLinks());
  821. $admin->setMaxPageLinks(14);
  822. $this->assertSame(14, $admin->getMaxPageLinks());
  823. }
  824. public function testGetMaxPerPage()
  825. {
  826. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  827. $this->assertSame(32, $admin->getMaxPerPage());
  828. $admin->setMaxPerPage(94);
  829. $this->assertSame(94, $admin->getMaxPerPage());
  830. }
  831. public function testGetLabel()
  832. {
  833. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  834. $this->assertNull($admin->getLabel());
  835. $admin->setLabel('FooLabel');
  836. $this->assertSame('FooLabel', $admin->getLabel());
  837. }
  838. public function testGetBaseController()
  839. {
  840. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  841. $this->assertSame('SonataNewsBundle:PostAdmin', $admin->getBaseControllerName());
  842. $admin->setBaseControllerName('SonataNewsBundle:FooAdmin');
  843. $this->assertSame('SonataNewsBundle:FooAdmin', $admin->getBaseControllerName());
  844. }
  845. public function testGetTemplates()
  846. {
  847. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  848. $this->assertSame(array(), $admin->getTemplates());
  849. $templates = array(
  850. 'list' => 'FooAdminBundle:CRUD:list.html.twig',
  851. 'show' => 'FooAdminBundle:CRUD:show.html.twig',
  852. 'edit' => 'FooAdminBundle:CRUD:edit.html.twig',
  853. );
  854. $admin->setTemplates($templates);
  855. $this->assertSame($templates, $admin->getTemplates());
  856. }
  857. public function testGetTemplate1()
  858. {
  859. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  860. $this->assertNull($admin->getTemplate('edit'));
  861. $admin->setTemplate('edit', 'FooAdminBundle:CRUD:edit.html.twig');
  862. $admin->setTemplate('show', 'FooAdminBundle:CRUD:show.html.twig');
  863. $this->assertSame('FooAdminBundle:CRUD:edit.html.twig', $admin->getTemplate('edit'));
  864. $this->assertSame('FooAdminBundle:CRUD:show.html.twig', $admin->getTemplate('show'));
  865. }
  866. public function testGetTemplate2()
  867. {
  868. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  869. $this->assertNull($admin->getTemplate('edit'));
  870. $templates = array(
  871. 'list' => 'FooAdminBundle:CRUD:list.html.twig',
  872. 'show' => 'FooAdminBundle:CRUD:show.html.twig',
  873. 'edit' => 'FooAdminBundle:CRUD:edit.html.twig',
  874. );
  875. $admin->setTemplates($templates);
  876. $this->assertSame('FooAdminBundle:CRUD:edit.html.twig', $admin->getTemplate('edit'));
  877. $this->assertSame('FooAdminBundle:CRUD:show.html.twig', $admin->getTemplate('show'));
  878. }
  879. public function testGetIdParameter()
  880. {
  881. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  882. $this->assertSame('id', $admin->getIdParameter());
  883. $this->assertFalse($admin->isChild());
  884. $parentAdmin = new PostAdmin('sonata.post.admin.post_parent', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostParentAdmin');
  885. $admin->setParent($parentAdmin);
  886. $this->assertTrue($admin->isChild());
  887. $this->assertSame('childId', $admin->getIdParameter());
  888. }
  889. public function testGetExportFormats()
  890. {
  891. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  892. $this->assertSame(array('json', 'xml', 'csv', 'xls'), $admin->getExportFormats());
  893. }
  894. public function testGetUrlsafeIdentifier()
  895. {
  896. $admin = new PostAdmin('sonata.post.admin.post', 'Acme\NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  897. $entity = new \stdClass();
  898. $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
  899. $modelManager->expects($this->once())
  900. ->method('getUrlsafeIdentifier')
  901. ->with($this->equalTo($entity))
  902. ->will($this->returnValue('foo'));
  903. $admin->setModelManager($modelManager);
  904. $this->assertSame('foo', $admin->getUrlsafeIdentifier($entity));
  905. }
  906. public function testDeterminedPerPageValue()
  907. {
  908. $admin = new PostAdmin('sonata.post.admin.post', 'Acme\NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  909. $this->assertFalse($admin->determinedPerPageValue('foo'));
  910. $this->assertFalse($admin->determinedPerPageValue(123));
  911. $this->assertTrue($admin->determinedPerPageValue(16));
  912. $this->assertTrue($admin->determinedPerPageValue(32));
  913. $this->assertTrue($admin->determinedPerPageValue(64));
  914. $this->assertTrue($admin->determinedPerPageValue(128));
  915. $this->assertTrue($admin->determinedPerPageValue(192));
  916. $admin->setPerPageOptions(array(101, 102, 103));
  917. $this->assertFalse($admin->determinedPerPageValue(15));
  918. $this->assertFalse($admin->determinedPerPageValue(25));
  919. $this->assertFalse($admin->determinedPerPageValue(200));
  920. $this->assertTrue($admin->determinedPerPageValue(101));
  921. $this->assertTrue($admin->determinedPerPageValue(102));
  922. $this->assertTrue($admin->determinedPerPageValue(103));
  923. }
  924. public function testIsGranted()
  925. {
  926. $admin = new PostAdmin('sonata.post.admin.post', 'Acme\NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  927. $entity = new \stdClass();
  928. $securityHandler = $this->createMock('Sonata\AdminBundle\Security\Handler\AclSecurityHandlerInterface');
  929. $securityHandler->expects($this->any())
  930. ->method('isGranted')
  931. ->will($this->returnCallback(function (AdminInterface $adminIn, $attributes, $object = null) use ($admin, $entity) {
  932. if ($admin == $adminIn && $attributes == 'FOO') {
  933. if (($object == $admin) || ($object == $entity)) {
  934. return true;
  935. }
  936. }
  937. return false;
  938. }));
  939. $admin->setSecurityHandler($securityHandler);
  940. $this->assertTrue($admin->isGranted('FOO'));
  941. $this->assertTrue($admin->isGranted('FOO', $entity));
  942. $this->assertFalse($admin->isGranted('BAR'));
  943. $this->assertFalse($admin->isGranted('BAR', $entity));
  944. }
  945. public function testSupportsPreviewMode()
  946. {
  947. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  948. $this->assertFalse($admin->supportsPreviewMode());
  949. }
  950. public function testGetPermissionsShow()
  951. {
  952. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  953. $this->assertSame(array('LIST'), $admin->getPermissionsShow(AbstractAdmin::CONTEXT_DASHBOARD));
  954. $this->assertSame(array('LIST'), $admin->getPermissionsShow(AbstractAdmin::CONTEXT_MENU));
  955. $this->assertSame(array('LIST'), $admin->getPermissionsShow('foo'));
  956. }
  957. public function testShowIn()
  958. {
  959. $admin = new PostAdmin('sonata.post.admin.post', 'Acme\NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  960. $securityHandler = $this->createMock('Sonata\AdminBundle\Security\Handler\AclSecurityHandlerInterface');
  961. $securityHandler->expects($this->any())
  962. ->method('isGranted')
  963. ->will($this->returnCallback(function (AdminInterface $adminIn, $attributes, $object = null) use ($admin) {
  964. if ($admin == $adminIn && $attributes == array('LIST')) {
  965. return true;
  966. }
  967. return false;
  968. }));
  969. $admin->setSecurityHandler($securityHandler);
  970. $this->assertTrue($admin->showIn(AbstractAdmin::CONTEXT_DASHBOARD));
  971. $this->assertTrue($admin->showIn(AbstractAdmin::CONTEXT_MENU));
  972. $this->assertTrue($admin->showIn('foo'));
  973. }
  974. public function testGetObjectIdentifier()
  975. {
  976. $admin = new PostAdmin('sonata.post.admin.post', 'Acme\NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  977. $this->assertSame('sonata.post.admin.post', $admin->getObjectIdentifier());
  978. }
  979. /**
  980. * @group legacy
  981. */
  982. public function testTrans()
  983. {
  984. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  985. $admin->setTranslationDomain('fooMessageDomain');
  986. $translator = $this->createMock('Symfony\Component\Translation\TranslatorInterface');
  987. $admin->setTranslator($translator);
  988. $translator->expects($this->once())
  989. ->method('trans')
  990. ->with($this->equalTo('foo'), $this->equalTo(array()), $this->equalTo('fooMessageDomain'))
  991. ->will($this->returnValue('fooTranslated'));
  992. $this->assertSame('fooTranslated', $admin->trans('foo'));
  993. }
  994. /**
  995. * @group legacy
  996. */
  997. public function testTransWithMessageDomain()
  998. {
  999. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1000. $translator = $this->createMock('Symfony\Component\Translation\TranslatorInterface');
  1001. $admin->setTranslator($translator);
  1002. $translator->expects($this->once())
  1003. ->method('trans')
  1004. ->with($this->equalTo('foo'), $this->equalTo(array('name' => 'Andrej')), $this->equalTo('fooMessageDomain'))
  1005. ->will($this->returnValue('fooTranslated'));
  1006. $this->assertSame('fooTranslated', $admin->trans('foo', array('name' => 'Andrej'), 'fooMessageDomain'));
  1007. }
  1008. /**
  1009. * @group legacy
  1010. */
  1011. public function testTransChoice()
  1012. {
  1013. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1014. $admin->setTranslationDomain('fooMessageDomain');
  1015. $translator = $this->createMock('Symfony\Component\Translation\TranslatorInterface');
  1016. $admin->setTranslator($translator);
  1017. $translator->expects($this->once())
  1018. ->method('transChoice')
  1019. ->with($this->equalTo('foo'), $this->equalTo(2), $this->equalTo(array()), $this->equalTo('fooMessageDomain'))
  1020. ->will($this->returnValue('fooTranslated'));
  1021. $this->assertSame('fooTranslated', $admin->transChoice('foo', 2));
  1022. }
  1023. /**
  1024. * @group legacy
  1025. */
  1026. public function testTransChoiceWithMessageDomain()
  1027. {
  1028. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1029. $translator = $this->createMock('Symfony\Component\Translation\TranslatorInterface');
  1030. $admin->setTranslator($translator);
  1031. $translator->expects($this->once())
  1032. ->method('transChoice')
  1033. ->with($this->equalTo('foo'), $this->equalTo(2), $this->equalTo(array('name' => 'Andrej')), $this->equalTo('fooMessageDomain'))
  1034. ->will($this->returnValue('fooTranslated'));
  1035. $this->assertSame('fooTranslated', $admin->transChoice('foo', 2, array('name' => 'Andrej'), 'fooMessageDomain'));
  1036. }
  1037. public function testSetPersistFilters()
  1038. {
  1039. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1040. $this->assertAttributeSame(false, 'persistFilters', $admin);
  1041. $admin->setPersistFilters(true);
  1042. $this->assertAttributeSame(true, 'persistFilters', $admin);
  1043. }
  1044. public function testGetRootCode()
  1045. {
  1046. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1047. $this->assertSame('sonata.post.admin.post', $admin->getRootCode());
  1048. $parentAdmin = new PostAdmin('sonata.post.admin.post.parent', 'NewsBundle\Entity\PostParent', 'SonataNewsBundle:PostParentAdmin');
  1049. $parentFieldDescription = $this->createMock('Sonata\AdminBundle\Admin\FieldDescriptionInterface');
  1050. $parentFieldDescription->expects($this->once())
  1051. ->method('getAdmin')
  1052. ->will($this->returnValue($parentAdmin));
  1053. $this->assertNull($admin->getParentFieldDescription());
  1054. $admin->setParentFieldDescription($parentFieldDescription);
  1055. $this->assertSame($parentFieldDescription, $admin->getParentFieldDescription());
  1056. $this->assertSame('sonata.post.admin.post.parent', $admin->getRootCode());
  1057. }
  1058. public function testGetRoot()
  1059. {
  1060. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1061. $this->assertSame($admin, $admin->getRoot());
  1062. $parentAdmin = new PostAdmin('sonata.post.admin.post.parent', 'NewsBundle\Entity\PostParent', 'SonataNewsBundle:PostParentAdmin');
  1063. $parentFieldDescription = $this->createMock('Sonata\AdminBundle\Admin\FieldDescriptionInterface');
  1064. $parentFieldDescription->expects($this->once())
  1065. ->method('getAdmin')
  1066. ->will($this->returnValue($parentAdmin));
  1067. $this->assertNull($admin->getParentFieldDescription());
  1068. $admin->setParentFieldDescription($parentFieldDescription);
  1069. $this->assertSame($parentFieldDescription, $admin->getParentFieldDescription());
  1070. $this->assertSame($parentAdmin, $admin->getRoot());
  1071. }
  1072. public function testGetExportFields()
  1073. {
  1074. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1075. $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
  1076. $modelManager->expects($this->once())
  1077. ->method('getExportFields')
  1078. ->with($this->equalTo('NewsBundle\Entity\Post'))
  1079. ->will($this->returnValue(array('foo', 'bar')));
  1080. $admin->setModelManager($modelManager);
  1081. $this->assertSame(array('foo', 'bar'), $admin->getExportFields());
  1082. }
  1083. public function testGetPersistentParametersWithNoExtension()
  1084. {
  1085. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1086. $this->assertEmpty($admin->getPersistentParameters());
  1087. }
  1088. /**
  1089. * @expectedException \RuntimeException
  1090. */
  1091. public function testGetPersistentParametersWithInvalidExtension()
  1092. {
  1093. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1094. $extension = $this->createMock('Sonata\AdminBundle\Admin\AdminExtensionInterface');
  1095. $extension->expects($this->once())->method('getPersistentParameters')->will($this->returnValue(null));
  1096. $admin->addExtension($extension);
  1097. $admin->getPersistentParameters();
  1098. }
  1099. public function testGetPersistentParametersWithValidExtension()
  1100. {
  1101. $expected = array(
  1102. 'context' => 'foobar',
  1103. );
  1104. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1105. $extension = $this->createMock('Sonata\AdminBundle\Admin\AdminExtensionInterface');
  1106. $extension->expects($this->once())->method('getPersistentParameters')->will($this->returnValue($expected));
  1107. $admin->addExtension($extension);
  1108. $this->assertSame($expected, $admin->getPersistentParameters());
  1109. }
  1110. public function testGetFormWithNonCollectionParentValue()
  1111. {
  1112. $post = new Post();
  1113. $tagAdmin = $this->createTagAdmin($post);
  1114. $tag = $tagAdmin->getSubject();
  1115. $tag->setPosts(null);
  1116. $tagAdmin->getForm();
  1117. $this->assertSame($post, $tag->getPosts());
  1118. }
  1119. public function testGetFormWithCollectionParentValue()
  1120. {
  1121. $post = new Post();
  1122. $tagAdmin = $this->createTagAdmin($post);
  1123. $tag = $tagAdmin->getSubject();
  1124. // Case of a doctrine collection
  1125. $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $tag->getPosts());
  1126. $this->assertCount(0, $tag->getPosts());
  1127. $tag->addPost(new Post());
  1128. $this->assertCount(1, $tag->getPosts());
  1129. $tagAdmin->getForm();
  1130. $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $tag->getPosts());
  1131. $this->assertCount(2, $tag->getPosts());
  1132. $this->assertContains($post, $tag->getPosts());
  1133. // Case of an array
  1134. $tag->setPosts(array());
  1135. $this->assertCount(0, $tag->getPosts());
  1136. $tag->addPost(new Post());
  1137. $this->assertCount(1, $tag->getPosts());
  1138. $tagAdmin->getForm();
  1139. $this->assertInternalType('array', $tag->getPosts());
  1140. $this->assertCount(2, $tag->getPosts());
  1141. $this->assertContains($post, $tag->getPosts());
  1142. }
  1143. public function testRemoveFieldFromFormGroup()
  1144. {
  1145. $formGroups = array(
  1146. 'foobar' => array(
  1147. 'fields' => array(
  1148. 'foo' => 'foo',
  1149. 'bar' => 'bar',
  1150. ),
  1151. ),
  1152. );
  1153. $admin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1154. $admin->setFormGroups($formGroups);
  1155. $admin->removeFieldFromFormGroup('foo');
  1156. $this->assertSame($admin->getFormGroups(), array(
  1157. 'foobar' => array(
  1158. 'fields' => array(
  1159. 'bar' => 'bar',
  1160. ),
  1161. ),
  1162. ));
  1163. $admin->removeFieldFromFormGroup('bar');
  1164. $this->assertSame($admin->getFormGroups(), array());
  1165. }
  1166. public function testGetFilterParameters()
  1167. {
  1168. $authorId = uniqid();
  1169. $postAdmin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1170. $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'SonataNewsBundle:CommentAdmin');
  1171. $commentAdmin->setParentAssociationMapping('post.author');
  1172. $commentAdmin->setParent($postAdmin);
  1173. $request = $this->createMock('Symfony\Component\HttpFoundation\Request', array('get'));
  1174. $query = $this->createMock('Symfony\Component\HttpFoundation\ParameterBag', array('get'));
  1175. $query->expects($this->any())
  1176. ->method('get')
  1177. ->will($this->returnValue(array()));
  1178. $request->query = $query;
  1179. $request->expects($this->any())
  1180. ->method('get')
  1181. ->will($this->returnValue($authorId));
  1182. $commentAdmin->setRequest($request);
  1183. $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
  1184. $modelManager->expects($this->any())
  1185. ->method('getDefaultSortValues')
  1186. ->will($this->returnValue(array()));
  1187. $commentAdmin->setModelManager($modelManager);
  1188. $parameters = $commentAdmin->getFilterParameters();
  1189. $this->assertTrue(isset($parameters['post__author']));
  1190. $this->assertSame(array('value' => $authorId), $parameters['post__author']);
  1191. }
  1192. public function testGetFilterFieldDescription()
  1193. {
  1194. $modelAdmin = new ModelAdmin('sonata.post.admin.model', 'Application\Sonata\FooBundle\Entity\Model', 'SonataFooBundle:ModelAdmin');
  1195. $fooFieldDescription = new FieldDescription();
  1196. $barFieldDescription = new FieldDescription();
  1197. $bazFieldDescription = new FieldDescription();
  1198. $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
  1199. $modelManager->expects($this->exactly(3))
  1200. ->method('getNewFieldDescriptionInstance')
  1201. ->will($this->returnCallback(function ($adminClass, $name, $filterOptions) use ($fooFieldDescription, $barFieldDescription, $bazFieldDescription) {
  1202. switch ($name) {
  1203. case 'foo':
  1204. $fieldDescription = $fooFieldDescription;
  1205. break;
  1206. case 'bar':
  1207. $fieldDescription = $barFieldDescription;
  1208. break;
  1209. case 'baz':
  1210. $fieldDescription = $bazFieldDescription;
  1211. break;
  1212. default:
  1213. throw new \RuntimeException(sprintf('Unknown filter name "%s"', $name));
  1214. break;
  1215. }
  1216. $fieldDescription->setName($name);
  1217. return $fieldDescription;
  1218. }));
  1219. $modelAdmin->setModelManager($modelManager);
  1220. $pager = $this->createMock('Sonata\AdminBundle\Datagrid\PagerInterface');
  1221. $datagrid = $this->createMock('Sonata\AdminBundle\Datagrid\DatagridInterface');
  1222. $datagrid->expects($this->once())
  1223. ->method('getPager')
  1224. ->will($this->returnValue($pager));
  1225. $datagridBuilder = $this->createMock('Sonata\AdminBundle\Builder\DatagridBuilderInterface');
  1226. $datagridBuilder->expects($this->once())
  1227. ->method('getBaseDatagrid')
  1228. ->with($this->identicalTo($modelAdmin), array())
  1229. ->will($this->returnValue($datagrid));
  1230. $datagridBuilder->expects($this->exactly(3))
  1231. ->method('addFilter')
  1232. ->will($this->returnCallback(function ($datagrid, $type, $fieldDescription, AdminInterface $admin) {
  1233. $admin->addFilterFieldDescription($fieldDescription->getName(), $fieldDescription);
  1234. $fieldDescription->mergeOption('field_options', array('required' => false));
  1235. }));
  1236. $modelAdmin->setDatagridBuilder($datagridBuilder);
  1237. $this->assertSame(array('foo' => $fooFieldDescription, 'bar' => $barFieldDescription, 'baz' => $bazFieldDescription), $modelAdmin->getFilterFieldDescriptions());
  1238. $this->assertFalse($modelAdmin->hasFilterFieldDescription('fooBar'));
  1239. $this->assertTrue($modelAdmin->hasFilterFieldDescription('foo'));
  1240. $this->assertTrue($modelAdmin->hasFilterFieldDescription('bar'));
  1241. $this->assertTrue($modelAdmin->hasFilterFieldDescription('baz'));
  1242. $this->assertSame($fooFieldDescription, $modelAdmin->getFilterFieldDescription('foo'));
  1243. $this->assertSame($barFieldDescription, $modelAdmin->getFilterFieldDescription('bar'));
  1244. $this->assertSame($bazFieldDescription, $modelAdmin->getFilterFieldDescription('baz'));
  1245. }
  1246. public function testGetSubjectNoRequest()
  1247. {
  1248. $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
  1249. $modelManager
  1250. ->expects($this->never())
  1251. ->method('find');
  1252. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1253. $admin->setModelManager($modelManager);
  1254. $this->assertNull($admin->getSubject());
  1255. }
  1256. public function testGetSideMenu()
  1257. {
  1258. $item = $this->createMock('Knp\Menu\ItemInterface');
  1259. $item
  1260. ->expects($this->once())
  1261. ->method('setChildrenAttribute')
  1262. ->with('class', 'nav navbar-nav');
  1263. $item
  1264. ->expects($this->once())
  1265. ->method('setExtra')
  1266. ->with('translation_domain', 'foo_bar_baz');
  1267. $menuFactory = $this->createMock('Knp\Menu\FactoryInterface');
  1268. $menuFactory
  1269. ->expects($this->once())
  1270. ->method('createItem')
  1271. ->will($this->returnValue($item));
  1272. $modelAdmin = new ModelAdmin('sonata.post.admin.model', 'Application\Sonata\FooBundle\Entity\Model', 'SonataFooBundle:ModelAdmin');
  1273. $modelAdmin->setMenuFactory($menuFactory);
  1274. $modelAdmin->setTranslationDomain('foo_bar_baz');
  1275. $modelAdmin->getSideMenu('foo');
  1276. }
  1277. /**
  1278. * @return array
  1279. */
  1280. public function provideGetSubject()
  1281. {
  1282. return array(
  1283. array(23),
  1284. array('azerty'),
  1285. array('4f69bbb5f14a13347f000092'),
  1286. array('0779ca8d-e2be-11e4-ac58-0242ac11000b'),
  1287. array('123'.AdapterInterface::ID_SEPARATOR.'my_type'), // composite keys are supported
  1288. );
  1289. }
  1290. /**
  1291. * @dataProvider provideGetSubject
  1292. */
  1293. public function testGetSubjectFailed($id)
  1294. {
  1295. $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
  1296. $modelManager
  1297. ->expects($this->once())
  1298. ->method('find')
  1299. ->with('NewsBundle\Entity\Post', $id)
  1300. ->will($this->returnValue(null)); // entity not found
  1301. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1302. $admin->setModelManager($modelManager);
  1303. $admin->setRequest(new Request(array('id' => $id)));
  1304. $this->assertNull($admin->getSubject());
  1305. }
  1306. /**
  1307. * @dataProvider provideGetSubject
  1308. */
  1309. public function testGetSubject($id)
  1310. {
  1311. $entity = new Post();
  1312. $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
  1313. $modelManager
  1314. ->expects($this->once())
  1315. ->method('find')
  1316. ->with('NewsBundle\Entity\Post', $id)
  1317. ->will($this->returnValue($entity));
  1318. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1319. $admin->setModelManager($modelManager);
  1320. $admin->setRequest(new Request(array('id' => $id)));
  1321. $this->assertSame($entity, $admin->getSubject());
  1322. $this->assertSame($entity, $admin->getSubject()); // model manager must be used only once
  1323. }
  1324. public function testGetSubjectWithParentDescription()
  1325. {
  1326. $adminId = 1;
  1327. $comment = new Comment();
  1328. $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
  1329. $modelManager
  1330. ->expects($this->any())
  1331. ->method('find')
  1332. ->with('NewsBundle\Entity\Comment', $adminId)
  1333. ->will($this->returnValue($comment));
  1334. $request = new Request(array('id' => $adminId));
  1335. $postAdmin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1336. $postAdmin->setRequest($request);
  1337. $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'NewsBundle\Entity\Comment', 'SonataNewsBundle:CommentAdmin');
  1338. $commentAdmin->setRequest($request);
  1339. $commentAdmin->setModelManager($modelManager);
  1340. $this->assertEquals($comment, $commentAdmin->getSubject());
  1341. $commentAdmin->setSubject(null);
  1342. $commentAdmin->setParentFieldDescription(new FieldDescription());
  1343. $this->assertNull($commentAdmin->getSubject());
  1344. }
  1345. /**
  1346. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::configureActionButtons
  1347. */
  1348. public function testGetActionButtonsList()
  1349. {
  1350. $expected = array(
  1351. 'create' => array(
  1352. 'template' => 'Foo.html.twig',
  1353. ),
  1354. );
  1355. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1356. $securityHandler = $this->createMock('Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface');
  1357. $securityHandler
  1358. ->expects($this->once())
  1359. ->method('isGranted')
  1360. ->with($admin, 'CREATE', $admin)
  1361. ->will($this->returnValue(true));
  1362. $admin->setSecurityHandler($securityHandler);
  1363. $routeGenerator = $this->createMock('Sonata\AdminBundle\Route\RouteGeneratorInterface');
  1364. $routeGenerator
  1365. ->expects($this->once())
  1366. ->method('hasAdminRoute')
  1367. ->with($admin, 'create')
  1368. ->will($this->returnValue(true));
  1369. $admin->setRouteGenerator($routeGenerator);
  1370. $admin->setTemplate('button_create', 'Foo.html.twig');
  1371. $this->assertSame($expected, $admin->getActionButtons('list', null));
  1372. }
  1373. /**
  1374. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::configureActionButtons
  1375. */
  1376. public function testGetActionButtonsListCreateDisabled()
  1377. {
  1378. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1379. $securityHandler = $this->createMock('Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface');
  1380. $securityHandler
  1381. ->expects($this->once())
  1382. ->method('isGranted')
  1383. ->with($admin, 'CREATE', $admin)
  1384. ->will($this->returnValue(false));
  1385. $admin->setSecurityHandler($securityHandler);
  1386. $this->assertSame(array(), $admin->getActionButtons('list', null));
  1387. }
  1388. /**
  1389. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::configureBatchActions
  1390. */
  1391. public function testGetBatchActions()
  1392. {
  1393. $expected = array(
  1394. 'delete' => array(
  1395. 'label' => 'action_delete',
  1396. 'translation_domain' => 'SonataAdminBundle',
  1397. 'ask_confirmation' => true, // by default always true
  1398. ),
  1399. 'foo' => array(
  1400. 'label' => 'action_foo',
  1401. 'translation_domain' => 'SonataAdminBundle',
  1402. ),
  1403. 'bar' => array(
  1404. 'label' => 'batch.label_bar',
  1405. 'translation_domain' => 'SonataAdminBundle',
  1406. ),
  1407. 'baz' => array(
  1408. 'label' => 'action_baz',
  1409. 'translation_domain' => 'AcmeAdminBundle',
  1410. ),
  1411. );
  1412. $pathInfo = new \Sonata\AdminBundle\Route\PathInfoBuilder($this->createMock('Sonata\AdminBundle\Model\AuditManagerInterface'));
  1413. $labelTranslatorStrategy = $this->createMock('Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface');
  1414. $labelTranslatorStrategy->expects($this->any())
  1415. ->method('getLabel')
  1416. ->will($this->returnCallback(function ($label, $context = '', $type = '') {
  1417. return $context.'.'.$type.'_'.$label;
  1418. }));
  1419. $admin = new PostAdmin('sonata.post.admin.model', 'Application\Sonata\FooBundle\Entity\Model', 'SonataFooBundle:ModelAdmin');
  1420. $admin->setRouteBuilder($pathInfo);
  1421. $admin->setTranslationDomain('SonataAdminBundle');
  1422. $admin->setLabelTranslatorStrategy($labelTranslatorStrategy);
  1423. $routeGenerator = $this->createMock('Sonata\AdminBundle\Route\RouteGeneratorInterface');
  1424. $routeGenerator
  1425. ->expects($this->once())
  1426. ->method('hasAdminRoute')
  1427. ->with($admin, 'delete')
  1428. ->will($this->returnValue(true));
  1429. $admin->setRouteGenerator($routeGenerator);
  1430. $securityHandler = $this->createMock('Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface');
  1431. $securityHandler->expects($this->any())
  1432. ->method('isGranted')
  1433. ->will($this->returnCallback(function (AdminInterface $adminIn, $attributes, $object = null) use ($admin) {
  1434. if ($admin == $adminIn && $attributes == 'DELETE') {
  1435. return true;
  1436. }
  1437. return false;
  1438. }));
  1439. $admin->setSecurityHandler($securityHandler);
  1440. $this->assertSame($expected, $admin->getBatchActions());
  1441. }
  1442. /**
  1443. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::showMosaicButton
  1444. */
  1445. public function testShowMosaicButton()
  1446. {
  1447. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1448. $listModes = $admin->getListModes();
  1449. $admin->showMosaicButton(true);
  1450. $this->assertSame($listModes, $admin->getListModes());
  1451. }
  1452. /**
  1453. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::showMosaicButton
  1454. */
  1455. public function testShowMosaicButtonHideMosaic()
  1456. {
  1457. $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
  1458. $listModes = $admin->getListModes();
  1459. $expected['list'] = $listModes['list'];
  1460. $admin->showMosaicButton(false);
  1461. $this->assertSame($expected, $admin->getListModes());
  1462. }
  1463. /**
  1464. * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getDashboardActions
  1465. * @dataProvider provideGetBaseRouteName
  1466. */
  1467. public function testDefaultDashboardActionsArePresent($objFqn, $expected)
  1468. {
  1469. $pathInfo = new \Sonata\AdminBundle\Route\PathInfoBuilder($this->createMock('Sonata\AdminBundle\Model\AuditManagerInterface'));
  1470. $routeGenerator = new DefaultRouteGenerator(
  1471. $this->createMock('Symfony\Component\Routing\RouterInterface'),
  1472. new RoutesCache($this->cacheTempFolder, true)
  1473. );
  1474. $admin = new PostAdmin('sonata.post.admin.post', $objFqn, 'SonataNewsBundle:PostAdmin');
  1475. $admin->setRouteBuilder($pathInfo);
  1476. $admin->setRouteGenerator($routeGenerator);
  1477. $admin->initialize();
  1478. $securityHandler = $this->createMock('Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface');
  1479. $securityHandler->expects($this->any())
  1480. ->method('isGranted')
  1481. ->will($this->returnCallback(function (AdminInterface $adminIn, $attributes, $object = null) use ($admin) {
  1482. if ($admin == $adminIn && ($attributes == 'CREATE' || $attributes == 'LIST')) {
  1483. return true;
  1484. }
  1485. return false;
  1486. }));
  1487. $admin->setSecurityHandler($securityHandler);
  1488. $this->assertArrayHasKey('list', $admin->getDashboardActions());
  1489. $this->assertArrayHasKey('create', $admin->getDashboardActions());
  1490. }
  1491. public function testDefaultFilters()
  1492. {
  1493. $admin = new FilteredAdmin('sonata.post.admin.model', 'Application\Sonata\FooBundle\Entity\Model', 'SonataFooBundle:ModelAdmin');
  1494. $subjectId = uniqid();
  1495. $request = $this->createMock('Symfony\Component\HttpFoundation\Request', array('get'));
  1496. $query = $this->createMock('Symfony\Component\HttpFoundation\ParameterBag', array('set', 'get'));
  1497. $query->expects($this->any())
  1498. ->method('get')
  1499. ->with($this->equalTo('filter'))
  1500. ->will($this->returnValue(array(
  1501. 'a' => array(
  1502. 'value' => 'b',
  1503. ),
  1504. 'foo' => array(
  1505. 'type' => '1',
  1506. 'value' => 'bar',
  1507. ),
  1508. 'baz' => array(
  1509. 'type' => '5',
  1510. 'value' => 'test',
  1511. ),
  1512. )));
  1513. $request->query = $query;
  1514. $request->expects($this->any())
  1515. ->method('get')
  1516. ->will($this->returnValue($subjectId));
  1517. $admin->setRequest($request);
  1518. $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
  1519. $modelManager->expects($this->any())
  1520. ->method('getDefaultSortValues')
  1521. ->will($this->returnValue(array()));
  1522. $admin->setModelManager($modelManager);
  1523. $this->assertEquals(array(
  1524. 'foo' => array(
  1525. 'type' => '1',
  1526. 'value' => 'bar',
  1527. ),
  1528. 'baz' => array(
  1529. 'type' => '5',
  1530. 'value' => 'test',
  1531. ),
  1532. '_page' => 1,
  1533. '_per_page' => 32,
  1534. 'a' => array(
  1535. 'value' => 'b',
  1536. ),
  1537. ), $admin->getFilterParameters());
  1538. $this->assertTrue($admin->isDefaultFilter('foo'));
  1539. $this->assertFalse($admin->isDefaultFilter('bar'));
  1540. $this->assertFalse($admin->isDefaultFilter('a'));
  1541. }
  1542. /**
  1543. * @group legacy
  1544. */
  1545. public function testDefaultBreadcrumbsBuilder()
  1546. {
  1547. $container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface');
  1548. $container->expects($this->once())
  1549. ->method('getParameter')
  1550. ->with('sonata.admin.configuration.breadcrumbs')
  1551. ->will($this->returnValue(array()));
  1552. $pool = $this->getMockBuilder('Sonata\AdminBundle\Admin\Pool')
  1553. ->disableOriginalConstructor()
  1554. ->getMock();
  1555. $pool->expects($this->once())
  1556. ->method('getContainer')
  1557. ->will($this->returnValue($container));
  1558. $admin = $this->getMockForAbstractClass('Sonata\AdminBundle\Admin\AbstractAdmin', array(
  1559. 'admin.my_code', 'My\Class', 'MyBundle:ClassAdmin',
  1560. ), '', true, true, true, array('getConfigurationPool'));
  1561. $admin->expects($this->once())
  1562. ->method('getConfigurationPool')
  1563. ->will($this->returnValue($pool));
  1564. $this->assertInstanceOf(
  1565. 'Sonata\AdminBundle\Admin\BreadcrumbsBuilder',
  1566. $admin->getBreadcrumbsBuilder()
  1567. );
  1568. }
  1569. /**
  1570. * @group legacy
  1571. */
  1572. public function testBreadcrumbsBuilderSetter()
  1573. {
  1574. $admin = $this->getMockForAbstractClass('Sonata\AdminBundle\Admin\AbstractAdmin', array(
  1575. 'admin.my_code', 'My\Class', 'MyBundle:ClassAdmin',
  1576. ));
  1577. $this->assertSame($admin, $admin->setBreadcrumbsBuilder($builder = $this->createMock(
  1578. 'Sonata\AdminBundle\Admin\BreadcrumbsBuilderInterface'
  1579. )));
  1580. $this->assertSame($builder, $admin->getBreadcrumbsBuilder());
  1581. }
  1582. /**
  1583. * @group legacy
  1584. */
  1585. public function testGetBreadcrumbs()
  1586. {
  1587. $admin = $this->getMockForAbstractClass('Sonata\AdminBundle\Admin\AbstractAdmin', array(
  1588. 'admin.my_code', 'My\Class', 'MyBundle:ClassAdmin',
  1589. ));
  1590. $builder = $this->prophesize(
  1591. 'Sonata\AdminBundle\Admin\BreadcrumbsBuilderInterface'
  1592. );
  1593. $action = 'myaction';
  1594. $builder->getBreadcrumbs($admin, $action)->shouldBeCalled();
  1595. $admin->setBreadcrumbsBuilder($builder->reveal())->getBreadcrumbs($action);
  1596. }
  1597. /**
  1598. * @group legacy
  1599. */
  1600. public function testBuildBreadcrumbs()
  1601. {
  1602. $admin = $this->getMockForAbstractClass('Sonata\AdminBundle\Admin\AbstractAdmin', array(
  1603. 'admin.my_code', 'My\Class', 'MyBundle:ClassAdmin',
  1604. ));
  1605. $builder = $this->prophesize(
  1606. 'Sonata\AdminBundle\Admin\BreadcrumbsBuilderInterface'
  1607. );
  1608. $action = 'myaction';
  1609. $menu = $this->createMock('Knp\Menu\ItemInterface');
  1610. $builder->buildBreadcrumbs($admin, $action, $menu)
  1611. ->shouldBeCalledTimes(1)
  1612. ->willReturn($menu);
  1613. $admin->setBreadcrumbsBuilder($builder->reveal());
  1614. /* check the called is proxied only once */
  1615. $this->assertSame($menu, $admin->buildBreadcrumbs($action, $menu));
  1616. $this->assertSame($menu, $admin->buildBreadcrumbs($action, $menu));
  1617. }
  1618. /**
  1619. * NEXT_MAJOR: remove this method.
  1620. *
  1621. * @group legacy
  1622. */
  1623. public function testCreateQueryLegacyCallWorks()
  1624. {
  1625. $admin = $this->getMockForAbstractClass('Sonata\AdminBundle\Admin\AbstractAdmin', array(
  1626. 'admin.my_code', 'My\Class', 'MyBundle:ClassAdmin',
  1627. ));
  1628. $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
  1629. $modelManager->expects($this->once())
  1630. ->method('createQuery')
  1631. ->with('My\Class')
  1632. ->willReturn('a query');
  1633. $admin->setModelManager($modelManager);
  1634. $this->assertSame('a query', $admin->createQuery('list'));
  1635. }
  1636. public function testGetDataSourceIterator()
  1637. {
  1638. $datagrid = $this->createMock('Sonata\AdminBundle\Datagrid\DatagridInterface');
  1639. $datagrid->method('buildPager');
  1640. $modelManager = $this->createMock('Sonata\AdminBundle\Model\ModelManagerInterface');
  1641. $modelManager->method('getExportFields')->will($this->returnValue(array(
  1642. 'field',
  1643. 'foo',
  1644. 'bar',
  1645. )));
  1646. $modelManager->expects($this->once())->method('getDataSourceIterator')
  1647. ->with($this->equalTo($datagrid), $this->equalTo(array(
  1648. 'Feld' => 'field',
  1649. 1 => 'foo',
  1650. 2 => 'bar',
  1651. )));
  1652. $admin = $this->getMockBuilder('Sonata\AdminBundle\Admin\AbstractAdmin')
  1653. ->disableOriginalConstructor()
  1654. ->setMethods(array('getDatagrid', 'getTranslationLabel', 'trans'))
  1655. ->getMockForAbstractClass();
  1656. $admin->method('getDatagrid')->will($this->returnValue($datagrid));
  1657. $admin->setModelManager($modelManager);
  1658. $admin->expects($this->any())
  1659. ->method('getTranslationLabel')
  1660. ->will($this->returnCallback(function ($label, $context = '', $type = '') {
  1661. return $context.'.'.$type.'_'.$label;
  1662. }));
  1663. $admin->expects($this->any())
  1664. ->method('trans')
  1665. ->will($this->returnCallback(function ($label) {
  1666. if ($label == 'export.label_field') {
  1667. return 'Feld';
  1668. }
  1669. return $label;
  1670. }));
  1671. $admin->getDataSourceIterator();
  1672. }
  1673. private function createTagAdmin(Post $post)
  1674. {
  1675. $postAdmin = $this->getMockBuilder('Sonata\AdminBundle\Tests\Fixtures\Admin\PostAdmin')
  1676. ->disableOriginalConstructor()
  1677. ->getMock();
  1678. $postAdmin->expects($this->any())->method('getObject')->will($this->returnValue($post));
  1679. $formBuilder = $this->createMock('Symfony\Component\Form\FormBuilderInterface');
  1680. $formBuilder->expects($this->any())->method('getForm')->will($this->returnValue(null));
  1681. $tagAdmin = $this->getMockBuilder('Sonata\AdminBundle\Tests\Fixtures\Admin\TagAdmin')
  1682. ->setConstructorArgs(array(
  1683. 'admin.tag',
  1684. 'Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\Tag',
  1685. 'MyBundle:MyController',
  1686. ))
  1687. ->setMethods(array('getFormBuilder'))
  1688. ->getMock();
  1689. $tagAdmin->expects($this->any())->method('getFormBuilder')->will($this->returnValue($formBuilder));
  1690. $tagAdmin->setParent($postAdmin);
  1691. $tag = new Tag();
  1692. $tagAdmin->setSubject($tag);
  1693. $request = $this->createMock('Symfony\Component\HttpFoundation\Request');
  1694. $tagAdmin->setRequest($request);
  1695. $configurationPool = $this->getMockBuilder('Sonata\AdminBundle\Admin\Pool')
  1696. ->disableOriginalConstructor()
  1697. ->getMock();
  1698. $configurationPool->expects($this->any())->method('getPropertyAccessor')->will($this->returnValue(PropertyAccess::createPropertyAccessor()));
  1699. $tagAdmin->setConfigurationPool($configurationPool);
  1700. return $tagAdmin;
  1701. }
  1702. }