Skip to content

Commit

Permalink
Clean NEXT_MAJOR comments of #4542 (#4672)
Browse files Browse the repository at this point in the history
* Clean NEXT_MAJOR comments.

* Fix tests :x
  • Loading branch information
jlamur authored and jordisala1991 committed Sep 29, 2017
1 parent 2e2098a commit 52aca05
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 99 deletions.
49 changes: 2 additions & 47 deletions Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,6 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A
*/
protected $parent = null;

/**
* The base code route refer to the prefix used to generate the route name.
*
* NEXT_MAJOR: remove this attribute.
*
* @deprecated This attribute is deprecated since 3.x and will be removed in 4.0
*
* @var string
*/
protected $baseCodeRoute = '';

/**
* The related parent association, ie if OrderElement has a parent property named order,
* then the $parentAssociationMapping must be a string named `order`.
Expand Down Expand Up @@ -611,9 +600,6 @@ public function initialize()
$this->classnameLabel = substr($this->getClass(), strrpos($this->getClass(), '\\') + 1);
}

// NEXT_MAJOR: Remove this line.
$this->baseCodeRoute = $this->getCode();

$this->configure();
}

Expand Down Expand Up @@ -2242,47 +2228,16 @@ public function getCode()
return $this->code;
}

/**
* NEXT_MAJOR: Remove this function.
*
* @deprecated This method is deprecated since 3.x and will be removed in 4.0
*
* @param string $baseCodeRoute
*/
public function setBaseCodeRoute($baseCodeRoute)
{
@trigger_error(
'The '.__METHOD__.' is deprecated since 3.x and will be removed in 4.0.',
E_USER_DEPRECATED
);

$this->baseCodeRoute = $baseCodeRoute;
}

/**
* {@inheritdoc}
*/
public function getBaseCodeRoute()
{
// NEXT_MAJOR: Uncomment the following lines.
// if ($this->isChild()) {
// return $this->getParent()->getBaseCodeRoute().'|'.$this->getCode();
// }
//
// return $this->getCode();

// NEXT_MAJOR: Remove all the code below.
if ($this->isChild()) {
$parentCode = $this->getParent()->getCode();

if ($this->getParent()->isChild()) {
$parentCode = $this->getParent()->getBaseCodeRoute();
}

return $parentCode.'|'.$this->getCode();
return $this->getParent()->getBaseCodeRoute().'|'.$this->getCode();
}

return $this->baseCodeRoute;
return $this->getCode();
}

/**
Expand Down
10 changes: 1 addition & 9 deletions Route/DefaultRouteGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,7 @@ private function getCode(AdminInterface $admin, $name)
return $name;
}

// NEXT_MAJOR: Uncomment the following line.
// $codePrefix = $admin->getBaseCodeRoute();

// NEXT_MAJOR: Remove next 5 lines.
$codePrefix = $admin->getCode();

if ($admin->isChild()) {
$codePrefix = $admin->getBaseCodeRoute();
}
$codePrefix = $admin->getBaseCodeRoute();

// someone provide a code, so it is a child
if (strpos($name, '.')) {
Expand Down
54 changes: 19 additions & 35 deletions Tests/Admin/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -908,44 +908,28 @@ public function testGetModelManager()
$this->assertSame($modelManager, $admin->getModelManager());
}

/**
* NEXT_MAJOR: remove this method.
*
* @group legacy
*/
public function testGetBaseCodeRoute()
{
$admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
$postAdmin = new PostAdmin(
'sonata.post.admin.post',
'NewsBundle\Entity\Post',
'SonataNewsBundle:PostAdmin'
);
$commentAdmin = new CommentAdmin(
'sonata.post.admin.comment',
'Application\Sonata\NewsBundle\Entity\Comment',
'SonataNewsBundle:CommentAdmin'
);

$this->assertSame($postAdmin->getCode(), $postAdmin->getBaseCodeRoute());

$this->assertSame('', $admin->getBaseCodeRoute());

$admin->setBaseCodeRoute('foo');
$this->assertSame('foo', $admin->getBaseCodeRoute());
}

// NEXT_MAJOR: uncomment this method.
// public function testGetBaseCodeRoute()
// {
// $postAdmin = new PostAdmin(
// 'sonata.post.admin.post',
// 'NewsBundle\Entity\Post',
// 'SonataNewsBundle:PostAdmin'
// );
// $commentAdmin = new CommentAdmin(
// 'sonata.post.admin.comment',
// 'Application\Sonata\NewsBundle\Entity\Comment',
// 'SonataNewsBundle:CommentAdmin'
// );
//
// $this->assertSame($postAdmin->getCode(), $postAdmin->getBaseCodeRoute());
//
// $postAdmin->addChild($commentAdmin);
//
// $this->assertSame(
// 'sonata.post.admin.post|sonata.post.admin.comment',
// $commentAdmin->getBaseCodeRoute()
// );
// }
$postAdmin->addChild($commentAdmin);

$this->assertSame(
'sonata.post.admin.post|sonata.post.admin.comment',
$commentAdmin->getBaseCodeRoute()
);
}

