CoreControllerTest.php 4.6 KB

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