ea6a359272
* Upd: Add Symfony 4 Compatibility #SymfonyConHackday2017 * Upd: Configure visibility of services for SF4 * Updated composer to allow Symfony 4.0 * Updated composer to allow Symfony 4.0 * PropelBundle for Symfony 4 * Upd: Travis configuration * Upd: PHP 5 not supported anymore by PHPUnit * Upd: Removing old SF version + PHPUnit correction * * Removed param that was removed in symfony/yaml afb873f * Updated format of object dumping as deprecated tags using colon symfony/yaml 38d3087 * * Added commands to console.xml as symfony no longer auto registers bundle commands * Updated two services to public * * Removed deprecated getMock calls for new createMock calls. * * Add stub for additional abstract method * * Updated schema locator test * reverted unnecessary changes to abstract command and schemal locator * Added fixtures for schema testing. * * Updated schema locator test * reverted unnecessary changes to abstract command and schemal locator * Added fixtures for schema testing. * * Removed unnecessary default for services * Updated readme to reflect symfony version support
136 lines
5.1 KiB
PHP
136 lines
5.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* This file is part of the PropelBundle package.
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*
|
|
* @license MIT License
|
|
*/
|
|
|
|
namespace Propel\Bundle\PropelBundle\Tests\Model\Acl;
|
|
|
|
use Propel\Bundle\PropelBundle\Model\Acl\Entry;
|
|
use Propel\Bundle\PropelBundle\Model\Acl\EntryQuery;
|
|
use Propel\Bundle\PropelBundle\Model\Acl\SecurityIdentity;
|
|
|
|
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
|
|
|
|
use Propel\Bundle\PropelBundle\Tests\AclTestCase;
|
|
|
|
/**
|
|
* @author Toni Uebernickel <tuebernickel@gmail.com>
|
|
*/
|
|
class EntryQueryTest extends AclTestCase
|
|
{
|
|
public function setUp()
|
|
{
|
|
parent::setUp();
|
|
|
|
$obj = $this->createModelObjectIdentity(1);
|
|
$entry = $this->createEntry();
|
|
$entry
|
|
->setSecurityIdentity(SecurityIdentity::fromAclIdentity($this->getRoleSecurityIdentity('ROLE_USER')))
|
|
->setAclClass($obj->getAclClass())
|
|
->setMask(64)
|
|
;
|
|
$obj->addEntry($entry)->save($this->con);
|
|
}
|
|
|
|
public function testFindByAclIdentityInvalidSecurityIdentity()
|
|
{
|
|
$this->expectException('InvalidArgumentException');
|
|
EntryQuery::create()->findByAclIdentity($this->getAclObjectIdentity(), array('foo'), $this->con);
|
|
}
|
|
|
|
public function testFindByAclIdentityInvalidSecurityIdentityObject()
|
|
{
|
|
$this->expectException('InvalidArgumentException');
|
|
EntryQuery::create()->findByAclIdentity($this->getAclObjectIdentity(), array(new \stdClass()), $this->con);
|
|
}
|
|
|
|
public function testFindByAclIdentityNotExists()
|
|
{
|
|
$this->assertCount(0, EntryQuery::create()->findByAclIdentity($this->getAclObjectIdentity(2), array(), $this->con));
|
|
}
|
|
|
|
public function testFindByAclIdentitySecurityIdentityNotFound()
|
|
{
|
|
$this->assertCount(0, EntryQuery::create()->findByAclIdentity($this->getAclObjectIdentity(1), array($this->getRoleSecurityIdentity('ROLE_ADMIN')), $this->con));
|
|
}
|
|
|
|
public function testFindByAclIdentity()
|
|
{
|
|
// Another Entry, should not be found (different ObjectIdentity).
|
|
$obj = $this->createModelObjectIdentity(2);
|
|
$entry = $this->createEntry();
|
|
$entry
|
|
->setSecurityIdentity(SecurityIdentity::fromAclIdentity($this->getRoleSecurityIdentity()))
|
|
->setAclClass($obj->getAclClass())
|
|
->setMask(64)
|
|
;
|
|
$obj->addEntry($entry)->save($this->con);
|
|
|
|
$entries = EntryQuery::create()->findByAclIdentity($this->getAclObjectIdentity(1), array(), $this->con);
|
|
$this->assertCount(1, $entries);
|
|
$this->assertEquals(1, $entries[0]->getObjectIdentityId());
|
|
|
|
// A class based entry for the wrong ObjectIdentity.
|
|
$classEntry = $this->createEntry();
|
|
$classEntry
|
|
->setObjectIdentityId(2)
|
|
->setSecurityIdentity(SecurityIdentity::fromAclIdentity($this->getRoleSecurityIdentity()))
|
|
->setAclClass($obj->getAclClass())
|
|
->setMask(64)
|
|
->save($this->con)
|
|
;
|
|
|
|
// A class based entry for the correct ObjectIdentity.
|
|
$classEntry = $this->createEntry();
|
|
$classEntry
|
|
->setObjectIdentityId(null)
|
|
->setSecurityIdentity(SecurityIdentity::fromAclIdentity($this->getRoleSecurityIdentity()))
|
|
->setAclClass($this->getAclClass())
|
|
->setMask(64)
|
|
->save($this->con)
|
|
;
|
|
|
|
$this->assertEquals(4, EntryQuery::create()->count($this->con));
|
|
|
|
$entries = EntryQuery::create()->findByAclIdentity($this->getAclObjectIdentity(1), array(), $this->con);
|
|
$this->assertCount(2, $entries);
|
|
$this->assertEquals($obj->getClassId(), $entries[0]->getClassId());
|
|
$this->assertEquals($obj->getClassId(), $entries[1]->getClassId());
|
|
}
|
|
|
|
public function testFindByAclIdentityFilterSecurityIdentity()
|
|
{
|
|
// Another Entry, should not be found (different SecurityIdentity).
|
|
$entry = $this->createEntry();
|
|
$entry
|
|
->setObjectIdentityId(1)
|
|
->setSecurityIdentity(SecurityIdentity::fromAclIdentity($this->getRoleSecurityIdentity('ROLE_ADMIN')))
|
|
->setAclClass($this->getAclClass())
|
|
->setMask(64)
|
|
->save($this->con)
|
|
;
|
|
|
|
$this->assertEquals(2, EntryQuery::create()->count($this->con));
|
|
|
|
$entries = EntryQuery::create()->findByAclIdentity($this->getAclObjectIdentity(1), array($this->getRoleSecurityIdentity('ROLE_USER')), $this->con);
|
|
$this->assertCount(1, $entries);
|
|
$this->assertEquals(SecurityIdentity::fromAclIdentity($this->getRoleSecurityIdentity('ROLE_USER'))->getId(), $entries[0]->getSecurityIdentityId());
|
|
}
|
|
|
|
public function testFindByAclIdentityOnlyClassEntries()
|
|
{
|
|
$this->assertEquals(1, EntryQuery::create()->count($this->con));
|
|
EntryQuery::create()->findOne($this->con)
|
|
->setObjectIdentity(null)
|
|
->save($this->con);
|
|
|
|
$entries = EntryQuery::create()->findByAclIdentity($this->getAclObjectIdentity(1), array(), $this->con);
|
|
$this->assertCount(1, $entries);
|
|
}
|
|
}
|