CoreControllerTest.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 Sonata\AdminBundle\Tests\Helpers\PHPUnit_Framework_TestCase;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\RequestStack;
  16. class CoreControllerTest extends PHPUnit_Framework_TestCase
  17. {
  18. public function testdashboardActionStandardRequest()
  19. {
  20. $container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface');
  21. $pool = new Pool($container, 'title', 'logo.png');
  22. $pool->setTemplates(array(
  23. 'ajax' => 'ajax.html',
  24. ));
  25. $templating = $this->createMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
  26. $request = new Request();
  27. $requestStack = null;
  28. if (class_exists('Symfony\Component\HttpFoundation\RequestStack')) {
  29. $requestStack = new RequestStack();
  30. $requestStack->push($request);
  31. }
  32. $breadcrumbsBuilder = $this->getMockForAbstractClass('Sonata\AdminBundle\Admin\BreadcrumbsBuilderInterface');
  33. $values = array(
  34. 'sonata.admin.breadcrumbs_builder' => $breadcrumbsBuilder,
  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())
  44. ->method('has')
  45. ->will($this->returnCallback(function ($id) {
  46. if ($id == 'templating') {
  47. return true;
  48. }
  49. return false;
  50. }));
  51. $container->expects($this->any())->method('getParameter')->will($this->returnCallback(function ($name) {
  52. if ($name == 'sonata.admin.configuration.dashboard_blocks') {
  53. return array();
  54. }
  55. }));
  56. $container->expects($this->any())->method('has')->will($this->returnCallback(function ($id) {
  57. if ($id == 'templating') {
  58. return true;
  59. }
  60. return false;
  61. }));
  62. $controller = new CoreController();
  63. $controller->setContainer($container);
  64. $response = $controller->dashboardAction($request);
  65. $this->isInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
  66. }
  67. public function testdashboardActionAjaxLayout()
  68. {
  69. $container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface');
  70. $pool = new Pool($container, 'title', 'logo.png');
  71. $pool->setTemplates(array(
  72. 'ajax' => 'ajax.html',
  73. ));
  74. $templating = $this->createMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
  75. $request = new Request();
  76. $request->headers->set('X-Requested-With', 'XMLHttpRequest');
  77. $requestStack = null;
  78. if (class_exists('Symfony\Component\HttpFoundation\RequestStack')) {
  79. $requestStack = new RequestStack();
  80. $requestStack->push($request);
  81. }
  82. $values = array(
  83. 'sonata.admin.pool' => $pool,
  84. 'templating' => $templating,
  85. 'request' => $request,
  86. 'request_stack' => $requestStack,
  87. );
  88. $container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use ($values) {
  89. return $values[$id];
  90. }));
  91. $container->expects($this->any())
  92. ->method('has')
  93. ->will($this->returnCallback(function ($id) {
  94. if ($id == 'templating') {
  95. return true;
  96. }
  97. return false;
  98. }));
  99. $container->expects($this->any())->method('getParameter')->will($this->returnCallback(function ($name) {
  100. if ($name == 'sonata.admin.configuration.dashboard_blocks') {
  101. return array();
  102. }
  103. }));
  104. $container->expects($this->any())->method('has')->will($this->returnCallback(function ($id) {
  105. if ($id == 'templating') {
  106. return true;
  107. }
  108. return false;
  109. }));
  110. $controller = new CoreController();
  111. $controller->setContainer($container);
  112. $response = $controller->dashboardAction($request);
  113. $this->isInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
  114. }
  115. }