GlobalVariablesTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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\Twig;
  11. use Sonata\AdminBundle\Twig\GlobalVariables;
  12. /**
  13. * @author Ahmet Akbana <ahmetakbana@gmail.com>
  14. */
  15. class GlobalVariablesTest extends \PHPUnit_Framework_TestCase
  16. {
  17. private $code;
  18. private $action;
  19. private $admin;
  20. private $pool;
  21. public function setUp()
  22. {
  23. $this->code = 'sonata.page.admin.page|sonata.page.admin.snapshot';
  24. $this->action = 'list';
  25. $this->admin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');
  26. $this->pool = $this->getMockBuilder('Sonata\AdminBundle\Admin\Pool')->disableOriginalConstructor()->getMock();
  27. }
  28. public function testUrl()
  29. {
  30. $this->admin->expects($this->once())
  31. ->method('generateUrl')
  32. ->with('sonata.page.admin.page|sonata.page.admin.snapshot.list', array('foo'), false)
  33. ->willReturn(true);
  34. $this->pool->expects($this->once())
  35. ->method('getAdminByAdminCode')
  36. ->with('sonata.page.admin.page')
  37. ->willReturn($this->admin);
  38. $globalVariables = new GlobalVariables($this->pool);
  39. $globalVariables->url($this->code, $this->action, array('foo'));
  40. }
  41. public function testObjectUrl()
  42. {
  43. $this->admin->expects($this->once())
  44. ->method('generateObjectUrl')
  45. ->with('sonata.page.admin.page|sonata.page.admin.snapshot.list', 'foo', array('bar'), false)
  46. ->willReturn(true);
  47. $this->pool->expects($this->once())
  48. ->method('getAdminByAdminCode')
  49. ->with('sonata.page.admin.page')
  50. ->willReturn($this->admin);
  51. $globalVariables = new GlobalVariables($this->pool);
  52. $globalVariables->objectUrl($this->code, $this->action, 'foo', array('bar'));
  53. }
  54. /**
  55. * @group legacy
  56. * NEXT_MAJOR: remove this method
  57. */
  58. public function testWithContainer()
  59. {
  60. $this->admin->expects($this->once())
  61. ->method('generateUrl')
  62. ->with('sonata.page.admin.page|sonata.page.admin.snapshot.list', array('foo'), false)
  63. ->willReturn(true);
  64. $this->pool->expects($this->once())
  65. ->method('getAdminByAdminCode')
  66. ->with('sonata.page.admin.page')
  67. ->willReturn($this->admin);
  68. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  69. $container->expects($this->once())
  70. ->method('get')
  71. ->with('sonata.admin.pool')
  72. ->willReturn($this->pool);
  73. $globalVariables = new GlobalVariables($container);
  74. $globalVariables->url($this->code, $this->action, array('foo'));
  75. }
  76. /**
  77. * NEXT_MAJOR: remove this method.
  78. */
  79. public function testInvalidArgumentException()
  80. {
  81. $this->setExpectedException(
  82. 'InvalidArgumentException',
  83. '$adminPool should be an instance of Sonata\AdminBundle\Admin\Pool'
  84. );
  85. new GlobalVariables('foo');
  86. }
  87. }