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,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);
}
}