Started to port ACL tests
This commit is contained in:
parent
3dda1cdc61
commit
6f92e55d20
104
Tests/AclTestCase.php
Normal file
104
Tests/AclTestCase.php
Normal file
|
@ -0,0 +1,104 @@
|
|||
<?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\PropelBundle\Tests;
|
||||
|
||||
use Propel\Generator\Util\QuickBuilder;
|
||||
|
||||
use Propel\PropelBundle\Model\Acl\AclClass;
|
||||
use Propel\PropelBundle\Model\Acl\Entry;
|
||||
use Propel\PropelBundle\Model\Acl\ObjectIdentity as ModelObjectIdentity;
|
||||
use Propel\PropelBundle\Security\Acl\MutableAclProvider;
|
||||
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
|
||||
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
|
||||
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
|
||||
|
||||
/**
|
||||
* AclTestCase
|
||||
*
|
||||
* @author Toni Uebernickel <tuebernickel@gmail.com>
|
||||
*/
|
||||
class AclTestCase extends TestCase
|
||||
{
|
||||
protected $con = null;
|
||||
protected $cache = null;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$schema = file_get_contents(__DIR__.'/../Resources/acl_schema.xml');
|
||||
|
||||
if (!class_exists('Propel\PropelBundle\Model\Acl\map\AclClassTableMap')) {
|
||||
$classTargets = array('tablemap', 'object', 'query');
|
||||
} else {
|
||||
$classTargets = array();
|
||||
}
|
||||
|
||||
$builder = new QuickBuilder();
|
||||
$builder->setSchema($schema);
|
||||
|
||||
$this->con = $builder->build($dsn = null, $user = null, $pass = null, $adapter = null, $classTargets);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Propel\PropelBundle\Model\Acl\ObjectIdentity
|
||||
*/
|
||||
protected function createModelObjectIdentity($identifier)
|
||||
{
|
||||
$aclClass = $this->getAclClass();
|
||||
$objIdentity = new ModelObjectIdentity();
|
||||
|
||||
$this->assertTrue((bool) $objIdentity
|
||||
->setAclClass($aclClass)
|
||||
->setIdentifier($identifier)
|
||||
->save($this->con)
|
||||
);
|
||||
|
||||
return $objIdentity;
|
||||
}
|
||||
|
||||
protected function createEntry()
|
||||
{
|
||||
$entry = new Entry();
|
||||
$entry
|
||||
->setAuditSuccess(false)
|
||||
->setAuditFailure(false)
|
||||
->setMask(64)
|
||||
->setGranting(true)
|
||||
->setGrantingStrategy('all')
|
||||
->setAceOrder(0)
|
||||
;
|
||||
|
||||
return $entry;
|
||||
}
|
||||
|
||||
protected function getAclClass()
|
||||
{
|
||||
return AclClass::fromAclObjectIdentity($this->getAclObjectIdentity(), $this->con);
|
||||
}
|
||||
|
||||
protected function getAclProvider()
|
||||
{
|
||||
return new MutableAclProvider(new PermissionGrantingStrategy(), $this->con, $this->cache);
|
||||
}
|
||||
|
||||
protected function getAclObjectIdentity($identifier = 1)
|
||||
{
|
||||
return new ObjectIdentity($identifier, 'Propel\PropelBundle\Tests\Fixtures\Model\Book');
|
||||
}
|
||||
|
||||
protected function getRoleSecurityIdentity($role = 'ROLE_USER')
|
||||
{
|
||||
return new RoleSecurityIdentity(new Role($role));
|
||||
}
|
||||
}
|
41
Tests/Model/AclClassTest.php
Normal file
41
Tests/Model/AclClassTest.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?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\PropelBundle\Tests\Model\Acl;
|
||||
|
||||
use Criteria;
|
||||
|
||||
use Propel\PropelBundle\Model\Acl\AclClass;
|
||||
use Propel\PropelBundle\Model\Acl\AclClassQuery;
|
||||
|
||||
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
|
||||
|
||||
use Propel\PropelBundle\Tests\AclTestCase;
|
||||
|
||||
/**
|
||||
* @author Toni Uebernickel <tuebernickel@gmail.com>
|
||||
*/
|
||||
class AclClassTest extends AclTestCase
|
||||
{
|
||||
public function testFromAclObjectIdentity()
|
||||
{
|
||||
$type = 'Merchant';
|
||||
|
||||
$aclClass = AclClass::fromAclObjectIdentity(new ObjectIdentity(5, $type), $this->con);
|
||||
$this->assertInstanceOf('Propel\PropelBundle\Model\Acl\AclClass', $aclClass);
|
||||
$this->assertEquals($type, $aclClass->getType());
|
||||
|
||||
$dbEntry = AclClassQuery::create()->findOne($this->con);
|
||||
$this->assertInstanceOf('Propel\PropelBundle\Model\Acl\AclClass', $dbEntry);
|
||||
$this->assertEquals($type, $dbEntry->getType());
|
||||
|
||||
$this->assertEquals($dbEntry->getId(), $aclClass->getId());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue