CoreControllerTest.php 3.7 KB

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