CoreControllerTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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\Controller;
  11. use Sonata\AdminBundle\Admin\Pool;
  12. use Sonata\AdminBundle\Controller\CoreController;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpKernel\Kernel;
  15. class CoreControllerTest extends \PHPUnit_Framework_TestCase
  16. {
  17. public function testdashboardActionStandardRequest()
  18. {
  19. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  20. $pool = new Pool($container, 'title', 'logo.png');
  21. $pool->setTemplates(array(
  22. 'ajax' => 'ajax.html',
  23. ));
  24. $templating = $this->getMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
  25. $request = new Request();
  26. $requestStack = null;
  27. if (Kernel::MINOR_VERSION > 3) {
  28. $requestStack = new \Symfony\Component\HttpFoundation\RequestStack();
  29. $requestStack->push($request);
  30. }
  31. $values = array(
  32. 'sonata.admin.pool' => $pool,
  33. 'templating' => $templating,
  34. 'request' => $request,
  35. 'request_stack' => $requestStack,
  36. );
  37. $container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use ($values) {
  38. return $values[$id];
  39. }));
  40. $container->expects($this->any())
  41. ->method('has')
  42. ->will($this->returnCallback(function ($id) {
  43. if ($id == 'templating') {
  44. return true;
  45. }
  46. return false;
  47. }));
  48. $container->expects($this->any())->method('getParameter')->will($this->returnCallback(function ($name) {
  49. if ($name == 'sonata.admin.configuration.dashboard_blocks') {
  50. return array();
  51. }
  52. }));
  53. $controller = new CoreController();
  54. $controller->setContainer($container);
  55. $response = $controller->dashboardAction($request);
  56. $this->isInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
  57. }
  58. public function testdashboardActionAjaxLayout()
  59. {
  60. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  61. $pool = new Pool($container, 'title', 'logo.png');
  62. $pool->setTemplates(array(
  63. 'ajax' => 'ajax.html',
  64. ));
  65. $templating = $this->getMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
  66. $request = new Request();
  67. $request->headers->set('X-Requested-With', 'XMLHttpRequest');
  68. $requestStack = null;
  69. if (Kernel::MINOR_VERSION > 3) {
  70. $requestStack = new \Symfony\Component\HttpFoundation\RequestStack();
  71. $requestStack->push($request);
  72. }
  73. $values = array(
  74. 'sonata.admin.pool' => $pool,
  75. 'templating' => $templating,
  76. 'request' => $request,
  77. 'request_stack' => $requestStack,
  78. );
  79. $container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use ($values) {
  80. return $values[$id];
  81. }));
  82. $container->expects($this->any())
  83. ->method('has')
  84. ->will($this->returnCallback(function ($id) {
  85. if ($id == 'templating') {
  86. return true;
  87. }
  88. return false;
  89. }));
  90. $container->expects($this->any())->method('getParameter')->will($this->returnCallback(function ($name) {
  91. if ($name == 'sonata.admin.configuration.dashboard_blocks') {
  92. return array();
  93. }
  94. }));
  95. $controller = new CoreController();
  96. $controller->setContainer($container);
  97. $response = $controller->dashboardAction($request);
  98. $this->isInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
  99. }
  100. }