CoreControllerTest.php 3.2 KB

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