-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate using shortcut notation for user_model in favor of FQCN
Instead of using shortcut notation for referring a user entity, now we ask for the FQCN which allows us to not use a ManagerRegistry dependency.
- Loading branch information
Showing
4 changed files
with
120 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
use Sonata\AdminBundle\Admin\AbstractAdmin; | ||
use Sonata\AdminBundle\Admin\Pool; | ||
use Sonata\AdminBundle\Command\GenerateObjectAclCommand; | ||
use Sonata\AdminBundle\Tests\Fixtures\Entity\Foo; | ||
use Sonata\AdminBundle\Util\ObjectAclManipulatorInterface; | ||
use Symfony\Bridge\Doctrine\RegistryInterface; | ||
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; | ||
|
@@ -26,6 +27,7 @@ | |
use Symfony\Component\Console\Tester\CommandTester; | ||
use Symfony\Component\DependencyInjection\Container; | ||
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; | ||
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity; | ||
|
||
/** | ||
* @author Javier Spagnoletti <[email protected]> | ||
|
@@ -203,4 +205,81 @@ public function testExecuteWithManipulator(): void | |
$commandTester = new CommandTester($command); | ||
$commandTester->execute(['command' => $command->getName()]); | ||
} | ||
|
||
/** | ||
* NEXT_MAJOR: Remove this test. | ||
* | ||
* @group legacy | ||
*/ | ||
public function testExecuteWithDeprecatedUserModelNotation(): void | ||
{ | ||
$pool = new Pool($this->container, '', ''); | ||
|
||
$registry = $this->createStub(ManagerRegistry::class); | ||
$command = new GenerateObjectAclCommand($pool, [], $registry); | ||
|
||
$application = new Application(); | ||
$application->add($command); | ||
|
||
$command = $application->find(GenerateObjectAclCommand::getDefaultName()); | ||
$commandTester = new CommandTester($command); | ||
|
||
$this->expectDeprecation( | ||
'Passing a model shortcut name ("AppBundle:User" given) as "user_model" option is deprecated' | ||
.' since sonata-project/admin-bundle 3.x and will throw an exception in 4.x.' | ||
.' Pass a fully qualified class name instead (e.g. App\Model\User).' | ||
); | ||
$commandTester->execute([ | ||
'command' => $command->getName(), | ||
'--user_model' => 'AppBundle:User', | ||
]); | ||
} | ||
|
||
public function testExecuteWithUserModel(): void | ||
{ | ||
$admin = $this->createStub(AbstractAdmin::class); | ||
$registry = $this->createStub(ManagerRegistry::class); | ||
$pool = $this->createStub(Pool::class); | ||
|
||
$admin | ||
->method('getManagerType') | ||
->willReturn('bar'); | ||
|
||
$pool | ||
->method('getAdminServiceIds') | ||
->willReturn(['acme.admin.foo']); | ||
|
||
$pool | ||
->method('getInstance') | ||
->willReturn($admin); | ||
|
||
$manipulator = $this->createMock(ObjectAclManipulatorInterface::class); | ||
$manipulator | ||
->expects($this->once()) | ||
->method('batchConfigureAcls') | ||
->with( | ||
$this->isInstanceOf(StreamOutput::class), | ||
$admin, | ||
$this->callback(static function (UserSecurityIdentity $userSecurityIdentity): bool { | ||
return Foo::class === $userSecurityIdentity->getClass(); | ||
}) | ||
); | ||
|
||
$aclObjectManipulators = [ | ||
'sonata.admin.manipulator.acl.object.bar' => $manipulator, | ||
]; | ||
|
||
$command = new GenerateObjectAclCommand($pool, $aclObjectManipulators, $registry); | ||
|
||
$application = new Application(); | ||
$application->add($command); | ||
|
||
$command = $application->find(GenerateObjectAclCommand::getDefaultName()); | ||
$commandTester = new CommandTester($command); | ||
$commandTester->execute([ | ||
'command' => $command->getName(), | ||
'--user_model' => Foo::class, | ||
'--object_owner' => true, | ||
]); | ||
} | ||
} |