|
@@ -25,6 +25,9 @@ use Symfony\Component\HttpFoundation\Request;
|
|
|
*/
|
|
|
class BreadcrumbsBuilderTest extends \PHPUnit_Framework_TestCase
|
|
|
{
|
|
|
+ /**
|
|
|
+ * @group legacy
|
|
|
+ */
|
|
|
public function testGetBreadcrumbs()
|
|
|
{
|
|
|
$class = 'Application\Sonata\NewsBundle\Entity\Post';
|
|
@@ -187,6 +190,9 @@ class BreadcrumbsBuilderTest extends \PHPUnit_Framework_TestCase
|
|
|
$commentAdmin->getBreadcrumbs('reply');
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @group legacy
|
|
|
+ */
|
|
|
public function testGetBreadcrumbsWithNoCurrentAdmin()
|
|
|
{
|
|
|
$class = 'Application\Sonata\NewsBundle\Entity\Post';
|
|
@@ -217,12 +223,12 @@ class BreadcrumbsBuilderTest extends \PHPUnit_Framework_TestCase
|
|
|
$admin->setLabelTranslatorStrategy($translatorStrategy);
|
|
|
$admin->setRouteGenerator($routeGenerator);
|
|
|
|
|
|
- $menuFactory->expects($this->exactly(2))
|
|
|
+ $menuFactory->expects($this->any())
|
|
|
->method('createItem')
|
|
|
->with('root')
|
|
|
->will($this->returnValue($menu));
|
|
|
|
|
|
- $translatorStrategy->expects($this->exactly(5))
|
|
|
+ $translatorStrategy->expects($this->any())
|
|
|
->method('getLabel')
|
|
|
->withConsecutive(
|
|
|
array('dashboard'),
|
|
@@ -240,7 +246,7 @@ class BreadcrumbsBuilderTest extends \PHPUnit_Framework_TestCase
|
|
|
'someCoolLabel'
|
|
|
));
|
|
|
|
|
|
- $menu->expects($this->exactly(6))
|
|
|
+ $menu->expects($this->any())
|
|
|
->method('addChild')
|
|
|
->withConsecutive(
|
|
|
array('someLabel'),
|
|
@@ -259,39 +265,117 @@ class BreadcrumbsBuilderTest extends \PHPUnit_Framework_TestCase
|
|
|
$this->assertSame($flagBreadcrumb, $admin->getBreadcrumbs('flag'));
|
|
|
}
|
|
|
|
|
|
- public function testUnitGetBreadCrumbs()
|
|
|
+ public function testUnitChildGetBreadCrumbs()
|
|
|
{
|
|
|
- $root = $this->prophesize('Knp\Menu\ItemInterface');
|
|
|
- $breadcrumbs = $this->prophesize('Knp\Menu\ItemInterface');
|
|
|
- $breadcrumbs->getParent()->willreturn($root);
|
|
|
- $breadcrumbs = $breadcrumbs->reveal();
|
|
|
+ $menu = $this->prophesize('Knp\Menu\ItemInterface');
|
|
|
+ $menu->getParent()->willReturn(null);
|
|
|
+
|
|
|
+ $dashboardMenu = $this->prophesize('Knp\Menu\ItemInterface');
|
|
|
+ $dashboardMenu->getParent()->willReturn($menu);
|
|
|
+
|
|
|
+ $adminListMenu = $this->prophesize('Knp\Menu\ItemInterface');
|
|
|
+ $adminListMenu->getParent()->willReturn($dashboardMenu);
|
|
|
+
|
|
|
+ $adminSubjectMenu = $this->prophesize('Knp\Menu\ItemInterface');
|
|
|
+ $adminSubjectMenu->getParent()->willReturn($adminListMenu);
|
|
|
+
|
|
|
+ $childMenu = $this->prophesize('Knp\Menu\ItemInterface');
|
|
|
+ $childMenu->getParent()->willReturn($adminSubjectMenu);
|
|
|
+
|
|
|
+ $leafMenu = $this->prophesize('Knp\Menu\ItemInterface');
|
|
|
+ $leafMenu->getParent()->willReturn($childMenu);
|
|
|
+
|
|
|
$action = 'my_action';
|
|
|
$breadcrumbsBuilder = new BreadcrumbsBuilder();
|
|
|
$admin = $this->prophesize('Sonata\AdminBundle\Admin\AbstractAdmin');
|
|
|
$admin->isChild()->willReturn(false);
|
|
|
- $admin->buildBreadcrumbs($action)->willReturn($breadcrumbs);
|
|
|
- $this->assertSame(array($breadcrumbs), $breadcrumbsBuilder->getBreadcrumbs(
|
|
|
- $admin->reveal(),
|
|
|
- $action
|
|
|
- ));
|
|
|
- }
|
|
|
|
|
|
- public function testUnitChildGetBreadCrumbs()
|
|
|
- {
|
|
|
- $parentMenu = 'parent menu';
|
|
|
+ $menuFactory = $this->prophesize('Knp\Menu\MenuFactory');
|
|
|
+ $menuFactory->createItem('root')->willReturn($menu);
|
|
|
+ $admin->getMenuFactory()->willReturn($menuFactory);
|
|
|
+ $labelTranslatorStrategy = $this->prophesize(
|
|
|
+ 'Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface'
|
|
|
+ );
|
|
|
+ $labelTranslatorStrategy->getLabel(
|
|
|
+ 'dashboard',
|
|
|
+ 'breadcrumb',
|
|
|
+ 'link'
|
|
|
+ )->willReturn('Dashboard');
|
|
|
+ $admin->trans('Dashboard', array(), 'SonataAdminBundle')->willReturn(
|
|
|
+ 'Tableau de bord'
|
|
|
+ );
|
|
|
|
|
|
- $action = 'my_action';
|
|
|
- $breadcrumbsBuilder = new BreadcrumbsBuilder();
|
|
|
- $parentAdmin = $this->prophesize('Sonata\AdminBundle\Admin\AbstractAdmin');
|
|
|
- $parentAdmin->getBreadcrumbs($action)->willReturn($parentMenu);
|
|
|
- $admin = $this->prophesize('Sonata\AdminBundle\Admin\AbstractAdmin');
|
|
|
- $admin->isChild()->willReturn(true);
|
|
|
- $admin->getParent()->willReturn($parentAdmin->reveal());
|
|
|
+ $routeGenerator = $this->prophesize('Sonata\AdminBundle\Route\RouteGeneratorInterface');
|
|
|
+ $routeGenerator->generate('sonata_admin_dashboard')->willReturn('/dashboard');
|
|
|
+
|
|
|
+ $admin->getRouteGenerator()->willReturn($routeGenerator->reveal());
|
|
|
+ $menu->addChild('Tableau de bord', array('uri' => '/dashboard'))->willReturn(
|
|
|
+ $dashboardMenu->reveal()
|
|
|
+ );
|
|
|
+ $labelTranslatorStrategy->getLabel(
|
|
|
+ 'my_class_name_list',
|
|
|
+ 'breadcrumb',
|
|
|
+ 'link'
|
|
|
+ )->willReturn('My class');
|
|
|
+ $labelTranslatorStrategy->getLabel(
|
|
|
+ 'my_child_class_name_list',
|
|
|
+ 'breadcrumb',
|
|
|
+ 'link'
|
|
|
+ )->willReturn('My child class');
|
|
|
+ $childAdmin = $this->prophesize('Sonata\AdminBundle\Admin\AbstractAdmin');
|
|
|
+ $childAdmin->isChild()->willReturn(true);
|
|
|
+ $childAdmin->getParent()->willReturn($admin->reveal());
|
|
|
+ $childAdmin->getLabelTranslatorStrategy()
|
|
|
+ ->shouldBeCalled()
|
|
|
+ ->willReturn($labelTranslatorStrategy->reveal());
|
|
|
+ $childAdmin->getClassnameLabel()->willReturn('my_child_class_name');
|
|
|
+ $childAdmin->hasRoute('list')->willReturn(true);
|
|
|
+ $childAdmin->isGranted('LIST')->willReturn(true);
|
|
|
+ $childAdmin->generateUrl('list')->willReturn('/myadmin/my-object/mychildadmin/list');
|
|
|
+ $childAdmin->trans('My child class', array(), null)->willReturn('Ma classe fille');
|
|
|
+ $childAdmin->getCurrentChildAdmin()->willReturn(null);
|
|
|
+ $childAdmin->hasSubject()->willReturn(true);
|
|
|
+ $childAdmin->getSubject()->willReturn('my subject');
|
|
|
+ $childAdmin->toString('my subject')->willReturn('My subject');
|
|
|
|
|
|
- $this->assertSame(
|
|
|
- 'parent menu',
|
|
|
- $breadcrumbsBuilder->getBreadcrumbs($admin->reveal(), $action)
|
|
|
+ $admin->trans('My class', array(), null)->willReturn('Ma classe');
|
|
|
+ $admin->hasRoute('list')->willReturn(true);
|
|
|
+ $admin->isGranted('LIST')->willReturn(true);
|
|
|
+ $admin->generateUrl('list')->willReturn('/myadmin/list');
|
|
|
+ $admin->getCurrentChildAdmin()->willReturn($childAdmin->reveal());
|
|
|
+ $request = $this->prophesize('Symfony\Component\HttpFoundation\Request');
|
|
|
+ $request->get('slug')->willReturn('my-object');
|
|
|
+
|
|
|
+ $admin->getIdParameter()->willReturn('slug');
|
|
|
+ $admin->hasRoute('edit')->willReturn(true);
|
|
|
+ $admin->isGranted('EDIT')->willReturn(true);
|
|
|
+ $admin->generateUrl('edit', array('id' => 'my-object'))->willReturn('/myadmin/my-object');
|
|
|
+ $admin->getRequest()->willReturn($request->reveal());
|
|
|
+ $admin->hasSubject()->willReturn(true);
|
|
|
+ $admin->getSubject()->willReturn('my subject');
|
|
|
+ $admin->toString('my subject')->willReturn('My subject');
|
|
|
+ $admin->getLabelTranslatorStrategy()->willReturn(
|
|
|
+ $labelTranslatorStrategy->reveal()
|
|
|
);
|
|
|
+ $admin->getClassnameLabel()->willReturn('my_class_name');
|
|
|
+
|
|
|
+ $dashboardMenu->addChild('Ma classe', array(
|
|
|
+ 'uri' => '/myadmin/list',
|
|
|
+ ))->shouldBeCalled()->willReturn($adminListMenu->reveal());
|
|
|
+
|
|
|
+ $adminListMenu->addChild('My subject', array(
|
|
|
+ 'uri' => '/myadmin/my-object',
|
|
|
+ ))->shouldBeCalled()->willReturn($adminSubjectMenu->reveal());
|
|
|
+
|
|
|
+ $adminSubjectMenu->addChild('Ma classe fille', array(
|
|
|
+ 'uri' => '/myadmin/my-object/mychildadmin/list',
|
|
|
+ ))->shouldBeCalled()->willReturn($childMenu->reveal());
|
|
|
+
|
|
|
+ $childMenu->addChild('My subject')
|
|
|
+ ->shouldBeCalled()->willReturn($leafMenu->reveal());
|
|
|
+
|
|
|
+ $breadcrumbs = $breadcrumbsBuilder->getBreadcrumbs($childAdmin->reveal(), $action);
|
|
|
+ $this->assertCount(5, $breadcrumbs);
|
|
|
}
|
|
|
|
|
|
public function actionProvider()
|
|
@@ -339,6 +423,16 @@ class BreadcrumbsBuilderTest extends \PHPUnit_Framework_TestCase
|
|
|
'breadcrumb',
|
|
|
'link'
|
|
|
)->willReturn('My class');
|
|
|
+ $labelTranslatorStrategy->getLabel(
|
|
|
+ 'my_child_class_name_list',
|
|
|
+ 'breadcrumb',
|
|
|
+ 'link'
|
|
|
+ )->willReturn('My child class');
|
|
|
+ $labelTranslatorStrategy->getLabel(
|
|
|
+ 'my_child_class_name_my_action',
|
|
|
+ 'breadcrumb',
|
|
|
+ 'link'
|
|
|
+ )->willReturn('My action');
|
|
|
if ($action == 'create') {
|
|
|
$labelTranslatorStrategy->getLabel(
|
|
|
'my_class_name_create',
|
|
@@ -349,6 +443,13 @@ class BreadcrumbsBuilderTest extends \PHPUnit_Framework_TestCase
|
|
|
$menu->addChild('Créer mon objet', array())->willReturn($menu);
|
|
|
}
|
|
|
$childAdmin = $this->prophesize('Sonata\AdminBundle\Admin\AbstractAdmin');
|
|
|
+ $childAdmin->getLabelTranslatorStrategy()->willReturn($labelTranslatorStrategy->reveal());
|
|
|
+ $childAdmin->getClassnameLabel()->willReturn('my_child_class_name');
|
|
|
+ $childAdmin->hasRoute('list')->willReturn(false);
|
|
|
+ $childAdmin->trans('My child class', array(), null)->willReturn('Ma classe fille');
|
|
|
+ $childAdmin->trans('My action', array(), null)->willReturn('Mon action');
|
|
|
+ $childAdmin->getCurrentChildAdmin()->willReturn(null);
|
|
|
+ $childAdmin->hasSubject()->willReturn(false);
|
|
|
|
|
|
$admin->trans('My class', array(), null)->willReturn('Ma classe');
|
|
|
$admin->hasRoute('list')->willReturn(true);
|
|
@@ -380,6 +481,8 @@ class BreadcrumbsBuilderTest extends \PHPUnit_Framework_TestCase
|
|
|
))->willReturn($menu->reveal());
|
|
|
$menu->addChild('My subject')->willReturn($menu);
|
|
|
$menu->addChild('My subject', array('uri' => null))->willReturn($menu);
|
|
|
+ $menu->addChild('Ma classe fille', array('uri' => null))->willReturn($menu);
|
|
|
+ $menu->addChild('Mon action', array())->willReturn($menu);
|
|
|
|
|
|
$breadcrumbsBuilder->buildBreadCrumbs($admin->reveal(), $action);
|
|
|
}
|