AnnotationCompilerPassTest.php 3.8 KB

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