CoreControllerTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. class CoreControllerTest extends \PHPUnit_Framework_TestCase
  18. {
  19. public function testdashboardActionStandardRequest()
  20. {
  21. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  22. $pool = new Pool($container, 'title', 'logo.png');
  23. $pool->setTemplates(array(
  24. 'ajax' => 'ajax.html',
  25. ));
  26. $templating = $this->getMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
  27. $request = new Request();
  28. $values = array(
  29. 'sonata.admin.pool' => $pool,
  30. 'templating' => $templating,
  31. 'request' => $request
  32. );
  33. $container->expects($this->any())->method('get')->will($this->returnCallback(function($id) use ($values) {
  34. return $values[$id];
  35. }));
  36. $controller = new CoreController();
  37. $controller->setContainer($container);
  38. $response = $controller->dashboardAction();
  39. $this->isInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
  40. }
  41. public function testdashboardActionAjaxLayout()
  42. {
  43. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  44. $pool = new Pool($container, 'title', 'logo.png');
  45. $pool->setTemplates(array(
  46. 'ajax' => 'ajax.html',
  47. ));
  48. $templating = $this->getMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
  49. $request = new Request();
  50. $request->headers->set('X-Requested-With', 'XMLHttpRequest');
  51. $values = array(
  52. 'sonata.admin.pool' => $pool,
  53. 'templating' => $templating,
  54. 'request' => $request
  55. );
  56. $container->expects($this->any())->method('get')->will($this->returnCallback(function($id) use ($values) {
  57. return $values[$id];
  58. }));
  59. $controller = new CoreController();
  60. $controller->setContainer($container);
  61. $response = $controller->dashboardAction();
  62. $this->isInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
  63. }
  64. }