AnnotationCompilerPassTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. array(
  45. 'manager_type' => 'orm',
  46. 'group' => 'Admin',
  47. 'label' => 'Tests\Fixtures\Foo',
  48. 'show_in_dashboard' => false,
  49. 'keep_open' => false,
  50. 'on_top' => false,
  51. ),
  52. $meta->tags['sonata.admin'][0]
  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. array(
  66. 'manager_type' => 'orm',
  67. 'group' => 'Admin',
  68. 'label' => 'Foo',
  69. 'show_in_dashboard' => true,
  70. 'keep_open' => false,
  71. 'on_top' => false,
  72. ),
  73. $meta->tags['sonata.admin'][0]
  74. );
  75. }
  76. public function testIdForAdmin()
  77. {
  78. /*
  79. * @Admin(class="Sonata\AdminBundle\Entity\Foo", id="my.id")
  80. */
  81. $annotation = new Admin();
  82. $annotation->class = 'Sonata\AdminBundle\Entity\Foo';
  83. $annotation->id = 'my.id';
  84. $meta = new ClassMetadata('Sonata\AdminBundle\Tests\Fixtures\Entity\Foo');
  85. $annotation->processMetadata($meta);
  86. $this->assertSame('my.id', $meta->id);
  87. }
  88. public function testAdmin()
  89. {
  90. /*
  91. * @Admin(
  92. * class="Sonata\AdminBundle\Entity\Foo",
  93. * managerType="doctrine_mongodb",
  94. * group="myGroup",
  95. * label="myLabel",
  96. * translationDomain="OMG",
  97. * keepOpen=true,
  98. * onTop=true
  99. * )
  100. */
  101. $annotation = new Admin();
  102. $annotation->class = 'Sonata\AdminBundle\Entity\Foo';
  103. $annotation->managerType = 'doctrine_mongodb';
  104. $annotation->group = 'myGroup';
  105. $annotation->label = 'myLabel';
  106. $annotation->showInDashboard = false;
  107. $annotation->translationDomain = 'OMG';
  108. $annotation->keepOpen = true;
  109. $annotation->onTop = true;
  110. $meta = new ClassMetadata('Sonata\AdminBundle\Tests\Fixtures\Entity\Foo');
  111. $annotation->processMetadata($meta);
  112. $this->assertSame(
  113. array(
  114. 'manager_type' => 'doctrine_mongodb',
  115. 'group' => 'myGroup',
  116. 'label' => 'myLabel',
  117. 'show_in_dashboard' => false,
  118. 'keep_open' => true,
  119. 'on_top' => true,
  120. ),
  121. $meta->tags['sonata.admin'][0]
  122. );
  123. $this->assertSame(array('setTranslationDomain', array('OMG')), $meta->methodCalls[0]);
  124. }
  125. }