TabMenuTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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\Menu\Integration;
  11. use Knp\Menu\MenuFactory;
  12. use Knp\Menu\MenuItem;
  13. use Prophecy\Argument;
  14. class TabMenuTest extends BaseMenuTest
  15. {
  16. protected $translator;
  17. protected function getTemplate()
  18. {
  19. return 'Core/tab_menu_template.html.twig';
  20. }
  21. public function getTranslator()
  22. {
  23. if (isset($this->translator)) {
  24. return $this->translator;
  25. }
  26. return parent::getTranslator();
  27. }
  28. public function testLabelTranslationNominalCase()
  29. {
  30. $translatorProphecy = $this->prophesize(
  31. 'Symfony\Component\Translation\TranslatorInterface'
  32. );
  33. $translatorProphecy
  34. ->trans(
  35. 'some-label',
  36. array(),
  37. Argument::any(), //messages or null
  38. null
  39. )
  40. ->willReturn('my-translation');
  41. $this->translator = $translatorProphecy->reveal();
  42. $factory = new MenuFactory();
  43. $menu = new MenuItem('test-menu', $factory);
  44. $menu->addChild('some-label', array('uri' => '/whatever'));
  45. $this->assertContains('my-translation', $this->renderMenu($menu));
  46. }
  47. public function testLabelTranslationWithParameters()
  48. {
  49. $params = array('my' => 'param');
  50. $translatorProphecy = $this->prophesize(
  51. 'Symfony\Component\Translation\TranslatorInterface'
  52. );
  53. $translatorProphecy
  54. ->trans(
  55. 'some-label',
  56. $params,
  57. Argument::any(), // messages or null
  58. null
  59. )
  60. ->willReturn('my-translation');
  61. $this->translator = $translatorProphecy->reveal();
  62. $factory = new MenuFactory();
  63. $menu = new MenuItem('test-menu', $factory);
  64. $menu->addChild('some-label', array('uri' => '/whatever'))
  65. ->setExtra('translation_params', $params);
  66. $this->assertContains('my-translation', $this->renderMenu($menu));
  67. }
  68. public function testLabelTranslationDomainOverride()
  69. {
  70. $translatorProphecy = $this->prophesize(
  71. 'Symfony\Component\Translation\TranslatorInterface'
  72. );
  73. $translatorProphecy
  74. ->trans('some-label', array(), 'my_local_domain', null)
  75. ->willReturn('my-translation');
  76. $translatorProphecy
  77. ->trans('some-other-label', array(), 'my_global_domain', null)
  78. ->willReturn('my-other-translation');
  79. $this->translator = $translatorProphecy->reveal();
  80. $factory = new MenuFactory();
  81. $menu = new MenuItem('test-menu', $factory);
  82. $menu->setExtra('translation_domain', 'my_global_domain');
  83. $menu->addChild('some-label', array('uri' => '/whatever'))
  84. ->setExtra('translation_domain', 'my_local_domain');
  85. $menu->addChild('some-other-label', array('uri' => '/whatever'));
  86. $html = $this->renderMenu($menu);
  87. $this->assertContains('my-translation', $html);
  88. $this->assertContains('my-other-translation', $html);
  89. }
  90. }