ActiveVoterTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\Matcher\Voter;
  11. use Knp\Menu\ItemInterface;
  12. use Sonata\AdminBundle\Menu\Matcher\Voter\ActiveVoter;
  13. class ActiveVoterTest extends AbstractVoterTest
  14. {
  15. /**
  16. * {@inheritdoc}
  17. */
  18. public function createVoter($dataVoter, $route)
  19. {
  20. return new ActiveVoter();
  21. }
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public function provideData()
  26. {
  27. return array(
  28. 'active' => array(true, null, true, true),
  29. 'no active' => array(false, null, false, false),
  30. 'null' => array(null, null, null, null),
  31. );
  32. }
  33. /**
  34. * @param mixed $data
  35. *
  36. * @return ItemInterface
  37. */
  38. protected function createItem($data)
  39. {
  40. $item = $this->getMockForAbstractClass('Knp\Menu\ItemInterface');
  41. $item->expects($this->any())
  42. ->method('getExtra')
  43. ->with($this->logicalOr(
  44. $this->equalTo('active'),
  45. $this->equalTo('sonata_admin')
  46. ))
  47. ->will($this->returnCallback(function ($name) use ($data) {
  48. if ('active' === $name) {
  49. return $data;
  50. }
  51. return true;
  52. }))
  53. ;
  54. return $item;
  55. }
  56. }