ConfigurationTest.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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;
  11. use Sonata\AdminBundle\DependencyInjection\Configuration;
  12. use Symfony\Component\Config\Definition\Processor;
  13. class ConfigurationTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testOptions()
  16. {
  17. $processor = new Processor();
  18. $config = $processor->processConfiguration(new Configuration(), array());
  19. $this->assertTrue($config['options']['html5_validate']);
  20. $this->assertNull($config['options']['pager_links']);
  21. $this->assertTrue($config['options']['confirm_exit']);
  22. $this->assertTrue($config['options']['use_icheck']);
  23. }
  24. public function testOptionsWithInvalidFormat()
  25. {
  26. $this->setExpectedException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
  27. $processor = new Processor();
  28. $config = $processor->processConfiguration(new Configuration(), array(array(
  29. 'options' => array(
  30. 'html5_validate' => '1',
  31. ),
  32. )));
  33. }
  34. public function testCustomTemplatesPerAdmin()
  35. {
  36. $processor = new Processor();
  37. $config = $processor->processConfiguration(new Configuration(), array(array(
  38. 'admin_services' => array(
  39. 'my_admin_id' => array(
  40. 'templates' => array(
  41. 'form' => array('form.twig.html', 'form_extra.twig.html'),
  42. 'view' => array('user_block' => 'SonataAdminBundle:mycustomtemplate.html.twig'),
  43. 'filter' => array(),
  44. ),
  45. ),
  46. ),
  47. )));
  48. $this->assertSame('SonataAdminBundle:mycustomtemplate.html.twig', $config['admin_services']['my_admin_id']['templates']['view']['user_block']);
  49. }
  50. public function testAdminServicesDefault()
  51. {
  52. $processor = new Processor();
  53. $config = $processor->processConfiguration(new Configuration(), array(array(
  54. 'admin_services' => array('my_admin_id' => array()),
  55. )));
  56. $this->assertSame(array(
  57. 'model_manager' => null,
  58. 'form_contractor' => null,
  59. 'show_builder' => null,
  60. 'list_builder' => null,
  61. 'datagrid_builder' => null,
  62. 'translator' => null,
  63. 'configuration_pool' => null,
  64. 'route_generator' => null,
  65. 'validator' => null,
  66. 'security_handler' => null,
  67. 'label' => null,
  68. 'menu_factory' => null,
  69. 'route_builder' => null,
  70. 'label_translator_strategy' => null,
  71. 'pager_type' => null,
  72. 'templates' => array(
  73. 'form' => array(),
  74. 'filter' => array(),
  75. 'view' => array(),
  76. ),
  77. ), $config['admin_services']['my_admin_id']);
  78. }
  79. public function testDashboardWithoutRoles()
  80. {
  81. $processor = new Processor();
  82. $config = $processor->processConfiguration(new Configuration(), array());
  83. $this->assertEmpty($config['dashboard']['blocks'][0]['roles']);
  84. }
  85. public function testDashboardWithRoles()
  86. {
  87. $processor = new Processor();
  88. $config = $processor->processConfiguration(new Configuration(), array(array(
  89. 'dashboard' => array(
  90. 'blocks' => array(array(
  91. 'roles' => array('ROLE_ADMIN'),
  92. 'type' => 'my.type',
  93. )),
  94. ),
  95. )));
  96. $this->assertSame($config['dashboard']['blocks'][0]['roles'], array('ROLE_ADMIN'));
  97. }
  98. public function testDashboardGroups()
  99. {
  100. $processor = new Processor();
  101. $config = $processor->processConfiguration(new Configuration(), array(array(
  102. 'dashboard' => array(
  103. 'groups' => array(
  104. 'bar' => array(
  105. 'label' => 'foo',
  106. 'icon' => '<i class="fa fa-edit"></i>',
  107. 'items' => array(
  108. 'item1',
  109. 'item2',
  110. array(
  111. 'label' => 'fooLabel',
  112. 'route' => 'fooRoute',
  113. 'route_params' => array('bar' => 'foo'),
  114. ),
  115. array(
  116. 'label' => 'barLabel',
  117. 'route' => 'barRoute',
  118. ),
  119. ),
  120. ),
  121. ),
  122. ),
  123. )));
  124. $this->assertCount(4, $config['dashboard']['groups']['bar']['items']);
  125. $this->assertSame(
  126. $config['dashboard']['groups']['bar']['items'][0],
  127. array(
  128. 'admin' => 'item1',
  129. 'label' => '',
  130. 'route' => '',
  131. 'route_params' => array(),
  132. )
  133. );
  134. $this->assertSame(
  135. $config['dashboard']['groups']['bar']['items'][1],
  136. array(
  137. 'admin' => 'item2',
  138. 'label' => '',
  139. 'route' => '',
  140. 'route_params' => array(),
  141. )
  142. );
  143. $this->assertSame(
  144. $config['dashboard']['groups']['bar']['items'][2],
  145. array(
  146. 'label' => 'fooLabel',
  147. 'route' => 'fooRoute',
  148. 'route_params' => array('bar' => 'foo'),
  149. 'admin' => '',
  150. )
  151. );
  152. $this->assertSame(
  153. $config['dashboard']['groups']['bar']['items'][3],
  154. array(
  155. 'label' => 'barLabel',
  156. 'route' => 'barRoute',
  157. 'route_params' => array(),
  158. 'admin' => '',
  159. )
  160. );
  161. }
  162. public function testDashboardGroupsWithBadItemsParams()
  163. {
  164. $this->setExpectedException('\InvalidArgumentException', 'Expected either parameters "route" and "label" for array items');
  165. $processor = new Processor();
  166. $config = $processor->processConfiguration(new Configuration(), array(array(
  167. 'dashboard' => array(
  168. 'groups' => array(
  169. 'bar' => array(
  170. 'label' => 'foo',
  171. 'icon' => '<i class="fa fa-edit"></i>',
  172. 'items' => array(
  173. 'item1',
  174. 'item2',
  175. array(
  176. 'route' => 'fooRoute',
  177. ),
  178. ),
  179. ),
  180. ),
  181. ),
  182. )));
  183. }
  184. }