public function testGetRouteGenerator()
{
Expand Down
13 changes: 5 additions & 8 deletions Tests/Route/DefaultRouteGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ public function testGenerateUrl($expected, $name, array $parameters)

$admin = $this->getMockForAbstractClass('Sonata\AdminBundle\Admin\AdminInterface');
$admin->expects($this->any())->method('isChild')->will($this->returnValue(false));
$admin->expects($this->any())->method('getCode')->will($this->returnValue('base.Code.Foo'));
$admin->expects($this->any())->method('getBaseCodeRoute')->will($this->returnValue('base.Code.Foo'));
$admin->expects($this->once())->method('hasParentFieldDescription')->will($this->returnValue(false));
$admin->expects($this->once())->method('hasRequest')->will($this->returnValue(true));
$admin->expects($this->any())->method('getUniqid')->will($this->returnValue('foo_uniqueid'));
$admin->expects($this->any())->method('getCode')->will($this->returnValue('foo_code'));
$admin->expects($this->once())->method('getPersistentParameters')->will($this->returnValue(array('abc' => 'a123', 'efg' => 'e456')));
$admin->expects($this->any())->method('getRoutes')->will($this->returnValue($collection));
$admin->expects($this->any())->method('getExtensions')->will($this->returnValue(array()));
Expand Down Expand Up @@ -103,7 +102,7 @@ public function testGenerateUrlWithException()

$admin = $this->getMockForAbstractClass('Sonata\AdminBundle\Admin\AdminInterface');
$admin->expects($this->any())->method('isChild')->will($this->returnValue(false));
$admin->expects($this->any())->method('getCode')->will($this->returnValue('base.Code.Route'));
$admin->expects($this->any())->method('getBaseCodeRoute')->will($this->returnValue('base.Code.Route'));
$admin->expects($this->once())->method('hasParentFieldDescription')->will($this->returnValue(false));
$admin->expects($this->once())->method('hasRequest')->will($this->returnValue(true));
$admin->expects($this->once())->method('getPersistentParameters')->will($this->returnValue(array()));
Expand Down Expand Up @@ -132,21 +131,19 @@ public function testGenerateUrlChild($type, $expected, $name, array $parameters)

$admin = $this->getMockForAbstractClass('Sonata\AdminBundle\Admin\AdminInterface');
$admin->expects($this->any())->method('isChild')->will($this->returnValue(true));
$admin->expects($this->any())->method('getCode')->will($this->returnValue('base.Code.Child'));
$admin->expects($this->any())->method('getBaseCodeRoute')->will($this->returnValue('base.Code.Parent|base.Code.Child'));
$admin->expects($this->any())->method('getIdParameter')->will($this->returnValue('id'));
$admin->expects($this->any())->method('hasParentFieldDescription')->will($this->returnValue(false));
$admin->expects($this->any())->method('hasRequest')->will($this->returnValue(true));
$admin->expects($this->any())->method('getUniqid')->will($this->returnValue('foo_uniqueid'));
$admin->expects($this->any())->method('getCode')->will($this->returnValue('foo_code'));
$admin->expects($this->any())->method('getPersistentParameters')->will($this->returnValue(array('abc' => 'a123', 'efg' => 'e456')));
$admin->expects($this->any())->method('getRoutes')->will($this->returnValue($childCollection));
$admin->expects($this->any())->method('getExtensions')->will($this->returnValue(array()));

$parentAdmin = $this->getMockForAbstractClass('Sonata\AdminBundle\Admin\AdminInterface');
$parentAdmin->expects($this->any())->method('getIdParameter')->will($this->returnValue('childId'));
$parentAdmin->expects($this->any())->method('getRoutes')->will($this->returnValue($collection));
$parentAdmin->expects($this->any())->method('getCode')->will($this->returnValue('base.Code.Parent'));
$parentAdmin->expects($this->any())->method('getBaseCodeRoute')->will($this->returnValue('base.Code.Parent'));
$parentAdmin->expects($this->any())->method('getExtensions')->will($this->returnValue(array()));

// no request attached in this test, so this will not be used
Expand Down Expand Up @@ -218,11 +215,11 @@ public function testGenerateUrlParentFieldDescription($expected, $name, array $p
$admin = $this->getMockForAbstractClass('Sonata\AdminBundle\Admin\AdminInterface');
$admin->expects($this->any())->method('isChild')->will($this->returnValue(false));
$admin->expects($this->any())->method('getCode')->will($this->returnValue('base.Code.Parent'));
$admin->expects($this->any())->method('getBaseCodeRoute')->will($this->returnValue('base.Code.Parent'));
// embeded admin (not nested ...)
$admin->expects($this->once())->method('hasParentFieldDescription')->will($this->returnValue(true));
$admin->expects($this->once())->method('hasRequest')->will($this->returnValue(true));
$admin->expects($this->any())->method('getUniqid')->will($this->returnValue('foo_uniqueid'));
$admin->expects($this->any())->method('getCode')->will($this->returnValue('foo_code'));
$admin->expects($this->once())->method('getPersistentParameters')->will($this->returnValue(array('abc' => 'a123', 'efg' => 'e456')));
$admin->expects($this->any())->method('getExtensions')->will($this->returnValue(array()));
$admin->expects($this->any())->method('getRoutes')->will($this->returnValue($collection));
Expand Down Expand Up @@ -327,7 +324,7 @@ public function testGenerateUrlLoadCache($expected, $name, array $parameters)

$standaloneAdmin = $this->getMockForAbstractClass('Sonata\AdminBundle\Admin\AdminInterface');
$standaloneAdmin->expects($this->any())->method('isChild')->will($this->returnValue(false));
$standaloneAdmin->expects($this->any())->method('getCode')->will($this->returnValue('base.Code.Child'));
$standaloneAdmin->expects($this->any())->method('getBaseCodeRoute')->will($this->returnValue('base.Code.Child'));
$standaloneAdmin->expects($this->once())->method('hasParentFieldDescription')->will($this->returnValue(false));
$standaloneAdmin->expects($this->once())->method('hasRequest')->will($this->returnValue(true));
$standaloneAdmin->expects($this->any())->method('getUniqid')->will($this->returnValue('foo_uniqueid'));
Expand Down

0 comments on commit 52aca05

Please sign in to comment.