Upgrade 1-11.38

This commit is contained in:
xesmyd
2026-03-30 14:10:30 +02:00
parent f2a7e6d1fc
commit ac648ef29d
24665 changed files with 69682 additions and 2205004 deletions
@@ -11,43 +11,45 @@
namespace Symfony\Component\Security\Acl\Tests\Dbal;
use Symfony\Component\Security\Acl\Dbal\AclProvider;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Dbal\Schema;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Acl\Dbal\AclProvider;
use Symfony\Component\Security\Acl\Dbal\Schema;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
/**
* @group benchmark
*/
class AclProviderBenchmarkTest extends \PHPUnit_Framework_TestCase
class AclProviderBenchmarkTest extends TestCase
{
/** @var \Doctrine\DBAL\Connection */
protected $con;
/** @var Connection */
protected $connection;
protected $insertClassStmt;
protected $insertSidStmt;
protected $insertOidAncestorStmt;
protected $insertOidStmt;
protected $insertEntryStmt;
protected function setUp()
protected function setUp(): void
{
try {
$this->con = DriverManager::getConnection(array(
$this->connection = DriverManager::getConnection([
'driver' => 'pdo_mysql',
'host' => 'localhost',
'user' => 'root',
'dbname' => 'testdb',
));
$this->con->connect();
]);
$this->connection->connect();
} catch (\Exception $e) {
$this->markTestSkipped('Unable to connect to the database: '.$e->getMessage());
}
}
protected function tearDown()
protected function tearDown(): void
{
$this->con = null;
$this->connection = null;
}
public function testFindAcls()
@@ -55,9 +57,9 @@ class AclProviderBenchmarkTest extends \PHPUnit_Framework_TestCase
// $this->generateTestData();
// get some random test object identities from the database
$oids = array();
$stmt = $this->con->executeQuery('SELECT object_identifier, class_type FROM acl_object_identities o INNER JOIN acl_classes c ON c.id = o.class_id ORDER BY RAND() LIMIT 25');
foreach ($stmt->fetchAll() as $oid) {
$oids = [];
$stmt = $this->connection->executeQuery('SELECT object_identifier, class_type FROM acl_object_identities o INNER JOIN acl_classes c ON c.id = o.class_id ORDER BY RAND() LIMIT 25');
foreach ($stmt->fetchAllAssociative() as $oid) {
$oids[] = new ObjectIdentity($oid['object_identifier'], $oid['class_type']);
}
@@ -75,22 +77,22 @@ class AclProviderBenchmarkTest extends \PHPUnit_Framework_TestCase
*/
protected function generateTestData()
{
$sm = $this->con->getSchemaManager();
$sm = $this->connection->createSchemaManager();
$sm->dropAndCreateDatabase('testdb');
$this->con->exec('USE testdb');
$this->connection->executeStatement('USE testdb');
// import the schema
$schema = new Schema($options = $this->getOptions());
foreach ($schema->toSql($this->con->getDatabasePlatform()) as $sql) {
$this->con->exec($sql);
foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) {
$this->connection->executeStatement($sql);
}
// setup prepared statements
$this->insertClassStmt = $this->con->prepare('INSERT INTO acl_classes (id, class_type) VALUES (?, ?)');
$this->insertSidStmt = $this->con->prepare('INSERT INTO acl_security_identities (id, identifier, username) VALUES (?, ?, ?)');
$this->insertOidStmt = $this->con->prepare('INSERT INTO acl_object_identities (id, class_id, object_identifier, parent_object_identity_id, entries_inheriting) VALUES (?, ?, ?, ?, ?)');
$this->insertEntryStmt = $this->con->prepare('INSERT INTO acl_entries (id, class_id, object_identity_id, field_name, ace_order, security_identity_id, mask, granting, granting_strategy, audit_success, audit_failure) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
$this->insertOidAncestorStmt = $this->con->prepare('INSERT INTO acl_object_identity_ancestors (object_identity_id, ancestor_id) VALUES (?, ?)');
$this->insertClassStmt = $this->connection->prepare('INSERT INTO acl_classes (id, class_type) VALUES (?, ?)');
$this->insertSidStmt = $this->connection->prepare('INSERT INTO acl_security_identities (id, identifier, username) VALUES (?, ?, ?)');
$this->insertOidStmt = $this->connection->prepare('INSERT INTO acl_object_identities (id, class_id, object_identifier, parent_object_identity_id, entries_inheriting) VALUES (?, ?, ?, ?, ?)');
$this->insertEntryStmt = $this->connection->prepare('INSERT INTO acl_entries (id, class_id, object_identity_id, field_name, ace_order, security_identity_id, mask, granting, granting_strategy, audit_success, audit_failure) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
$this->insertOidAncestorStmt = $this->connection->prepare('INSERT INTO acl_object_identity_ancestors (object_identity_id, ancestor_id) VALUES (?, ?)');
for ($i = 0; $i < 40000; ++$i) {
$this->generateAclHierarchy();
@@ -99,19 +101,19 @@ class AclProviderBenchmarkTest extends \PHPUnit_Framework_TestCase
protected function generateAclHierarchy()
{
$rootId = $this->generateAcl($this->chooseClassId(), null, array());
$rootId = $this->generateAcl($this->chooseClassId(), null, []);
$this->generateAclLevel(rand(1, 15), $rootId, array($rootId));
$this->generateAclLevel(rand(1, 15), $rootId, [$rootId]);
}
protected function generateAclLevel($depth, $parentId, $ancestors)
{
$level = count($ancestors);
$level = \count($ancestors);
for ($i = 0, $t = rand(1, 10); $i < $t; ++$i) {
$id = $this->generateAcl($this->chooseClassId(), $parentId, $ancestors);
if ($level < $depth) {
$this->generateAclLevel($depth, $id, array_merge($ancestors, array($id)));
$this->generateAclLevel($depth, $id, array_merge($ancestors, [$id]));
}
}
}
@@ -120,8 +122,8 @@ class AclProviderBenchmarkTest extends \PHPUnit_Framework_TestCase
{
static $id = 1000;
if ($id === 1000 || ($id < 1500 && rand(0, 1))) {
$this->insertClassStmt->execute(array($id, $this->getRandomString(rand(20, 100), 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\\_')));
if (1000 === $id || ($id < 1500 && rand(0, 1))) {
$this->insertClassStmt->executeStatement([$id, $this->getRandomString(rand(20, 100), 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\\_')]);
++$id;
return $id - 1;
@@ -134,17 +136,17 @@ class AclProviderBenchmarkTest extends \PHPUnit_Framework_TestCase
{
static $id = 1000;
$this->insertOidStmt->execute(array(
$this->insertOidStmt->executeStatement([
$id,
$classId,
$this->getRandomString(rand(20, 50)),
$parentId,
rand(0, 1),
));
]);
$this->insertOidAncestorStmt->execute(array($id, $id));
$this->insertOidAncestorStmt->executeStatement([$id, $id]);
foreach ($ancestors as $ancestor) {
$this->insertOidAncestorStmt->execute(array($id, $ancestor));
$this->insertOidAncestorStmt->executeStatement([$id, $ancestor]);
}
$this->generateAces($classId, $id);
@@ -157,12 +159,12 @@ class AclProviderBenchmarkTest extends \PHPUnit_Framework_TestCase
{
static $id = 1000;
if ($id === 1000 || ($id < 11000 && rand(0, 1))) {
$this->insertSidStmt->execute(array(
if (1000 === $id || ($id < 11000 && rand(0, 1))) {
$this->insertSidStmt->executeStatement([
$id,
$this->getRandomString(rand(5, 30)),
rand(0, 1),
));
]);
++$id;
return $id - 1;
@@ -175,33 +177,33 @@ class AclProviderBenchmarkTest extends \PHPUnit_Framework_TestCase
{
static $id = 1000;
$sids = array();
$fieldOrder = array();
$sids = [];
$fieldOrder = [];
for ($i = 0; $i <= 30; ++$i) {
$fieldName = rand(0, 1) ? null : $this->getRandomString(rand(10, 20));
do {
$sid = $this->chooseSid();
} while (array_key_exists($sid, $sids) && in_array($fieldName, $sids[$sid], true));
} while (\array_key_exists($sid, $sids) && \in_array($fieldName, $sids[$sid], true));
$fieldOrder[$fieldName] = array_key_exists($fieldName, $fieldOrder) ? $fieldOrder[$fieldName] + 1 : 0;
$fieldOrder[$fieldName] = \array_key_exists($fieldName, $fieldOrder) ? $fieldOrder[$fieldName] + 1 : 0;
if (!isset($sids[$sid])) {
$sids[$sid] = array();
$sids[$sid] = [];
}
$sids[$sid][] = $fieldName;
$strategy = rand(0, 2);
if ($strategy === 0) {
if (0 === $strategy) {
$strategy = PermissionGrantingStrategy::ALL;
} elseif ($strategy === 1) {
} elseif (1 === $strategy) {
$strategy = PermissionGrantingStrategy::ANY;
} else {
$strategy = PermissionGrantingStrategy::EQUAL;
}
// id, cid, oid, field, order, sid, mask, granting, strategy, a success, a failure
$this->insertEntryStmt->execute(array(
$this->insertEntryStmt->executeStatement([
$id,
$classId,
rand(0, 5) ? $objectId : null,
@@ -213,7 +215,7 @@ class AclProviderBenchmarkTest extends \PHPUnit_Framework_TestCase
$strategy,
rand(0, 1),
rand(0, 1),
));
]);
++$id;
}
@@ -235,9 +237,9 @@ class AclProviderBenchmarkTest extends \PHPUnit_Framework_TestCase
protected function getRandomString($length, $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
{
$s = '';
$cLength = strlen($chars);
$cLength = \strlen($chars);
while (strlen($s) < $length) {
while (\strlen($s) < $length) {
$s .= $chars[mt_rand(0, $cLength - 1)];
}
@@ -246,13 +248,13 @@ class AclProviderBenchmarkTest extends \PHPUnit_Framework_TestCase
protected function getOptions()
{
return array(
return [
'oid_table_name' => 'acl_object_identities',
'oid_ancestors_table_name' => 'acl_object_identity_ancestors',
'class_table_name' => 'acl_classes',
'sid_table_name' => 'acl_security_identities',
'entry_table_name' => 'acl_entries',
);
];
}
protected function getStrategy()
@@ -262,6 +264,6 @@ class AclProviderBenchmarkTest extends \PHPUnit_Framework_TestCase
protected function getProvider()
{
return new AclProvider($this->con, $this->getStrategy(), $this->getOptions());
return new AclProvider($this->connection, $this->getStrategy(), $this->getOptions());
}
}
+75 -78
View File
@@ -11,36 +11,33 @@
namespace Symfony\Component\Security\Acl\Tests\Dbal;
use Symfony\Component\Security\Acl\Dbal\AclProvider;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Dbal\Schema;
use Doctrine\DBAL\DriverManager;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Acl\Dbal\AclProvider;
use Symfony\Component\Security\Acl\Dbal\Schema;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
/**
* @requires extension pdo_sqlite
*/
class AclProviderTest extends \PHPUnit_Framework_TestCase
class AclProviderTest extends TestCase
{
protected $con;
protected $insertClassStmt;
protected $insertEntryStmt;
protected $insertOidStmt;
protected $insertOidAncestorStmt;
protected $insertSidStmt;
private $connection;
/**
* @expectedException \Symfony\Component\Security\Acl\Exception\AclNotFoundException
* @expectedMessage There is no ACL for the given object identity.
*/
public function testFindAclThrowsExceptionWhenNoAclExists()
{
$this->expectException(\Symfony\Component\Security\Acl\Exception\AclNotFoundException::class);
$this->getProvider()->findAcl(new ObjectIdentity('foo', 'foo'));
}
public function testFindAclsThrowsExceptionUnlessAnACLIsFoundForEveryOID()
{
$oids = array();
$oids = [];
$oids[] = new ObjectIdentity('1', 'foo');
$oids[] = new ObjectIdentity('foo', 'foo');
@@ -60,7 +57,7 @@ class AclProviderTest extends \PHPUnit_Framework_TestCase
public function testFindAcls()
{
$oids = array();
$oids = [];
$oids[] = new ObjectIdentity('1', 'foo');
$oids[] = new ObjectIdentity('2', 'foo');
@@ -77,7 +74,7 @@ class AclProviderTest extends \PHPUnit_Framework_TestCase
public function testFindAclsWithDifferentTypes()
{
$oids = array();
$oids = [];
$oids[] = new ObjectIdentity('123', 'Bundle\SomeVendor\MyBundle\Entity\SomeEntity');
$oids[] = new ObjectIdentity('123', 'Bundle\MyBundle\Entity\AnotherEntity');
@@ -142,49 +139,49 @@ class AclProviderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('SomeClass', $sid->getClass());
}
protected function setUp()
protected function setUp(): void
{
$this->con = DriverManager::getConnection(array(
$this->connection = DriverManager::getConnection([
'driver' => 'pdo_sqlite',
'memory' => true,
));
]);
// import the schema
$schema = new Schema($options = $this->getOptions());
foreach ($schema->toSql($this->con->getDatabasePlatform()) as $sql) {
$this->con->exec($sql);
$schema = new Schema($this->getOptions());
foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) {
$this->connection->executeStatement($sql);
}
// populate the schema with some test data
$this->insertClassStmt = $this->con->prepare('INSERT INTO acl_classes (id, class_type) VALUES (?, ?)');
$insertClassStmt = $this->connection->prepare('INSERT INTO acl_classes (id, class_type) VALUES (?, ?)');
foreach ($this->getClassData() as $data) {
$this->insertClassStmt->execute($data);
$insertClassStmt->executeStatement($data);
}
$this->insertSidStmt = $this->con->prepare('INSERT INTO acl_security_identities (id, identifier, username) VALUES (?, ?, ?)');
$insertSidStmt = $this->connection->prepare('INSERT INTO acl_security_identities (id, identifier, username) VALUES (?, ?, ?)');
foreach ($this->getSidData() as $data) {
$this->insertSidStmt->execute($data);
$insertSidStmt->executeStatement($data);
}
$this->insertOidStmt = $this->con->prepare('INSERT INTO acl_object_identities (id, class_id, object_identifier, parent_object_identity_id, entries_inheriting) VALUES (?, ?, ?, ?, ?)');
$insertOidStmt = $this->connection->prepare('INSERT INTO acl_object_identities (id, class_id, object_identifier, parent_object_identity_id, entries_inheriting) VALUES (?, ?, ?, ?, ?)');
foreach ($this->getOidData() as $data) {
$this->insertOidStmt->execute($data);
$insertOidStmt->executeStatement($data);
}
$this->insertEntryStmt = $this->con->prepare('INSERT INTO acl_entries (id, class_id, object_identity_id, field_name, ace_order, security_identity_id, mask, granting, granting_strategy, audit_success, audit_failure) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
$insertEntryStmt = $this->connection->prepare('INSERT INTO acl_entries (id, class_id, object_identity_id, field_name, ace_order, security_identity_id, mask, granting, granting_strategy, audit_success, audit_failure) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
foreach ($this->getEntryData() as $data) {
$this->insertEntryStmt->execute($data);
$insertEntryStmt->executeStatement($data);
}
$this->insertOidAncestorStmt = $this->con->prepare('INSERT INTO acl_object_identity_ancestors (object_identity_id, ancestor_id) VALUES (?, ?)');
$insertOidAncestorStmt = $this->connection->prepare('INSERT INTO acl_object_identity_ancestors (object_identity_id, ancestor_id) VALUES (?, ?)');
foreach ($this->getOidAncestorData() as $data) {
$this->insertOidAncestorStmt->execute($data);
$insertOidAncestorStmt->executeStatement($data);
}
}
protected function tearDown()
protected function tearDown(): void
{
$this->con = null;
$this->connection = null;
}
protected function getField($object, $field)
@@ -198,83 +195,83 @@ class AclProviderTest extends \PHPUnit_Framework_TestCase
protected function getEntryData()
{
// id, cid, oid, field, order, sid, mask, granting, strategy, a success, a failure
return array(
array(1, 1, 1, null, 0, 1, 1, 1, 'all', 1, 1),
array(2, 1, 1, null, 1, 2, 1 << 2 | 1 << 1, 0, 'any', 0, 0),
array(3, 3, 4, null, 0, 1, 2, 1, 'all', 1, 1),
array(4, 3, 4, null, 2, 2, 1, 1, 'all', 1, 1),
array(5, 3, 4, null, 1, 3, 1, 1, 'all', 1, 1),
);
return [
[1, 1, 1, null, 0, 1, 1, 1, 'all', 1, 1],
[2, 1, 1, null, 1, 2, 1 << 2 | 1 << 1, 0, 'any', 0, 0],
[3, 3, 4, null, 0, 1, 2, 1, 'all', 1, 1],
[4, 3, 4, null, 2, 2, 1, 1, 'all', 1, 1],
[5, 3, 4, null, 1, 3, 1, 1, 'all', 1, 1],
];
}
protected function getOidData()
{
// id, cid, oid, parent_oid, entries_inheriting
return array(
array(1, 1, '123', null, 1),
array(2, 2, '123', 1, 1),
array(3, 2, 'i:3:123', 1, 1),
array(4, 3, '1', 2, 1),
array(5, 3, '2', 2, 1),
);
return [
[1, 1, '123', null, 1],
[2, 2, '123', 1, 1],
[3, 2, 'i:3:123', 1, 1],
[4, 3, '1', 2, 1],
[5, 3, '2', 2, 1],
];
}
protected function getOidAncestorData()
{
return array(
array(1, 1),
array(2, 1),
array(2, 2),
array(3, 1),
array(3, 3),
array(4, 2),
array(4, 1),
array(4, 4),
array(5, 2),
array(5, 1),
array(5, 5),
);
return [
[1, 1],
[2, 1],
[2, 2],
[3, 1],
[3, 3],
[4, 2],
[4, 1],
[4, 4],
[5, 2],
[5, 1],
[5, 5],
];
}
protected function getSidData()
{
return array(
array(1, 'SomeClass-john.doe', 1),
array(2, 'MyClass-john.doe@foo.com', 1),
array(3, 'FooClass-123', 1),
array(4, 'MooClass-ROLE_USER', 1),
array(5, 'ROLE_USER', 0),
array(6, 'IS_AUTHENTICATED_FULLY', 0),
);
return [
[1, 'SomeClass-john.doe', 1],
[2, 'MyClass-john.doe@foo.com', 1],
[3, 'FooClass-123', 1],
[4, 'MooClass-ROLE_USER', 1],
[5, 'ROLE_USER', 0],
[6, 'IS_AUTHENTICATED_FULLY', 0],
];
}
protected function getClassData()
{
return array(
array(1, 'Bundle\SomeVendor\MyBundle\Entity\SomeEntity'),
array(2, 'Bundle\MyBundle\Entity\AnotherEntity'),
array(3, 'foo'),
);
return [
[1, 'Bundle\SomeVendor\MyBundle\Entity\SomeEntity'],
[2, 'Bundle\MyBundle\Entity\AnotherEntity'],
[3, 'foo'],
];
}
protected function getOptions()
{
return array(
return [
'oid_table_name' => 'acl_object_identities',
'oid_ancestors_table_name' => 'acl_object_identity_ancestors',
'class_table_name' => 'acl_classes',
'sid_table_name' => 'acl_security_identities',
'entry_table_name' => 'acl_entries',
);
];
}
protected function getStrategy()
protected function getStrategy(): PermissionGrantingStrategy
{
return new PermissionGrantingStrategy();
}
protected function getProvider()
protected function getProvider(): AclProvider
{
return new AclProvider($this->con, $this->getStrategy(), $this->getOptions());
return new AclProvider($this->connection, $this->getStrategy(), $this->getOptions());
}
}
@@ -11,34 +11,36 @@
namespace Symfony\Component\Security\Acl\Tests\Dbal;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Model\FieldEntryInterface;
use Symfony\Component\Security\Acl\Model\AuditableEntryInterface;
use Symfony\Component\Security\Acl\Model\EntryInterface;
use Symfony\Component\Security\Acl\Domain\Entry;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\Acl;
use Symfony\Component\Security\Acl\Exception\AclNotFoundException;
use Symfony\Component\Security\Acl\Exception\ConcurrentModificationException;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Acl\Dbal\AclProvider;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
use Symfony\Component\Security\Acl\Dbal\MutableAclProvider;
use Symfony\Component\Security\Acl\Dbal\Schema;
use Doctrine\DBAL\DriverManager;
use Symfony\Component\Security\Acl\Domain\Acl;
use Symfony\Component\Security\Acl\Domain\Entry;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Exception\AclNotFoundException;
use Symfony\Component\Security\Acl\Exception\ConcurrentModificationException;
use Symfony\Component\Security\Acl\Model\AuditableEntryInterface;
use Symfony\Component\Security\Acl\Model\EntryInterface;
use Symfony\Component\Security\Acl\Model\FieldEntryInterface;
/**
* @requires extension pdo_sqlite
*/
class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
class MutableAclProviderTest extends TestCase
{
protected $con;
protected $connection;
public static function assertAceEquals(EntryInterface $a, EntryInterface $b)
{
self::assertInstanceOf(get_class($a), $b);
self::assertInstanceOf(\get_class($a), $b);
foreach (array('getId', 'getMask', 'getStrategy', 'isGranting') as $getter) {
foreach (['getId', 'getMask', 'getStrategy', 'isGranting'] as $getter) {
self::assertSame($a->$getter(), $b->$getter());
}
@@ -55,11 +57,10 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
}
}
/**
* @expectedException \Symfony\Component\Security\Acl\Exception\AclAlreadyExistsException
*/
public function testCreateAclThrowsExceptionWhenAclAlreadyExists()
{
$this->expectException(\Symfony\Component\Security\Acl\Exception\AclAlreadyExistsException::class);
$provider = $this->getProvider();
$oid = new ObjectIdentity('123456', 'FOO');
$provider->createAcl($oid);
@@ -104,11 +105,10 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
$provider->updateAcl($acl);
$provider->deleteAcl($parentAcl->getObjectIdentity());
try {
$provider->findAcl(new ObjectIdentity(1, 'Foo'));
$this->fail('Child-ACLs have not been deleted.');
} catch (AclNotFoundException $e) {
}
$this->expectException(AclNotFoundException::class);
$this->expectExceptionMessage('There is no ACL for the given object identity.');
$provider->findAcl(new ObjectIdentity(1, 'Foo'));
}
public function testFindAclsAddsPropertyListener()
@@ -119,7 +119,7 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
$propertyChanges = $this->getField($provider, 'propertyChanges');
$this->assertCount(1, $propertyChanges);
$this->assertTrue($propertyChanges->contains($acl));
$this->assertEquals(array(), $propertyChanges->offsetGet($acl));
$this->assertEquals([], $propertyChanges->offsetGet($acl));
$listeners = $this->getField($acl, 'listeners');
$this->assertSame($provider, $listeners[0]);
@@ -134,7 +134,7 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
$propertyChanges = $this->getField($provider, 'propertyChanges');
$this->assertCount(1, $propertyChanges);
$this->assertTrue($propertyChanges->contains($acl));
$this->assertEquals(array(), $propertyChanges->offsetGet($acl));
$this->assertEquals([], $propertyChanges->offsetGet($acl));
$listeners = $this->getField($acl, 'listeners');
$this->assertCount(1, $listeners);
@@ -144,17 +144,17 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
public function testFindAclsAddsPropertyListenerToParentAcls()
{
$provider = $this->getProvider();
$this->importAcls($provider, array(
'main' => array(
$this->importAcls($provider, [
'main' => [
'object_identifier' => '1',
'class_type' => 'foo',
'parent_acl' => 'parent',
),
'parent' => array(
],
'parent' => [
'object_identifier' => '1',
'class_type' => 'anotherFoo',
),
));
],
]);
$propertyChanges = $this->getField($provider, 'propertyChanges');
$this->assertCount(0, $propertyChanges);
@@ -165,15 +165,14 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($propertyChanges->contains($acl->getParentAcl()));
}
/**
* @expectedException \InvalidArgumentException
*/
public function testPropertyChangedDoesNotTrackUnmanagedAcls()
{
$provider = $this->getProvider();
$acl = new Acl(1, new ObjectIdentity(1, 'foo'), new PermissionGrantingStrategy(), array(), false);
$this->expectException(\InvalidArgumentException::class);
$provider->propertyChanged($acl, 'classAces', array(), array('foo'));
$provider = $this->getProvider();
$acl = new Acl(1, new ObjectIdentity(1, 'foo'), new PermissionGrantingStrategy(), [], false);
$provider->propertyChanged($acl, 'classAces', [], ['foo']);
}
public function testPropertyChangedTracksChangesToAclProperties()
@@ -243,32 +242,32 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
$this->assertFalse(isset($changes['aces']));
}
/**
* @expectedException \InvalidArgumentException
*/
public function testUpdateAclDoesNotAcceptUntrackedAcls()
{
$this->expectException(\InvalidArgumentException::class);
$provider = $this->getProvider();
$acl = new Acl(1, new ObjectIdentity(1, 'Foo'), new PermissionGrantingStrategy(), array(), true);
$acl = new Acl(1, new ObjectIdentity(1, 'Foo'), new PermissionGrantingStrategy(), [], true);
$provider->updateAcl($acl);
}
public function testUpdateDoesNothingWhenThereAreNoChanges()
{
$con = $this->getMock('Doctrine\DBAL\Connection', array(), array(), '', false);
$con = $this->createMock(Connection::class);
$con
->expects($this->never())
->method('beginTransaction')
;
$con
->expects($this->never())
->method('executeQuery')
->method('executeUpdate')
;
$provider = new MutableAclProvider($con, new PermissionGrantingStrategy(), array());
$acl = new Acl(1, new ObjectIdentity(1, 'Foo'), new PermissionGrantingStrategy(), array(), true);
$provider = new MutableAclProvider($con, new PermissionGrantingStrategy(), []);
$acl = new Acl(1, new ObjectIdentity(1, 'Foo'), new PermissionGrantingStrategy(), [], true);
$propertyChanges = $this->getField($provider, 'propertyChanges');
$propertyChanges->offsetSet($acl, array());
$propertyChanges->offsetSet($acl, []);
$provider->updateAcl($acl);
}
@@ -290,11 +289,11 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
$acl1->insertClassAce($sid, 3);
$acl2->insertClassAce($sid, 5);
try {
$provider->updateAcl($acl1);
$this->fail('Provider failed to detect a concurrent modification.');
} catch (ConcurrentModificationException $e) {
}
$this->expectException(ConcurrentModificationException::class);
$this->expectExceptionMessage('The "classAces" property has been modified concurrently.');
$provider->updateAcl($acl1);
}
public function testUpdateAcl()
@@ -323,7 +322,7 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
$aces = $acl->getObjectAces();
$reloadedAces = $reloadedAcl->getObjectAces();
$this->assertEquals(count($aces), count($reloadedAces));
$this->assertEquals(\count($aces), \count($reloadedAces));
foreach ($aces as $index => $ace) {
$this->assertAceEquals($ace, $reloadedAces[$index]);
}
@@ -385,6 +384,9 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
$acl = $provider->findAcl($oid);
$acl->insertObjectFieldAce($fieldName, $sid3, 4);
$provider->updateAcl($acl);
$acls = $provider->findAcl($oid);
$this->assertCount(3, $acls->getObjectFieldAces($fieldName));
}
public function testUpdateAclDeletingObjectFieldAcesThrowsDBConstraintViolations()
@@ -411,6 +413,9 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
$acl = $provider->findAcl($oid);
$acl->insertObjectFieldAce($fieldName, $sid3, 4);
$provider->updateAcl($acl);
$acls = $provider->findAcl($oid);
$this->assertCount(2, $acls->getObjectFieldAces($fieldName));
}
public function testUpdateUserSecurityIdentity()
@@ -437,7 +442,7 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
$aces = $acl->getObjectAces();
$reloadedAces = $reloadedAcl->getObjectAces();
$this->assertEquals(count($aces), count($reloadedAces));
$this->assertEquals(\count($aces), \count($reloadedAces));
foreach ($reloadedAces as $ace) {
$this->assertTrue($ace->getSecurityIdentity()->equals($newSid));
}
@@ -455,15 +460,12 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
* ),
* )
*
* @param AclProvider $provider
* @param array $data
*
* @throws \InvalidArgumentException
* @throws \Exception
*/
protected function importAcls(AclProvider $provider, array $data)
{
$aclIds = $parentAcls = array();
$aclIds = $parentAcls = [];
$con = $this->getField($provider, 'connection');
$con->beginTransaction();
try {
@@ -472,17 +474,17 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
throw new \InvalidArgumentException('"object_identifier", and "class_type" must be present.');
}
$this->callMethod($provider, 'createObjectIdentity', array(new ObjectIdentity($aclData['object_identifier'], $aclData['class_type'])));
$this->callMethod($provider, 'createObjectIdentity', [new ObjectIdentity($aclData['object_identifier'], $aclData['class_type'])]);
$aclId = $con->lastInsertId();
$aclIds[$name] = $aclId;
$sql = $this->callMethod($provider, 'getInsertObjectIdentityRelationSql', array($aclId, $aclId));
$con->executeQuery($sql);
$sql = $this->callMethod($provider, 'getInsertObjectIdentityRelationSql', [$aclId, $aclId]);
$con->executeStatement($sql);
if (isset($aclData['parent_acl'])) {
if (isset($aclIds[$aclData['parent_acl']])) {
$con->executeQuery('UPDATE acl_object_identities SET parent_object_identity_id = '.$aclIds[$aclData['parent_acl']].' WHERE id = '.$aclId);
$con->executeQuery($this->callMethod($provider, 'getInsertObjectIdentityRelationSql', array($aclId, $aclIds[$aclData['parent_acl']])));
$con->executeStatement('UPDATE acl_object_identities SET parent_object_identity_id = '.$aclIds[$aclData['parent_acl']].' WHERE id = '.$aclId);
$con->executeStatement($this->callMethod($provider, 'getInsertObjectIdentityRelationSql', [$aclId, $aclIds[$aclData['parent_acl']]]));
} else {
$parentAcls[$aclId] = $aclData['parent_acl'];
}
@@ -494,8 +496,8 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
throw new \InvalidArgumentException(sprintf('"%s" does not exist.', $name));
}
$con->executeQuery(sprintf('UPDATE acl_object_identities SET parent_object_identity_id = %d WHERE id = %d', $aclIds[$name], $aclId));
$con->executeQuery($this->callMethod($provider, 'getInsertObjectIdentityRelationSql', array($aclId, $aclIds[$name])));
$con->executeStatement(sprintf('UPDATE acl_object_identities SET parent_object_identity_id = %d WHERE id = %d', $aclIds[$name], $aclId));
$con->executeStatement($this->callMethod($provider, 'getInsertObjectIdentityRelationSql', [$aclId, $aclIds[$name]]));
}
$con->commit();
@@ -514,23 +516,23 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
return $method->invokeArgs($object, $args);
}
protected function setUp()
protected function setUp(): void
{
$this->con = DriverManager::getConnection(array(
$this->connection = DriverManager::getConnection([
'driver' => 'pdo_sqlite',
'memory' => true,
));
]);
// import the schema
$schema = new Schema($this->getOptions());
foreach ($schema->toSql($this->con->getDatabasePlatform()) as $sql) {
$this->con->exec($sql);
foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) {
$this->connection->executeStatement($sql);
}
}
protected function tearDown()
protected function tearDown(): void
{
$this->con = null;
$this->connection = null;
}
protected function getField($object, $field)
@@ -551,13 +553,13 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
protected function getOptions()
{
return array(
return [
'oid_table_name' => 'acl_object_identities',
'oid_ancestors_table_name' => 'acl_object_identity_ancestors',
'class_table_name' => 'acl_classes',
'sid_table_name' => 'acl_security_identities',
'entry_table_name' => 'acl_entries',
);
];
}
protected function getStrategy()
@@ -567,6 +569,6 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
protected function getProvider($cache = null)
{
return new MutableAclProvider($this->con, $this->getStrategy(), $this->getOptions(), $cache);
return new MutableAclProvider($this->connection, $this->getStrategy(), $this->getOptions(), $cache);
}
}
+100 -89
View File
@@ -11,17 +11,18 @@
namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Doctrine\Persistence\PropertyChangedListener;
use Symfony\Component\Security\Acl\Domain\Acl;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
class AclTest extends \PHPUnit_Framework_TestCase
class AclTest extends \PHPUnit\Framework\TestCase
{
public function testConstructor()
{
$acl = new Acl(1, $oid = new ObjectIdentity('foo', 'foo'), $permissionStrategy = new PermissionGrantingStrategy(), array(), true);
$acl = new Acl(1, $oid = new ObjectIdentity('foo', 'foo'), $permissionStrategy = new PermissionGrantingStrategy(), [], true);
$this->assertSame(1, $acl->getId());
$this->assertSame($oid, $acl->getObjectIdentity());
@@ -30,11 +31,12 @@ class AclTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException \OutOfBoundsException
* @dataProvider getDeleteAceTests
*/
public function testDeleteAceThrowsExceptionOnInvalidIndex($type)
{
$this->expectException(\OutOfBoundsException::class);
$acl = $this->getAcl();
$acl->{'delete'.$type.'Ace'}(0);
}
@@ -49,9 +51,9 @@ class AclTest extends \PHPUnit_Framework_TestCase
$acl->{'insert'.$type.'Ace'}(new RoleSecurityIdentity('foo'), 2, 1);
$acl->{'insert'.$type.'Ace'}(new RoleSecurityIdentity('foo'), 3, 2);
$listener = $this->getListener(array(
$listener = $this->getListener([
$type.'Aces', 'aceOrder', 'aceOrder', $type.'Aces',
));
]);
$acl->addPropertyChangedListener($listener);
$this->assertCount(3, $acl->{'get'.$type.'Aces'}());
@@ -68,18 +70,19 @@ class AclTest extends \PHPUnit_Framework_TestCase
public function getDeleteAceTests()
{
return array(
array('class'),
array('object'),
);
return [
['class'],
['object'],
];
}
/**
* @expectedException \OutOfBoundsException
* @dataProvider getDeleteFieldAceTests
*/
public function testDeleteFieldAceThrowsExceptionOnInvalidIndex($type)
{
$this->expectException(\OutOfBoundsException::class);
$acl = $this->getAcl();
$acl->{'delete'.$type.'Ace'}('foo', 0);
}
@@ -94,9 +97,9 @@ class AclTest extends \PHPUnit_Framework_TestCase
$acl->{'insert'.$type.'Ace'}('foo', new RoleSecurityIdentity('foo'), 2, 1);
$acl->{'insert'.$type.'Ace'}('foo', new RoleSecurityIdentity('foo'), 3, 2);
$listener = $this->getListener(array(
$listener = $this->getListener([
$type.'Aces', 'aceOrder', 'aceOrder', $type.'Aces',
));
]);
$acl->addPropertyChangedListener($listener);
$this->assertCount(3, $acl->{'get'.$type.'Aces'}('foo'));
@@ -113,10 +116,10 @@ class AclTest extends \PHPUnit_Framework_TestCase
public function getDeleteFieldAceTests()
{
return array(
array('classField'),
array('objectField'),
);
return [
['classField'],
['objectField'],
];
}
/**
@@ -126,9 +129,9 @@ class AclTest extends \PHPUnit_Framework_TestCase
{
$acl = $this->getAcl();
$listener = $this->getListener(array(
$listener = $this->getListener([
$property, 'aceOrder', $property, 'aceOrder', $property,
));
]);
$acl->addPropertyChangedListener($listener);
$sid = new RoleSecurityIdentity('foo');
@@ -143,21 +146,22 @@ class AclTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException \OutOfBoundsException
* @dataProvider getInsertAceTests
*/
public function testInsertClassAceThrowsExceptionOnInvalidIndex($property, $method)
{
$this->expectException(\OutOfBoundsException::class);
$acl = $this->getAcl();
$acl->$method(new RoleSecurityIdentity('foo'), 1, 1);
}
public function getInsertAceTests()
{
return array(
array('classAces', 'insertClassAce'),
array('objectAces', 'insertObjectAce'),
);
return [
['classAces', 'insertClassAce'],
['objectAces', 'insertObjectAce'],
];
}
/**
@@ -167,10 +171,10 @@ class AclTest extends \PHPUnit_Framework_TestCase
{
$acl = $this->getAcl();
$listener = $this->getListener(array(
$listener = $this->getListener([
$property, $property, 'aceOrder', $property,
'aceOrder', 'aceOrder', $property,
));
]);
$acl->addPropertyChangedListener($listener);
$sid = new RoleSecurityIdentity('foo');
@@ -187,35 +191,36 @@ class AclTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException \OutOfBoundsException
* @dataProvider getInsertFieldAceTests
*/
public function testInsertClassFieldAceThrowsExceptionOnInvalidIndex($property, $method)
{
$this->expectException(\OutOfBoundsException::class);
$acl = $this->getAcl();
$acl->$method('foo', new RoleSecurityIdentity('foo'), 1, 1);
}
public function getInsertFieldAceTests()
{
return array(
array('classFieldAces', 'insertClassFieldAce'),
array('objectFieldAces', 'insertObjectFieldAce'),
);
return [
['classFieldAces', 'insertClassFieldAce'],
['objectFieldAces', 'insertObjectFieldAce'],
];
}
public function testIsFieldGranted()
{
$sids = array(new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity('ROLE_IDDQD'));
$masks = array(1, 2, 4);
$strategy = $this->getMock('Symfony\Component\Security\Acl\Model\PermissionGrantingStrategyInterface');
$acl = new Acl(1, new ObjectIdentity(1, 'foo'), $strategy, array(), true);
$sids = [new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity('ROLE_IDDQD')];
$masks = [1, 2, 4];
$strategy = $this->createMock('Symfony\Component\Security\Acl\Model\PermissionGrantingStrategyInterface');
$acl = new Acl(1, new ObjectIdentity(1, 'foo'), $strategy, [], true);
$strategy
->expects($this->once())
->method('isFieldGranted')
->with($this->equalTo($acl), $this->equalTo('foo'), $this->equalTo($masks), $this->equalTo($sids), $this->isTrue())
->will($this->returnValue(true))
->willReturn(true)
;
$this->assertTrue($acl->isFieldGranted('foo', $masks, $sids, true));
@@ -223,16 +228,16 @@ class AclTest extends \PHPUnit_Framework_TestCase
public function testIsGranted()
{
$sids = array(new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity('ROLE_IDDQD'));
$masks = array(1, 2, 4);
$strategy = $this->getMock('Symfony\Component\Security\Acl\Model\PermissionGrantingStrategyInterface');
$acl = new Acl(1, new ObjectIdentity(1, 'foo'), $strategy, array(), true);
$sids = [new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity('ROLE_IDDQD')];
$masks = [1, 2, 4];
$strategy = $this->createMock('Symfony\Component\Security\Acl\Model\PermissionGrantingStrategyInterface');
$acl = new Acl(1, new ObjectIdentity(1, 'foo'), $strategy, [], true);
$strategy
->expects($this->once())
->method('isGranted')
->with($this->equalTo($acl), $this->equalTo($masks), $this->equalTo($sids), $this->isTrue())
->will($this->returnValue(true))
->willReturn(true)
;
$this->assertTrue($acl->isGranted($masks, $sids, true));
@@ -243,7 +248,7 @@ class AclTest extends \PHPUnit_Framework_TestCase
$acl = $this->getAcl();
$parentAcl = $this->getAcl();
$listener = $this->getListener(array('parentAcl'));
$listener = $this->getListener(['parentAcl']);
$acl->addPropertyChangedListener($listener);
$this->assertNull($acl->getParentAcl());
@@ -258,7 +263,7 @@ class AclTest extends \PHPUnit_Framework_TestCase
{
$acl = $this->getAcl();
$listener = $this->getListener(array('entriesInheriting'));
$listener = $this->getListener(['entriesInheriting']);
$acl->addPropertyChangedListener($listener);
$this->assertTrue($acl->isEntriesInheriting());
@@ -276,29 +281,30 @@ class AclTest extends \PHPUnit_Framework_TestCase
public function testIsSidLoaded()
{
$acl = new Acl(1, new ObjectIdentity('1', 'foo'), new PermissionGrantingStrategy(), array(new UserSecurityIdentity('foo', 'Foo'), new UserSecurityIdentity('johannes', 'Bar')), true);
$acl = new Acl(1, new ObjectIdentity('1', 'foo'), new PermissionGrantingStrategy(), [new UserSecurityIdentity('foo', 'Foo'), new UserSecurityIdentity('johannes', 'Bar')], true);
$this->assertTrue($acl->isSidLoaded(new UserSecurityIdentity('foo', 'Foo')));
$this->assertTrue($acl->isSidLoaded(new UserSecurityIdentity('johannes', 'Bar')));
$this->assertTrue($acl->isSidLoaded(array(
$this->assertTrue($acl->isSidLoaded([
new UserSecurityIdentity('foo', 'Foo'),
new UserSecurityIdentity('johannes', 'Bar'),
)));
]));
$this->assertFalse($acl->isSidLoaded(new RoleSecurityIdentity('ROLE_FOO')));
$this->assertFalse($acl->isSidLoaded(new UserSecurityIdentity('schmittjoh@gmail.com', 'Moo')));
$this->assertFalse($acl->isSidLoaded(array(
$this->assertFalse($acl->isSidLoaded([
new UserSecurityIdentity('foo', 'Foo'),
new UserSecurityIdentity('johannes', 'Bar'),
new RoleSecurityIdentity('ROLE_FOO'),
)));
]));
}
/**
* @dataProvider getUpdateAceTests
* @expectedException \OutOfBoundsException
*/
public function testUpdateAceThrowsOutOfBoundsExceptionOnInvalidIndex($type)
{
$this->expectException(\OutOfBoundsException::class);
$acl = $this->getAcl();
$acl->{'update'.$type}(0, 1);
}
@@ -311,9 +317,9 @@ class AclTest extends \PHPUnit_Framework_TestCase
$acl = $this->getAcl();
$acl->{'insert'.$type}(new RoleSecurityIdentity('foo'), 1);
$listener = $this->getListener(array(
$listener = $this->getListener([
'mask', 'mask', 'strategy',
));
]);
$acl->addPropertyChangedListener($listener);
$aces = $acl->{'get'.$type.'s'}();
@@ -332,18 +338,19 @@ class AclTest extends \PHPUnit_Framework_TestCase
public function getUpdateAceTests()
{
return array(
array('classAce'),
array('objectAce'),
);
return [
['classAce'],
['objectAce'],
];
}
/**
* @dataProvider getUpdateFieldAceTests
* @expectedException \OutOfBoundsException
*/
public function testUpdateFieldAceThrowsExceptionOnInvalidIndex($type)
{
$this->expectException(\OutOfBoundsException::class);
$acl = $this->getAcl();
$acl->{'update'.$type}(0, 'foo', 1);
}
@@ -356,9 +363,9 @@ class AclTest extends \PHPUnit_Framework_TestCase
$acl = $this->getAcl();
$acl->{'insert'.$type}('foo', new UserSecurityIdentity('foo', 'Foo'), 1);
$listener = $this->getListener(array(
$listener = $this->getListener([
'mask', 'mask', 'strategy',
));
]);
$acl->addPropertyChangedListener($listener);
$aces = $acl->{'get'.$type.'s'}('foo');
@@ -377,18 +384,19 @@ class AclTest extends \PHPUnit_Framework_TestCase
public function getUpdateFieldAceTests()
{
return array(
array('classFieldAce'),
array('objectFieldAce'),
);
return [
['classFieldAce'],
['objectFieldAce'],
];
}
/**
* @dataProvider getUpdateAuditingTests
* @expectedException \OutOfBoundsException
*/
public function testUpdateAuditingThrowsExceptionOnInvalidIndex($type)
{
$this->expectException(\OutOfBoundsException::class);
$acl = $this->getAcl();
$acl->{'update'.$type.'Auditing'}(0, true, false);
}
@@ -401,9 +409,9 @@ class AclTest extends \PHPUnit_Framework_TestCase
$acl = $this->getAcl();
$acl->{'insert'.$type.'Ace'}(new RoleSecurityIdentity('foo'), 1);
$listener = $this->getListener(array(
$listener = $this->getListener([
'auditFailure', 'auditSuccess', 'auditFailure',
));
]);
$acl->addPropertyChangedListener($listener);
$aces = $acl->{'get'.$type.'Aces'}();
@@ -422,28 +430,30 @@ class AclTest extends \PHPUnit_Framework_TestCase
public function getUpdateAuditingTests()
{
return array(
array('class'),
array('object'),
);
return [
['class'],
['object'],
];
}
/**
* @expectedException \InvalidArgumentException
* @dataProvider getUpdateFieldAuditingTests
*/
public function testUpdateFieldAuditingThrowsExceptionOnInvalidField($type)
{
$this->expectException(\InvalidArgumentException::class);
$acl = $this->getAcl();
$acl->{'update'.$type.'Auditing'}(0, 'foo', true, true);
}
/**
* @expectedException \OutOfBoundsException
* @dataProvider getUpdateFieldAuditingTests
*/
public function testUpdateFieldAuditingThrowsExceptionOnInvalidIndex($type)
{
$this->expectException(\OutOfBoundsException::class);
$acl = $this->getAcl();
$acl->{'insert'.$type.'Ace'}('foo', new RoleSecurityIdentity('foo'), 1);
$acl->{'update'.$type.'Auditing'}(1, 'foo', true, false);
@@ -457,9 +467,9 @@ class AclTest extends \PHPUnit_Framework_TestCase
$acl = $this->getAcl();
$acl->{'insert'.$type.'Ace'}('foo', new RoleSecurityIdentity('foo'), 1);
$listener = $this->getListener(array(
$listener = $this->getListener([
'auditSuccess', 'auditSuccess', 'auditFailure',
));
]);
$acl->addPropertyChangedListener($listener);
$aces = $acl->{'get'.$type.'Aces'}('foo');
@@ -478,36 +488,37 @@ class AclTest extends \PHPUnit_Framework_TestCase
public function getUpdateFieldAuditingTests()
{
return array(
array('classField'),
array('objectField'),
);
return [
['classField'],
['objectField'],
];
}
protected function getListener($expectedChanges)
{
$aceProperties = array('aceOrder', 'mask', 'strategy', 'auditSuccess', 'auditFailure');
$aceProperties = ['aceOrder', 'mask', 'strategy', 'auditSuccess', 'auditFailure'];
$listener = $this->getMock('Doctrine\Common\PropertyChangedListener');
$arguments = [];
$listener = $this->createMock(PropertyChangedListener::class);
foreach ($expectedChanges as $index => $property) {
if (in_array($property, $aceProperties)) {
if (\in_array($property, $aceProperties)) {
$class = 'Symfony\Component\Security\Acl\Domain\Entry';
} else {
$class = 'Symfony\Component\Security\Acl\Domain\Acl';
}
$listener
->expects($this->at($index))
->method('propertyChanged')
->with($this->isInstanceOf($class), $this->equalTo($property))
;
$arguments[] = [$this->isInstanceOf($class), $this->equalTo($property)];
}
$listener
->method('propertyChanged')
->withConsecutive(...$arguments)
;
return $listener;
}
protected function getAcl()
{
return new Acl(1, new ObjectIdentity(1, 'foo'), new PermissionGrantingStrategy(), array(), true);
return new Acl(1, new ObjectIdentity(1, 'foo'), new PermissionGrantingStrategy(), [], true);
}
}
+10 -10
View File
@@ -11,7 +11,7 @@
namespace Symfony\Component\Security\Acl\Tests\Domain;
class AuditLoggerTest extends \PHPUnit_Framework_TestCase
class AuditLoggerTest extends \PHPUnit\Framework\TestCase
{
/**
* @dataProvider getTestLogData
@@ -25,7 +25,7 @@ class AuditLoggerTest extends \PHPUnit_Framework_TestCase
$ace
->expects($this->once())
->method('isAuditSuccess')
->will($this->returnValue($audit))
->willReturn($audit)
;
$ace
@@ -41,7 +41,7 @@ class AuditLoggerTest extends \PHPUnit_Framework_TestCase
$ace
->expects($this->once())
->method('isAuditFailure')
->will($this->returnValue($audit))
->willReturn($audit)
;
}
@@ -63,17 +63,17 @@ class AuditLoggerTest extends \PHPUnit_Framework_TestCase
public function getTestLogData()
{
return array(
array(true, false),
array(true, true),
array(false, false),
array(false, true),
);
return [
[true, false],
[true, true],
[false, false],
[false, true],
];
}
protected function getEntry()
{
return $this->getMock('Symfony\Component\Security\Acl\Model\AuditableEntryInterface');
return $this->createMock('Symfony\Component\Security\Acl\Model\AuditableEntryInterface');
}
protected function getLogger()
@@ -11,33 +11,34 @@
namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
use Doctrine\Common\Cache\ArrayCache;
use Symfony\Component\Security\Acl\Domain\Acl;
use Symfony\Component\Security\Acl\Domain\DoctrineAclCache;
use Doctrine\Common\Cache\ArrayCache;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
class DoctrineAclCacheTest extends \PHPUnit_Framework_TestCase
class DoctrineAclCacheTest extends \PHPUnit\Framework\TestCase
{
protected $permissionGrantingStrategy;
/**
* @expectedException \InvalidArgumentException
* @dataProvider getEmptyValue
*/
public function testConstructorDoesNotAcceptEmptyPrefix($empty)
{
$this->expectException(\InvalidArgumentException::class);
new DoctrineAclCache(new ArrayCache(), $this->getPermissionGrantingStrategy(), $empty);
}
public function getEmptyValue()
{
return array(
array(null),
array(false),
array(''),
);
return [
[null],
[false],
[''],
];
}
public function test()
@@ -64,7 +65,7 @@ class DoctrineAclCacheTest extends \PHPUnit_Framework_TestCase
{
static $id = 1;
$acl = new Acl($id, new ObjectIdentity($id, 'foo'), $this->getPermissionGrantingStrategy(), array(), $depth > 0);
$acl = new Acl($id, new ObjectIdentity($id, 'foo'), $this->getPermissionGrantingStrategy(), [], $depth > 0);
// insert some ACEs
$sid = new UserSecurityIdentity('johannes', 'Foo');
+3 -3
View File
@@ -13,7 +13,7 @@ namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\Entry;
class EntryTest extends \PHPUnit_Framework_TestCase
class EntryTest extends \PHPUnit\Framework\TestCase
{
public function testConstructor()
{
@@ -109,11 +109,11 @@ class EntryTest extends \PHPUnit_Framework_TestCase
protected function getAcl()
{
return $this->getMock('Symfony\Component\Security\Acl\Model\AclInterface');
return $this->createMock('Symfony\Component\Security\Acl\Model\AclInterface');
}
protected function getSid()
{
return $this->getMock('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface');
return $this->createMock('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface');
}
}
@@ -13,7 +13,7 @@ namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\FieldEntry;
class FieldEntryTest extends \PHPUnit_Framework_TestCase
class FieldEntryTest extends \PHPUnit\Framework\TestCase
{
public function testConstructor()
{
@@ -64,11 +64,11 @@ class FieldEntryTest extends \PHPUnit_Framework_TestCase
protected function getAcl()
{
return $this->getMock('Symfony\Component\Security\Acl\Model\AclInterface');
return $this->createMock('Symfony\Component\Security\Acl\Model\AclInterface');
}
protected function getSid()
{
return $this->getMock('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface');
return $this->createMock('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface');
}
}
@@ -13,7 +13,7 @@ namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\ObjectIdentityRetrievalStrategy;
class ObjectIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
class ObjectIdentityRetrievalStrategyTest extends \PHPUnit\Framework\TestCase
{
public function testGetObjectIdentityReturnsNullForInvalidDomainObject()
{
@@ -28,7 +28,7 @@ class ObjectIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
$objectIdentity = $strategy->getObjectIdentity($domainObject);
$this->assertEquals($domainObject->getId(), $objectIdentity->getIdentifier());
$this->assertEquals(get_class($domainObject), $objectIdentity->getType());
$this->assertEquals(\get_class($domainObject), $objectIdentity->getType());
}
}
@@ -12,8 +12,9 @@
namespace Symfony\Component\Security\Acl\Tests\Domain
{
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Model\DomainObjectInterface;
class ObjectIdentityTest extends \PHPUnit_Framework_TestCase
class ObjectIdentityTest extends \PHPUnit\Framework\TestCase
{
public function testConstructor()
{
@@ -34,17 +35,17 @@ namespace Symfony\Component\Security\Acl\Tests\Domain
public function testFromDomainObjectPrefersInterfaceOverGetId()
{
$domainObject = $this->getMock('Symfony\Component\Security\Acl\Model\DomainObjectInterface');
$domainObject
->expects($this->once())
->method('getObjectIdentifier')
->will($this->returnValue('getObjectIdentifier()'))
;
$domainObject
->expects($this->never())
->method('getId')
->will($this->returnValue('getId()'))
;
$domainObject = new class() implements DomainObjectInterface {
public function getObjectIdentifier()
{
return 'getObjectIdentifier()';
}
public function getId()
{
return 'getId()';
}
};
$id = ObjectIdentity::fromDomainObject($domainObject);
$this->assertEquals('getObjectIdentifier()', $id->getIdentifier());
@@ -98,12 +99,12 @@ namespace Symfony\Component\Security\Acl\Tests\Domain
public function getCompareData()
{
return array(
array(new ObjectIdentity('123', 'foo'), new ObjectIdentity('123', 'foo'), true),
array(new ObjectIdentity('123', 'foo'), new ObjectIdentity(123, 'foo'), true),
array(new ObjectIdentity('1', 'foo'), new ObjectIdentity('2', 'foo'), false),
array(new ObjectIdentity('1', 'bla'), new ObjectIdentity('1', 'blub'), false),
);
return [
[new ObjectIdentity('123', 'foo'), new ObjectIdentity('123', 'foo'), true],
[new ObjectIdentity('123', 'foo'), new ObjectIdentity(123, 'foo'), true],
[new ObjectIdentity('1', 'foo'), new ObjectIdentity('2', 'foo'), false],
[new ObjectIdentity('1', 'bla'), new ObjectIdentity('1', 'blub'), false],
];
}
}
@@ -11,14 +11,14 @@
namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\Acl;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Exception\NoAceFoundException;
class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
class PermissionGrantingStrategyTest extends \PHPUnit\Framework\TestCase
{
public function testIsGrantedObjectAcesHavePriority()
{
@@ -28,7 +28,7 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$acl->insertClassAce($sid, 1);
$acl->insertObjectAce($sid, 1, 0, false);
$this->assertFalse($strategy->isGranted($acl, array(1), array($sid)));
$this->assertFalse($strategy->isGranted($acl, [1], [$sid]));
}
public function testIsGrantedFallsBackToClassAcesIfNoApplicableObjectAceWasFound()
@@ -38,7 +38,7 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$sid = new UserSecurityIdentity('johannes', 'Foo');
$acl->insertClassAce($sid, 1);
$this->assertTrue($strategy->isGranted($acl, array(1), array($sid)));
$this->assertTrue($strategy->isGranted($acl, [1], [$sid]));
}
public function testIsGrantedFavorsLocalAcesOverParentAclAces()
@@ -53,7 +53,7 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$acl->setParentAcl($parentAcl);
$parentAcl->insertClassAce($sid, 1, 0, false);
$this->assertTrue($strategy->isGranted($acl, array(1), array($sid)));
$this->assertTrue($strategy->isGranted($acl, [1], [$sid]));
}
public function testIsGrantedFallsBackToParentAcesIfNoLocalAcesAreApplicable()
@@ -69,19 +69,18 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$acl->setParentAcl($parentAcl);
$parentAcl->insertClassAce($sid, 1);
$this->assertTrue($strategy->isGranted($acl, array(1), array($sid)));
$this->assertTrue($strategy->isGranted($acl, [1], [$sid]));
}
/**
* @expectedException \Symfony\Component\Security\Acl\Exception\NoAceFoundException
*/
public function testIsGrantedReturnsExceptionIfNoAceIsFound()
{
$this->expectException(\Symfony\Component\Security\Acl\Exception\NoAceFoundException::class);
$strategy = new PermissionGrantingStrategy();
$acl = $this->getAcl($strategy);
$sid = new UserSecurityIdentity('johannes', 'Foo');
$strategy->isGranted($acl, array(1), array($sid));
$strategy->isGranted($acl, [1], [$sid]);
}
public function testIsGrantedFirstApplicableEntryMakesUltimateDecisionForPermissionIdentityCombination()
@@ -94,11 +93,11 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$acl->insertClassAce($aSid, 1);
$acl->insertClassAce($sid, 1, 1, false);
$acl->insertClassAce($sid, 1, 2);
$this->assertFalse($strategy->isGranted($acl, array(1), array($sid, $aSid)));
$this->assertFalse($strategy->isGranted($acl, [1], [$sid, $aSid]));
$acl->insertObjectAce($sid, 1, 0, false);
$acl->insertObjectAce($aSid, 1, 1);
$this->assertFalse($strategy->isGranted($acl, array(1), array($sid, $aSid)));
$this->assertFalse($strategy->isGranted($acl, [1], [$sid, $aSid]));
}
public function testIsGrantedCallsAuditLoggerOnGrant()
@@ -107,7 +106,7 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$acl = $this->getAcl($strategy);
$sid = new UserSecurityIdentity('johannes', 'Foo');
$logger = $this->getMock('Symfony\Component\Security\Acl\Model\AuditLoggerInterface');
$logger = $this->createMock('Symfony\Component\Security\Acl\Model\AuditLoggerInterface');
$logger
->expects($this->once())
->method('logIfNeeded')
@@ -117,7 +116,7 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$acl->insertObjectAce($sid, 1);
$acl->updateObjectAuditing(0, true, false);
$this->assertTrue($strategy->isGranted($acl, array(1), array($sid)));
$this->assertTrue($strategy->isGranted($acl, [1], [$sid]));
}
public function testIsGrantedCallsAuditLoggerOnDeny()
@@ -126,7 +125,7 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$acl = $this->getAcl($strategy);
$sid = new UserSecurityIdentity('johannes', 'Foo');
$logger = $this->getMock('Symfony\Component\Security\Acl\Model\AuditLoggerInterface');
$logger = $this->createMock('Symfony\Component\Security\Acl\Model\AuditLoggerInterface');
$logger
->expects($this->once())
->method('logIfNeeded')
@@ -136,7 +135,7 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$acl->insertObjectAce($sid, 1, 0, false);
$acl->updateObjectAuditing(0, false, true);
$this->assertFalse($strategy->isGranted($acl, array(1), array($sid)));
$this->assertFalse($strategy->isGranted($acl, [1], [$sid]));
}
/**
@@ -151,36 +150,35 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
$acl->insertObjectAce($sid, $aceMask, 0, true, $maskStrategy);
if (false === $result) {
try {
$strategy->isGranted($acl, array($requiredMask), array($sid));
$this->fail('The ACE is not supposed to match.');
} catch (NoAceFoundException $e) {
}
$this->expectException(NoAceFoundException::class);
$this->expectExceptionMessage('No applicable ACE was found.');
$strategy->isGranted($acl, [$requiredMask], [$sid]);
} else {
$this->assertTrue($strategy->isGranted($acl, array($requiredMask), array($sid)));
$this->assertTrue($strategy->isGranted($acl, [$requiredMask], [$sid]));
}
}
public function getAllStrategyTests()
{
return array(
array('all', 1 << 0 | 1 << 1, 1 << 0, true),
array('all', 1 << 0 | 1 << 1, 1 << 2, false),
array('all', 1 << 0 | 1 << 10, 1 << 0 | 1 << 10, true),
array('all', 1 << 0 | 1 << 1, 1 << 0 | 1 << 1 || 1 << 2, false),
array('any', 1 << 0 | 1 << 1, 1 << 0, true),
array('any', 1 << 0 | 1 << 1, 1 << 0 | 1 << 2, true),
array('any', 1 << 0 | 1 << 1, 1 << 2, false),
array('equal', 1 << 0 | 1 << 1, 1 << 0, false),
array('equal', 1 << 0 | 1 << 1, 1 << 1, false),
array('equal', 1 << 0 | 1 << 1, 1 << 0 | 1 << 1, true),
);
return [
['all', 1 << 0 | 1 << 1, 1 << 0, true],
['all', 1 << 0 | 1 << 1, 1 << 2, false],
['all', 1 << 0 | 1 << 10, 1 << 0 | 1 << 10, true],
['all', 1 << 0 | 1 << 1, 1 << 0 | 1 << 1 || 1 << 2, false],
['any', 1 << 0 | 1 << 1, 1 << 0, true],
['any', 1 << 0 | 1 << 1, 1 << 0 | 1 << 2, true],
['any', 1 << 0 | 1 << 1, 1 << 2, false],
['equal', 1 << 0 | 1 << 1, 1 << 0, false],
['equal', 1 << 0 | 1 << 1, 1 << 1, false],
['equal', 1 << 0 | 1 << 1, 1 << 0 | 1 << 1, true],
];
}
protected function getAcl($strategy)
{
static $id = 1;
return new Acl($id++, new ObjectIdentity(1, 'Foo'), $strategy, array(), true);
return new Acl($id++, new ObjectIdentity(1, 'Foo'), $strategy, [], true);
}
}
@@ -11,11 +11,11 @@
namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
class RoleSecurityIdentityTest extends \PHPUnit_Framework_TestCase
class RoleSecurityIdentityTest extends \PHPUnit\Framework\TestCase
{
public function testConstructor()
{
@@ -24,8 +24,15 @@ class RoleSecurityIdentityTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('ROLE_FOO', $id->getRole());
}
/**
* @group legacy
*/
public function testConstructorWithRoleInstance()
{
if (!class_exists(\Symfony\Component\Security\Core\Role\Role::class)) {
$this->markTestSkipped();
}
$id = new RoleSecurityIdentity(new Role('ROLE_FOO'));
$this->assertEquals('ROLE_FOO', $id->getRole());
@@ -43,13 +50,26 @@ class RoleSecurityIdentityTest extends \PHPUnit_Framework_TestCase
}
}
/**
* @group legacy
*/
public function testDeprecatedRoleClassEquals()
{
if (!class_exists(Role::class)) {
$this->markTestSkipped();
}
$id1 = new RoleSecurityIdentity('ROLE_FOO');
$id2 = new RoleSecurityIdentity(new Role('ROLE_FOO'));
$this->assertTrue($id1->equals($id2));
}
public function getCompareData()
{
return array(
array(new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity('ROLE_FOO'), true),
array(new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity(new Role('ROLE_FOO')), true),
array(new RoleSecurityIdentity('ROLE_USER'), new RoleSecurityIdentity('ROLE_FOO'), false),
array(new RoleSecurityIdentity('ROLE_FOO'), new UserSecurityIdentity('ROLE_FOO', 'Foo'), false),
);
return [
[new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity('ROLE_FOO'), true],
[new RoleSecurityIdentity('ROLE_USER'), new RoleSecurityIdentity('ROLE_FOO'), false],
[new RoleSecurityIdentity('ROLE_FOO'), new UserSecurityIdentity('ROLE_FOO', 'Foo'), false],
];
}
}
@@ -11,12 +11,17 @@
namespace Symfony\Component\Security\Acl\Tests\Domain;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\SecurityIdentityRetrievalStrategy;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\Security\Core\User\UserInterface;
class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
class SecurityIdentityRetrievalStrategyTest extends TestCase
{
/**
* @dataProvider getSecurityIdentityRetrievalTests
@@ -24,18 +29,18 @@ class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
public function testGetSecurityIdentities($user, array $roles, $authenticationStatus, array $sids)
{
if ('anonymous' === $authenticationStatus) {
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken')
->disableOriginalConstructor()
->getMock();
$token = $this->getMockBuilder(AnonymousToken::class)
->disableOriginalConstructor()
->getMock();
} else {
$class = '';
if (is_string($user)) {
if (\is_string($user)) {
$class = 'MyCustomTokenImpl';
}
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')
->setMockClassName($class)
->getMock();
$token = $this->getMockBuilder(AbstractToken::class)
->setMockClassName($class)
->getMock();
}
if (method_exists($token, 'getRoleNames')) {
@@ -44,7 +49,7 @@ class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
$token
->expects($this->once())
->method('getRoleNames')
->will($this->returnValue(array('foo')))
->willReturn(['foo'])
;
} else {
$strategy = $this->getStrategy($roles, $authenticationStatus, true);
@@ -52,7 +57,7 @@ class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
$token
->expects($this->once())
->method('getRoles')
->will($this->returnValue(array(new Role('foo'))))
->willReturn([new Role('foo')])
;
}
@@ -65,7 +70,7 @@ class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
$token
->expects($this->once())
->method('getUser')
->will($this->returnValue($user))
->willReturn($user)
;
}
@@ -84,55 +89,58 @@ class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
public function getSecurityIdentityRetrievalTests()
{
return array(
array($this->getAccount('johannes', 'FooUser'), array('ROLE_USER', 'ROLE_SUPERADMIN'), 'fullFledged', array(
return [
[$this->getAccount('johannes', 'FooUser'), ['ROLE_USER', 'ROLE_SUPERADMIN'], 'fullFledged', [
new UserSecurityIdentity('johannes', 'FooUser'),
new RoleSecurityIdentity('ROLE_USER'),
new RoleSecurityIdentity('ROLE_SUPERADMIN'),
new RoleSecurityIdentity('IS_AUTHENTICATED_FULLY'),
new RoleSecurityIdentity('IS_AUTHENTICATED_REMEMBERED'),
new RoleSecurityIdentity('IS_AUTHENTICATED_ANONYMOUSLY'),
)),
array('johannes', array('ROLE_FOO'), 'fullFledged', array(
]],
['johannes', ['ROLE_FOO'], 'fullFledged', [
new UserSecurityIdentity('johannes', 'MyCustomTokenImpl'),
new RoleSecurityIdentity('ROLE_FOO'),
new RoleSecurityIdentity('IS_AUTHENTICATED_FULLY'),
new RoleSecurityIdentity('IS_AUTHENTICATED_REMEMBERED'),
new RoleSecurityIdentity('IS_AUTHENTICATED_ANONYMOUSLY'),
)),
array(new CustomUserImpl('johannes'), array('ROLE_FOO'), 'fullFledged', array(
]],
[new CustomUserImpl('johannes'), ['ROLE_FOO'], 'fullFledged', [
new UserSecurityIdentity('johannes', 'Symfony\Component\Security\Acl\Tests\Domain\CustomUserImpl'),
new RoleSecurityIdentity('ROLE_FOO'),
new RoleSecurityIdentity('IS_AUTHENTICATED_FULLY'),
new RoleSecurityIdentity('IS_AUTHENTICATED_REMEMBERED'),
new RoleSecurityIdentity('IS_AUTHENTICATED_ANONYMOUSLY'),
)),
array($this->getAccount('foo', 'FooBarUser'), array('ROLE_FOO'), 'rememberMe', array(
]],
[$this->getAccount('foo', 'FooBarUser'), ['ROLE_FOO'], 'rememberMe', [
new UserSecurityIdentity('foo', 'FooBarUser'),
new RoleSecurityIdentity('ROLE_FOO'),
new RoleSecurityIdentity('IS_AUTHENTICATED_REMEMBERED'),
new RoleSecurityIdentity('IS_AUTHENTICATED_ANONYMOUSLY'),
)),
array('guest', array('ROLE_FOO'), 'anonymous', array(
]],
['guest', ['ROLE_FOO'], 'anonymous', [
new RoleSecurityIdentity('ROLE_FOO'),
new RoleSecurityIdentity('IS_AUTHENTICATED_ANONYMOUSLY'),
)),
);
]],
];
}
protected function getAccount($username, $class)
{
$account = $this->getMock('Symfony\Component\Security\Core\User\UserInterface', array(), array(), $class);
$account = $this->getMockBuilder(UserInterface::class)
->setMockClassName($class)
->getMock()
;
$account
->expects($this->any())
->method('getUsername')
->will($this->returnValue($username))
->willReturn($username)
;
return $account;
}
protected function getStrategy(array $roles = array(), $authenticationStatus = 'fullFledged', $isBC = false)
protected function getStrategy(array $roles = [], $authenticationStatus = 'fullFledged', $isBC = false)
{
$roleHierarchyBuilder = $this->getMockBuilder('Symfony\Component\Security\Core\Role\RoleHierarchyInterface')
->disableProxyingToOriginalMethods()
@@ -146,7 +154,7 @@ class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
->expects($this->any())
->method('getReachableRoles')
->with($this->equalTo([new Role('foo')]))
->will($this->returnValue($roles));
->willReturn($roles);
} else {
$roleHierarchy = $roleHierarchyBuilder->setMethods(['getReachableRoleNames'])
->getMockForAbstractClass();
@@ -155,23 +163,21 @@ class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
->expects($this->any())
->method('getReachableRoleNames')
->with($this->equalTo(['foo']))
->will($this->returnValue($roles));
->willReturn($roles);
}
$trustResolver = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface', array(), array('', ''));
$trustResolver = $this->createMock(AuthenticationTrustResolverInterface::class);
$trustResolver
->expects($this->at(0))
->method('isAnonymous')
->will($this->returnValue('anonymous' === $authenticationStatus))
->willReturn('anonymous' === $authenticationStatus)
;
if ('fullFledged' === $authenticationStatus) {
$trustResolver
->expects($this->once())
->method('isFullFledged')
->will($this->returnValue(true))
->willReturn(true)
;
$trustResolver
->expects($this->never())
@@ -181,28 +187,27 @@ class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
$trustResolver
->expects($this->once())
->method('isFullFledged')
->will($this->returnValue(false))
->willReturn(false)
;
$trustResolver
->expects($this->once())
->method('isRememberMe')
->will($this->returnValue(true))
->willReturn(true)
;
} else {
$trustResolver
->expects($this->at(1))
->method('isAnonymous')
->will($this->returnValue(true))
->willReturn(true)
;
$trustResolver
->expects($this->once())
->method('isFullFledged')
->will($this->returnValue(false))
->willReturn(false)
;
$trustResolver
->expects($this->once())
->method('isRememberMe')
->will($this->returnValue(false))
->willReturn(false)
;
}
@@ -14,7 +14,7 @@ namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
class UserSecurityIdentityTest extends \PHPUnit_Framework_TestCase
class UserSecurityIdentityTest extends \PHPUnit\Framework\TestCase
{
public function testConstructor()
{
@@ -49,25 +49,25 @@ class UserSecurityIdentityTest extends \PHPUnit_Framework_TestCase
$account
->expects($this->any())
->method('getUsername')
->will($this->returnValue('foo'))
->willReturn('foo')
;
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
$token = $this->createMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
$token
->expects($this->any())
->method('getUser')
->will($this->returnValue($account))
->willReturn($account)
;
return array(
array(new UserSecurityIdentity('foo', 'Foo'), new UserSecurityIdentity('foo', 'Foo'), true),
array(new UserSecurityIdentity('foo', 'Bar'), new UserSecurityIdentity('foo', 'Foo'), false),
array(new UserSecurityIdentity('foo', 'Foo'), new UserSecurityIdentity('bar', 'Foo'), false),
array(new UserSecurityIdentity('foo', 'Foo'), UserSecurityIdentity::fromAccount($account), false),
array(new UserSecurityIdentity('bla', 'Foo'), new UserSecurityIdentity('blub', 'Foo'), false),
array(new UserSecurityIdentity('foo', 'Foo'), new RoleSecurityIdentity('foo'), false),
array(new UserSecurityIdentity('foo', 'Foo'), UserSecurityIdentity::fromToken($token), false),
array(new UserSecurityIdentity('foo', 'USI_AccountImpl'), UserSecurityIdentity::fromToken($token), true),
);
return [
[new UserSecurityIdentity('foo', 'Foo'), new UserSecurityIdentity('foo', 'Foo'), true],
[new UserSecurityIdentity('foo', 'Bar'), new UserSecurityIdentity('foo', 'Foo'), false],
[new UserSecurityIdentity('foo', 'Foo'), new UserSecurityIdentity('bar', 'Foo'), false],
[new UserSecurityIdentity('foo', 'Foo'), UserSecurityIdentity::fromAccount($account), false],
[new UserSecurityIdentity('bla', 'Foo'), new UserSecurityIdentity('blub', 'Foo'), false],
[new UserSecurityIdentity('foo', 'Foo'), new RoleSecurityIdentity('foo'), false],
[new UserSecurityIdentity('foo', 'Foo'), UserSecurityIdentity::fromToken($token), false],
[new UserSecurityIdentity('foo', 'USI_AccountImpl'), UserSecurityIdentity::fromToken($token), true],
];
}
}
@@ -13,7 +13,7 @@ namespace Symfony\Component\Security\Acl\Tests\Permission;
use Symfony\Component\Security\Acl\Permission\BasicPermissionMap;
class BasicPermissionMapTest extends \PHPUnit_Framework_TestCase
class BasicPermissionMapTest extends \PHPUnit\Framework\TestCase
{
public function testGetMasksReturnsNullWhenNotSupportedMask()
{
@@ -13,25 +13,26 @@ namespace Symfony\Component\Security\Acl\Tests\Permission;
use Symfony\Component\Security\Acl\Permission\MaskBuilder;
class MaskBuilderTest extends \PHPUnit_Framework_TestCase
class MaskBuilderTest extends \PHPUnit\Framework\TestCase
{
/**
* @expectedException \InvalidArgumentException
* @dataProvider getInvalidConstructorData
*/
public function testConstructorWithNonInteger($invalidMask)
{
$this->expectException(\InvalidArgumentException::class);
new MaskBuilder($invalidMask);
}
public function getInvalidConstructorData()
{
return array(
array(234.463),
array('asdgasdf'),
array(array()),
array(new \stdClass()),
);
return [
[234.463],
['asdgasdf'],
[[]],
[new \stdClass()],
];
}
public function testConstructorWithoutArguments()
+80 -80
View File
@@ -11,29 +11,29 @@
namespace Symfony\Component\Security\Acl\Tests\Voter;
use Symfony\Component\Security\Acl\Exception\NoAceFoundException;
use Symfony\Component\Security\Acl\Voter\FieldVote;
use Symfony\Component\Security\Acl\Exception\AclNotFoundException;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
use Symfony\Component\Security\Acl\Exception\AclNotFoundException;
use Symfony\Component\Security\Acl\Exception\NoAceFoundException;
use Symfony\Component\Security\Acl\Voter\AclVoter;
use Symfony\Component\Security\Acl\Voter\FieldVote;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
class AclVoterTest extends \PHPUnit_Framework_TestCase
class AclVoterTest extends \PHPUnit\Framework\TestCase
{
/**
* @dataProvider getSupportsAttributeTests
*/
public function testSupportsAttribute($attribute, $supported)
{
list($voter, , $permissionMap) = $this->getVoter(true, false);
[$voter, , $permissionMap] = $this->getVoter(true, false);
$permissionMap
->expects($this->once())
->method('contains')
->with($this->identicalTo($attribute))
->will($this->returnValue($supported))
->willReturn($supported)
;
$this->assertSame($supported, $voter->supportsAttribute($attribute));
@@ -44,27 +44,27 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
*/
public function testSupportsAttributeNonString($attribute)
{
list($voter) = $this->getVoter(true, false);
[$voter] = $this->getVoter(true, false);
$this->assertFalse($voter->supportsAttribute($attribute));
}
public function getSupportsAttributeTests()
{
return array(
array('foo', true),
array('foo', false),
);
return [
['foo', true],
['foo', false],
];
}
public function getSupportsAttributeNonStringTests()
{
return array(
array(new \stdClass()),
array(1),
array(true),
array(array()),
);
return [
[new \stdClass()],
[1],
[true],
[[]],
];
}
/**
@@ -72,30 +72,30 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
*/
public function testSupportsClass($class)
{
list($voter) = $this->getVoter();
[$voter] = $this->getVoter();
$this->assertTrue($voter->supportsClass($class));
}
public function getSupportsClassTests()
{
return array(
array('foo'),
array('bar'),
array('moo'),
);
return [
['foo'],
['bar'],
['moo'],
];
}
public function testVote()
{
list($voter, , $permissionMap) = $this->getVoter();
[$voter, , $permissionMap] = $this->getVoter();
$permissionMap
->expects($this->atLeastOnce())
->method('getMasks')
->will($this->returnValue(null))
->willReturn(null)
;
$this->assertSame(VoterInterface::ACCESS_ABSTAIN, $voter->vote($this->getToken(), null, array('VIEW', 'EDIT', 'DELETE')));
$this->assertSame(VoterInterface::ACCESS_ABSTAIN, $voter->vote($this->getToken(), null, ['VIEW', 'EDIT', 'DELETE']));
}
/**
@@ -103,11 +103,11 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
*/
public function testVoteWhenNoObjectIsPassed($allowIfObjectIdentityUnavailable)
{
list($voter, , $permissionMap) = $this->getVoter($allowIfObjectIdentityUnavailable);
[$voter, , $permissionMap] = $this->getVoter($allowIfObjectIdentityUnavailable);
$permissionMap
->expects($this->once())
->method('getMasks')
->will($this->returnValue(array()))
->willReturn([])
;
if ($allowIfObjectIdentityUnavailable) {
@@ -116,7 +116,7 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
$vote = VoterInterface::ACCESS_ABSTAIN;
}
$this->assertSame($vote, $voter->vote($this->getToken(), null, array('VIEW')));
$this->assertSame($vote, $voter->vote($this->getToken(), null, ['VIEW']));
}
/**
@@ -124,17 +124,17 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
*/
public function testVoteWhenOidStrategyReturnsNull($allowIfUnavailable)
{
list($voter, , $permissionMap, $oidStrategy) = $this->getVoter($allowIfUnavailable);
[$voter, , $permissionMap, $oidStrategy] = $this->getVoter($allowIfUnavailable);
$permissionMap
->expects($this->once())
->method('getMasks')
->will($this->returnValue(array()))
->willReturn([])
;
$oidStrategy
->expects($this->once())
->method('getObjectIdentity')
->will($this->returnValue(null))
->willReturn(null)
;
if ($allowIfUnavailable) {
@@ -143,34 +143,34 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
$vote = VoterInterface::ACCESS_ABSTAIN;
}
$this->assertSame($vote, $voter->vote($this->getToken(), new \stdClass(), array('VIEW')));
$this->assertSame($vote, $voter->vote($this->getToken(), new \stdClass(), ['VIEW']));
}
public function getTrueFalseTests()
{
return array(array(true), array(false));
return [[true], [false]];
}
public function testVoteNoAclFound()
{
list($voter, $provider, $permissionMap, $oidStrategy, $sidStrategy) = $this->getVoter();
[$voter, $provider, $permissionMap, $oidStrategy, $sidStrategy] = $this->getVoter();
$permissionMap
->expects($this->once())
->method('getMasks')
->will($this->returnValue(array()))
->willReturn([])
;
$oidStrategy
->expects($this->once())
->method('getObjectIdentity')
->will($this->returnValue($oid = new ObjectIdentity('1', 'Foo')))
->willReturn($oid = new ObjectIdentity('1', 'Foo'))
;
$sidStrategy
->expects($this->once())
->method('getSecurityIdentities')
->will($this->returnValue($sids = array(new UserSecurityIdentity('johannes', 'Foo'), new RoleSecurityIdentity('ROLE_FOO'))))
->willReturn($sids = [new UserSecurityIdentity('johannes', 'Foo'), new RoleSecurityIdentity('ROLE_FOO')])
;
$provider
@@ -180,7 +180,7 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
->will($this->throwException(new AclNotFoundException('Not found.')))
;
$this->assertSame(VoterInterface::ACCESS_DENIED, $voter->vote($this->getToken(), new \stdClass(), array('VIEW')));
$this->assertSame(VoterInterface::ACCESS_DENIED, $voter->vote($this->getToken(), new \stdClass(), ['VIEW']));
}
/**
@@ -188,39 +188,39 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
*/
public function testVoteGrantsAccess($grant)
{
list($voter, $provider, $permissionMap, $oidStrategy, $sidStrategy) = $this->getVoter();
[$voter, $provider, $permissionMap, $oidStrategy, $sidStrategy] = $this->getVoter();
$permissionMap
->expects($this->once())
->method('getMasks')
->with($this->equalTo('VIEW'))
->will($this->returnValue($masks = array(1, 2, 3)))
->willReturn($masks = [1, 2, 3])
;
$oidStrategy
->expects($this->once())
->method('getObjectIdentity')
->will($this->returnValue($oid = new ObjectIdentity('1', 'Foo')))
->willReturn($oid = new ObjectIdentity('1', 'Foo'))
;
$sidStrategy
->expects($this->once())
->method('getSecurityIdentities')
->will($this->returnValue($sids = array(new UserSecurityIdentity('johannes', 'Foo'), new RoleSecurityIdentity('ROLE_FOO'))))
->willReturn($sids = [new UserSecurityIdentity('johannes', 'Foo'), new RoleSecurityIdentity('ROLE_FOO')])
;
$provider
->expects($this->once())
->method('findAcl')
->with($this->equalTo($oid), $this->equalTo($sids))
->will($this->returnValue($acl = $this->getMock('Symfony\Component\Security\Acl\Model\AclInterface')))
->willReturn($acl = $this->createMock('Symfony\Component\Security\Acl\Model\AclInterface'))
;
$acl
->expects($this->once())
->method('isGranted')
->with($this->identicalTo($masks), $this->equalTo($sids), $this->isFalse())
->will($this->returnValue($grant))
->willReturn($grant)
;
if ($grant) {
@@ -229,37 +229,37 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
$vote = VoterInterface::ACCESS_DENIED;
}
$this->assertSame($vote, $voter->vote($this->getToken(), new \stdClass(), array('VIEW')));
$this->assertSame($vote, $voter->vote($this->getToken(), new \stdClass(), ['VIEW']));
}
public function testVoteNoAceFound()
{
list($voter, $provider, $permissionMap, $oidStrategy, $sidStrategy) = $this->getVoter();
[$voter, $provider, $permissionMap, $oidStrategy, $sidStrategy] = $this->getVoter();
$permissionMap
->expects($this->once())
->method('getMasks')
->with($this->equalTo('VIEW'))
->will($this->returnValue($masks = array(1, 2, 3)))
->willReturn($masks = [1, 2, 3])
;
$oidStrategy
->expects($this->once())
->method('getObjectIdentity')
->will($this->returnValue($oid = new ObjectIdentity('1', 'Foo')))
->willReturn($oid = new ObjectIdentity('1', 'Foo'))
;
$sidStrategy
->expects($this->once())
->method('getSecurityIdentities')
->will($this->returnValue($sids = array(new UserSecurityIdentity('johannes', 'Foo'), new RoleSecurityIdentity('ROLE_FOO'))))
->willReturn($sids = [new UserSecurityIdentity('johannes', 'Foo'), new RoleSecurityIdentity('ROLE_FOO')])
;
$provider
->expects($this->once())
->method('findAcl')
->with($this->equalTo($oid), $this->equalTo($sids))
->will($this->returnValue($acl = $this->getMock('Symfony\Component\Security\Acl\Model\AclInterface')))
->willReturn($acl = $this->createMock('Symfony\Component\Security\Acl\Model\AclInterface'))
;
$acl
@@ -269,7 +269,7 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
->will($this->throwException(new NoAceFoundException('No ACE')))
;
$this->assertSame(VoterInterface::ACCESS_DENIED, $voter->vote($this->getToken(), new \stdClass(), array('VIEW')));
$this->assertSame(VoterInterface::ACCESS_DENIED, $voter->vote($this->getToken(), new \stdClass(), ['VIEW']));
}
/**
@@ -277,39 +277,39 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
*/
public function testVoteGrantsFieldAccess($grant)
{
list($voter, $provider, $permissionMap, $oidStrategy, $sidStrategy) = $this->getVoter();
[$voter, $provider, $permissionMap, $oidStrategy, $sidStrategy] = $this->getVoter();
$permissionMap
->expects($this->once())
->method('getMasks')
->with($this->equalTo('VIEW'))
->will($this->returnValue($masks = array(1, 2, 3)))
->willReturn($masks = [1, 2, 3])
;
$oidStrategy
->expects($this->once())
->method('getObjectIdentity')
->will($this->returnValue($oid = new ObjectIdentity('1', 'Foo')))
->willReturn($oid = new ObjectIdentity('1', 'Foo'))
;
$sidStrategy
->expects($this->once())
->method('getSecurityIdentities')
->will($this->returnValue($sids = array(new UserSecurityIdentity('johannes', 'Foo'), new RoleSecurityIdentity('ROLE_FOO'))))
->willReturn($sids = [new UserSecurityIdentity('johannes', 'Foo'), new RoleSecurityIdentity('ROLE_FOO')])
;
$provider
->expects($this->once())
->method('findAcl')
->with($this->equalTo($oid), $this->equalTo($sids))
->will($this->returnValue($acl = $this->getMock('Symfony\Component\Security\Acl\Model\AclInterface')))
->willReturn($acl = $this->createMock('Symfony\Component\Security\Acl\Model\AclInterface'))
;
$acl
->expects($this->once())
->method('isFieldGranted')
->with($this->identicalTo('foo'), $this->identicalTo($masks), $this->equalTo($sids), $this->isFalse())
->will($this->returnValue($grant))
->willReturn($grant)
;
if ($grant) {
@@ -318,37 +318,37 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
$vote = VoterInterface::ACCESS_DENIED;
}
$this->assertSame($vote, $voter->vote($this->getToken(), new FieldVote(new \stdClass(), 'foo'), array('VIEW')));
$this->assertSame($vote, $voter->vote($this->getToken(), new FieldVote(new \stdClass(), 'foo'), ['VIEW']));
}
public function testVoteNoFieldAceFound()
{
list($voter, $provider, $permissionMap, $oidStrategy, $sidStrategy) = $this->getVoter();
[$voter, $provider, $permissionMap, $oidStrategy, $sidStrategy] = $this->getVoter();
$permissionMap
->expects($this->once())
->method('getMasks')
->with($this->equalTo('VIEW'))
->will($this->returnValue($masks = array(1, 2, 3)))
->willReturn($masks = [1, 2, 3])
;
$oidStrategy
->expects($this->once())
->method('getObjectIdentity')
->will($this->returnValue($oid = new ObjectIdentity('1', 'Foo')))
->willReturn($oid = new ObjectIdentity('1', 'Foo'))
;
$sidStrategy
->expects($this->once())
->method('getSecurityIdentities')
->will($this->returnValue($sids = array(new UserSecurityIdentity('johannes', 'Foo'), new RoleSecurityIdentity('ROLE_FOO'))))
->willReturn($sids = [new UserSecurityIdentity('johannes', 'Foo'), new RoleSecurityIdentity('ROLE_FOO')])
;
$provider
->expects($this->once())
->method('findAcl')
->with($this->equalTo($oid), $this->equalTo($sids))
->will($this->returnValue($acl = $this->getMock('Symfony\Component\Security\Acl\Model\AclInterface')))
->willReturn($acl = $this->createMock('Symfony\Component\Security\Acl\Model\AclInterface'))
;
$acl
@@ -358,12 +358,12 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
->will($this->throwException(new NoAceFoundException('No ACE')))
;
$this->assertSame(VoterInterface::ACCESS_DENIED, $voter->vote($this->getToken(), new FieldVote(new \stdClass(), 'foo'), array('VIEW')));
$this->assertSame(VoterInterface::ACCESS_DENIED, $voter->vote($this->getToken(), new FieldVote(new \stdClass(), 'foo'), ['VIEW']));
}
public function testWhenReceivingAnObjectIdentityInterfaceWeDontRetrieveANewObjectIdentity()
{
list($voter, $provider, $permissionMap, $oidStrategy, $sidStrategy) = $this->getVoter();
[$voter, $provider, $permissionMap, $oidStrategy, $sidStrategy] = $this->getVoter();
$oid = new ObjectIdentity('someID', 'someType');
@@ -371,7 +371,7 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
->expects($this->once())
->method('getMasks')
->with($this->equalTo('VIEW'))
->will($this->returnValue($masks = array(1, 2, 3)))
->willReturn($masks = [1, 2, 3])
;
$oidStrategy
@@ -382,14 +382,14 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
$sidStrategy
->expects($this->once())
->method('getSecurityIdentities')
->will($this->returnValue($sids = array(new UserSecurityIdentity('johannes', 'Foo'), new RoleSecurityIdentity('ROLE_FOO'))))
->willReturn($sids = [new UserSecurityIdentity('johannes', 'Foo'), new RoleSecurityIdentity('ROLE_FOO')])
;
$provider
->expects($this->once())
->method('findAcl')
->with($this->equalTo($oid), $this->equalTo($sids))
->will($this->returnValue($acl = $this->getMock('Symfony\Component\Security\Acl\Model\AclInterface')))
->willReturn($acl = $this->createMock('Symfony\Component\Security\Acl\Model\AclInterface'))
;
$acl
@@ -399,34 +399,34 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase
->will($this->throwException(new NoAceFoundException('No ACE')))
;
$voter->vote($this->getToken(), $oid, array('VIEW'));
$voter->vote($this->getToken(), $oid, ['VIEW']);
}
protected function getToken()
{
return $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
return $this->createMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
}
protected function getVoter($allowIfObjectIdentityUnavailable = true, $alwaysContains = true)
{
$provider = $this->getMock('Symfony\Component\Security\Acl\Model\AclProviderInterface');
$permissionMap = $this->getMock('Symfony\Component\Security\Acl\Permission\PermissionMapInterface');
$oidStrategy = $this->getMock('Symfony\Component\Security\Acl\Model\ObjectIdentityRetrievalStrategyInterface');
$sidStrategy = $this->getMock('Symfony\Component\Security\Acl\Model\SecurityIdentityRetrievalStrategyInterface');
$provider = $this->createMock('Symfony\Component\Security\Acl\Model\AclProviderInterface');
$permissionMap = $this->createMock('Symfony\Component\Security\Acl\Permission\PermissionMapInterface');
$oidStrategy = $this->createMock('Symfony\Component\Security\Acl\Model\ObjectIdentityRetrievalStrategyInterface');
$sidStrategy = $this->createMock('Symfony\Component\Security\Acl\Model\SecurityIdentityRetrievalStrategyInterface');
if ($alwaysContains) {
$permissionMap
->expects($this->any())
->method('contains')
->will($this->returnValue(true));
->willReturn(true);
}
return array(
return [
new AclVoter($provider, $oidStrategy, $sidStrategy, $permissionMap, null, $allowIfObjectIdentityUnavailable),
$provider,
$permissionMap,
$oidStrategy,
$sidStrategy,
);
];
}
}