AnnotationCompilerPassTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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\DependencyInjection;
  11. use JMS\DiExtraBundle\Metadata\ClassMetadata;
  12. use Sonata\AdminBundle\Annotation\Admin;
  13. class AnnotationCompilerPassTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testInvalidAdminAnnotation()
  16. {
  17. /*
  18. * @Admin(class="Sonata\AdminBundle\Tests\Fixtures\Foo")
  19. */
  20. $this->setExpectedException(
  21. 'LogicException',
  22. 'Unable to generate admin group and label for class Sonata\AdminBundle\Tests\Fixtures\Foo.'
  23. );
  24. $annotation = new Admin();
  25. $annotation->class = 'Sonata\AdminBundle\Tests\Fixtures\Foo';
  26. $meta = new ClassMetadata('Sonata\AdminBundle\Tests\Fixtures\Entity\Foo');
  27. $annotation->processMetadata($meta);
  28. }
  29. public function testEmbeddedAdmin()
  30. {
  31. /*
  32. * @Admin(
  33. * class="Sonata\Admin\Entity\Tests\Fixtures\Foo",
  34. * showInDashboard=false
  35. * )
  36. */
  37. $annotation = new Admin();
  38. $annotation->class = 'Sonata\Admin\Entity\Tests\Fixtures\Foo';
  39. $annotation->showInDashboard = false;
  40. $meta = new ClassMetadata('Sonata\AdminBundle\Tests\Fixtures\Entity\Foo');
  41. $annotation->processMetadata($meta);
  42. $this->assertSame(
  43. $meta->tags['sonata.admin'][0],
  44. array(
  45. 'manager_type' => 'orm',
  46. 'show_in_dashboard' => false,
  47. )
  48. );
  49. }
  50. public function testMinimalAdmin()
  51. {
  52. /*
  53. * @Admin(class="Sonata\AdminBundle\Entity\Foo")
  54. */
  55. $annotation = new Admin();
  56. $annotation->class = 'Sonata\AdminBundle\Entity\Foo';
  57. $meta = new ClassMetadata('Sonata\AdminBundle\Tests\Fixtures\Entity\Foo');
  58. $annotation->processMetadata($meta);
  59. $this->assertSame(
  60. $meta->tags['sonata.admin'][0],
  61. array(
  62. 'manager_type' => 'orm',
  63. 'group' => 'Admin',
  64. 'label' => 'Foo',
  65. 'show_in_dashboard' => true,
  66. )
  67. );
  68. }
  69. public function testAdmin()
  70. {
  71. /*
  72. * @Admin(
  73. * class="Sonata\AdminBundle\Entity\Foo",
  74. * managerType="doctrine_mongodb",
  75. * group="myGroup",
  76. * label="myLabel",
  77. * translationDomain="OMG"
  78. * )
  79. */
  80. $annotation = new Admin();
  81. $annotation->class = 'Sonata\AdminBundle\Entity\Foo';
  82. $annotation->managerType = 'doctrine_mongodb';
  83. $annotation->group = 'myGroup';
  84. $annotation->label = 'myLabel';
  85. $annotation->showInDashboard = false;
  86. $annotation->translationDomain = 'OMG';
  87. $meta = new ClassMetadata('Sonata\AdminBundle\Tests\Fixtures\Entity\Foo');
  88. $annotation->processMetadata($meta);
  89. $this->assertSame(
  90. $meta->tags['sonata.admin'][0],
  91. array(
  92. 'manager_type' => 'doctrine_mongodb',
  93. 'group' => 'myGroup',
  94. 'label' => 'myLabel',
  95. 'show_in_dashboard' => false,
  96. )
  97. );
  98. $this->assertSame($meta->methodCalls[0], array('setTranslationDomain', array('OMG')));
  99. }
  100. }