CoreControllerTest.php 4.5 KB

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