AnnotationCompilerPassTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. 'on_top' => false,
  52. )
  53. );
  54. }
  55. public function testMinimalAdmin()
  56. {
  57. /*
  58. * @Admin(class="Sonata\AdminBundle\Entity\Foo")
  59. */
  60. $annotation = new Admin();
  61. $annotation->class = 'Sonata\AdminBundle\Entity\Foo';
  62. $meta = new ClassMetadata('Sonata\AdminBundle\Tests\Fixtures\Entity\Foo');
  63. $annotation->processMetadata($meta);
  64. $this->assertSame(
  65. $meta->tags['sonata.admin'][0],
  66. array(
  67. 'manager_type' => 'orm',
  68. 'group' => 'Admin',
  69. 'label' => 'Foo',
  70. 'show_in_dashboard' => true,
  71. 'keep_open' => false,
  72. 'on_top' => false,
  73. )
  74. );
  75. }
  76. public function testAdmin()
  77. {
  78. /*
  79. * @Admin(
  80. * class="Sonata\AdminBundle\Entity\Foo",
  81. * managerType="doctrine_mongodb",
  82. * group="myGroup",
  83. * label="myLabel",
  84. * translationDomain="OMG",
  85. * keepOpen=true,
  86. * onTop=true
  87. * )
  88. */
  89. $annotation = new Admin();
  90. $annotation->class = 'Sonata\AdminBundle\Entity\Foo';
  91. $annotation->managerType = 'doctrine_mongodb';
  92. $annotation->group = 'myGroup';
  93. $annotation->label = 'myLabel';
  94. $annotation->showInDashboard = false;
  95. $annotation->translationDomain = 'OMG';
  96. $annotation->keepOpen = true;
  97. $annotation->onTop = true;
  98. $meta = new ClassMetadata('Sonata\AdminBundle\Tests\Fixtures\Entity\Foo');
  99. $annotation->processMetadata($meta);
  100. $this->assertSame(
  101. $meta->tags['sonata.admin'][0],
  102. array(
  103. 'manager_type' => 'doctrine_mongodb',
  104. 'group' => 'myGroup',
  105. 'label' => 'myLabel',
  106. 'show_in_dashboard' => false,
  107. 'keep_open' => true,
  108. 'on_top' => true,
  109. )
  110. );
  111. $this->assertSame($meta->methodCalls[0], array('setTranslationDomain', array('OMG')));
  112. }
  113. }