CoreControllerTest.php 4.0 KB

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