CoreControllerTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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())->method('getParameter')->will($this->returnCallback(function ($name) {
  41. if ($name == 'sonata.admin.configuration.dashboard_blocks') {
  42. return array();
  43. }
  44. }));
  45. $controller = new CoreController();
  46. $controller->setContainer($container);
  47. $response = $controller->dashboardAction($request);
  48. $this->isInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
  49. }
  50. public function testdashboardActionAjaxLayout()
  51. {
  52. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  53. $pool = new Pool($container, 'title', 'logo.png');
  54. $pool->setTemplates(array(
  55. 'ajax' => 'ajax.html',
  56. ));
  57. $templating = $this->getMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
  58. $request = new Request();
  59. $request->headers->set('X-Requested-With', 'XMLHttpRequest');
  60. $requestStack = null;
  61. if (Kernel::MINOR_VERSION > 3) {
  62. $requestStack = new \Symfony\Component\HttpFoundation\RequestStack();
  63. $requestStack->push($request);
  64. }
  65. $values = array(
  66. 'sonata.admin.pool' => $pool,
  67. 'templating' => $templating,
  68. 'request' => $request,
  69. 'request_stack' => $requestStack,
  70. );
  71. $container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use ($values) {
  72. return $values[$id];
  73. }));
  74. $container->expects($this->any())->method('getParameter')->will($this->returnCallback(function ($name) {
  75. if ($name == 'sonata.admin.configuration.dashboard_blocks') {
  76. return array();
  77. }
  78. }));
  79. $controller = new CoreController();
  80. $controller->setContainer($container);
  81. $response = $controller->dashboardAction($request);
  82. $this->isInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
  83. }
  84. }