add tests for Acl\Domain\(Field)Entry
* fix (un)serialize of (Field)Entry
This commit is contained in:
parent
27daeebfb9
commit
7a12aef44b
|
@ -80,6 +80,8 @@ class Entry implements AuditableEntryInterface
|
|||
$this->mask,
|
||||
$this->isGranting,
|
||||
$this->strategy,
|
||||
$this->auditFailure,
|
||||
$this->auditSuccess,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -101,6 +103,8 @@ class Entry implements AuditableEntryInterface
|
|||
$this->mask,
|
||||
$this->isGranting,
|
||||
$this->strategy,
|
||||
$this->auditFailure,
|
||||
$this->auditSuccess,
|
||||
) = unserialize($serialized);
|
||||
|
||||
return $this;
|
||||
|
|
|
@ -51,4 +51,52 @@ class FieldEntry extends Entry implements FieldEntryInterface
|
|||
{
|
||||
return $this->field;
|
||||
}
|
||||
|
||||
/**
|
||||
* String representation of object
|
||||
*
|
||||
* @link http://php.net/manual/en/serializable.serialize.php
|
||||
*
|
||||
* @return string the string representation of the object or &null;
|
||||
*/
|
||||
public function serialize()
|
||||
{
|
||||
return serialize(array(
|
||||
$this->acl,
|
||||
$this->securityIdentity,
|
||||
$this->id,
|
||||
$this->mask,
|
||||
$this->isGranting,
|
||||
$this->strategy,
|
||||
$this->auditFailure,
|
||||
$this->auditSuccess,
|
||||
$this->field,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the object
|
||||
*
|
||||
* @link http://php.net/manual/en/serializable.unserialize.php
|
||||
*
|
||||
* @param string $serialized
|
||||
*
|
||||
* @return mixed the original value unserialized.
|
||||
*/
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
list(
|
||||
$this->acl,
|
||||
$this->securityIdentity,
|
||||
$this->id,
|
||||
$this->mask,
|
||||
$this->isGranting,
|
||||
$this->strategy,
|
||||
$this->auditFailure,
|
||||
$this->auditSuccess,
|
||||
$this->field,
|
||||
) = unserialize($serialized);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
71
Tests/Security/Acl/Domain/EntryTest.php
Normal file
71
Tests/Security/Acl/Domain/EntryTest.php
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?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\Security\Acl\Domain;
|
||||
|
||||
use PropelCollection;
|
||||
|
||||
use Propel\PropelBundle\Model\Acl\Entry as ModelEntry;
|
||||
use Propel\PropelBundle\Model\Acl\SecurityIdentity;
|
||||
|
||||
use Propel\PropelBundle\Security\Acl\Domain\Acl;
|
||||
use Propel\PropelBundle\Security\Acl\Domain\Entry;
|
||||
|
||||
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
|
||||
|
||||
use Propel\PropelBundle\Tests\AclTestCase;
|
||||
|
||||
/**
|
||||
* @author Toni Uebernickel <tuebernickel@gmail.com>
|
||||
*/
|
||||
class EntryTest extends AclTestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$collection = new PropelCollection();
|
||||
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
|
||||
$acl = new Acl($collection, $this->getAclObjectIdentity(), new PermissionGrantingStrategy());
|
||||
|
||||
$model = $this->createEntry();
|
||||
$model->setAuditFailure(true);
|
||||
$model->setSecurityIdentity(SecurityIdentity::fromAclIdentity($this->getRoleSecurityIdentity()));
|
||||
|
||||
$entry = new Entry($model, $acl);
|
||||
|
||||
$this->assertEquals($model->getMask(), $entry->getMask());
|
||||
$this->assertEquals($model->getGranting(), $entry->isGranting());
|
||||
$this->assertEquals($model->getGrantingStrategy(), $entry->getStrategy());
|
||||
$this->assertEquals($model->getAuditFailure(), $entry->isAuditFailure());
|
||||
$this->assertEquals($model->getAuditSuccess(), $entry->isAuditSuccess());
|
||||
$this->assertEquals($this->getRoleSecurityIdentity(), $entry->getSecurityIdentity());
|
||||
|
||||
return $entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testConstruct
|
||||
*/
|
||||
public function testSerializeUnserialize(Entry $entry)
|
||||
{
|
||||
$serialized = serialize($entry);
|
||||
$unserialized = unserialize($serialized);
|
||||
|
||||
$this->assertNotEmpty($serialized);
|
||||
$this->assertNotEmpty($unserialized);
|
||||
$this->assertInstanceOf('Propel\PropelBundle\Security\Acl\Domain\Entry', $unserialized);
|
||||
|
||||
$this->assertEquals($entry->getMask(), $unserialized->getMask());
|
||||
$this->assertEquals($entry->isGranting(), $unserialized->isGranting());
|
||||
$this->assertEquals($entry->getStrategy(), $unserialized->getStrategy());
|
||||
$this->assertEquals($entry->isAuditFailure(), $unserialized->isAuditFailure());
|
||||
$this->assertEquals($entry->isAuditSuccess(), $unserialized->isAuditSuccess());
|
||||
$this->assertEquals($entry->getSecurityIdentity(), $unserialized->getSecurityIdentity());
|
||||
}
|
||||
}
|
74
Tests/Security/Acl/Domain/FieldEntryTest.php
Normal file
74
Tests/Security/Acl/Domain/FieldEntryTest.php
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?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\Security\Acl\Domain;
|
||||
|
||||
use PropelCollection;
|
||||
|
||||
use Propel\PropelBundle\Model\Acl\Entry as ModelEntry;
|
||||
use Propel\PropelBundle\Model\Acl\SecurityIdentity;
|
||||
|
||||
use Propel\PropelBundle\Security\Acl\Domain\Acl;
|
||||
use Propel\PropelBundle\Security\Acl\Domain\FieldEntry;
|
||||
|
||||
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
|
||||
|
||||
use Propel\PropelBundle\Tests\AclTestCase;
|
||||
|
||||
/**
|
||||
* @author Toni Uebernickel <tuebernickel@gmail.com>
|
||||
*/
|
||||
class FieldEntryTest extends AclTestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$collection = new PropelCollection();
|
||||
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
|
||||
$acl = new Acl($collection, $this->getAclObjectIdentity(), new PermissionGrantingStrategy());
|
||||
|
||||
$model = $this->createEntry();
|
||||
$model->setFieldName('name');
|
||||
$model->setAuditFailure(true);
|
||||
$model->setSecurityIdentity(SecurityIdentity::fromAclIdentity($this->getRoleSecurityIdentity()));
|
||||
|
||||
$entry = new FieldEntry($model, $acl);
|
||||
|
||||
$this->assertEquals($model->getMask(), $entry->getMask());
|
||||
$this->assertEquals($model->getGranting(), $entry->isGranting());
|
||||
$this->assertEquals($model->getGrantingStrategy(), $entry->getStrategy());
|
||||
$this->assertEquals($model->getAuditFailure(), $entry->isAuditFailure());
|
||||
$this->assertEquals($model->getAuditSuccess(), $entry->isAuditSuccess());
|
||||
$this->assertEquals($model->getFieldName(), $entry->getField());
|
||||
$this->assertEquals($this->getRoleSecurityIdentity(), $entry->getSecurityIdentity());
|
||||
|
||||
return $entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testConstruct
|
||||
*/
|
||||
public function testSerializeUnserialize(FieldEntry $entry)
|
||||
{
|
||||
$serialized = serialize($entry);
|
||||
$unserialized = unserialize($serialized);
|
||||
|
||||
$this->assertNotEmpty($serialized);
|
||||
$this->assertNotEmpty($unserialized);
|
||||
$this->assertInstanceOf('Propel\PropelBundle\Security\Acl\Domain\FieldEntry', $unserialized);
|
||||
|
||||
$this->assertEquals($entry->getMask(), $unserialized->getMask());
|
||||
$this->assertEquals($entry->isGranting(), $unserialized->isGranting());
|
||||
$this->assertEquals($entry->getStrategy(), $unserialized->getStrategy());
|
||||
$this->assertEquals($entry->isAuditFailure(), $unserialized->isAuditFailure());
|
||||
$this->assertEquals($entry->isAuditSuccess(), $unserialized->isAuditSuccess());
|
||||
$this->assertEquals($entry->getSecurityIdentity(), $unserialized->getSecurityIdentity());
|
||||
$this->assertEquals($entry->getField(), $unserialized->getField());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue