propel-bundle/Tests/Model/EntryTest.php

89 lines
2.9 KiB
PHP
Raw Normal View History

2013-12-14 12:49:10 +01:00
<?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
*/
2016-02-11 19:14:03 +01:00
namespace Propel\Bundle\PropelBundle\Tests\Model\Acl;
2013-12-14 12:49:10 +01:00
2016-02-11 19:14:03 +01:00
use Propel\Bundle\PropelBundle\Model\Acl\Entry as ModelEntry;
use Propel\Bundle\PropelBundle\Model\Acl\SecurityIdentity;
2013-12-14 12:49:10 +01:00
2016-02-11 19:14:03 +01:00
use Propel\Bundle\PropelBundle\Security\Acl\Domain\Entry as AclEntry;
2013-12-14 12:49:10 +01:00
2016-02-11 19:14:03 +01:00
use Propel\Bundle\PropelBundle\Tests\AclTestCase;
2013-12-14 12:49:10 +01:00
/**
* @author Toni Uebernickel <tuebernickel@gmail.com>
*/
class EntryTest extends AclTestCase
{
public function testToAclEntry()
{
2016-02-11 19:14:03 +01:00
$acl = $this->getMock('Propel\Bundle\PropelBundle\Security\Acl\Domain\AuditableAcl', array(), array(), '', false, false);
2013-12-14 12:49:10 +01:00
$entry = $this->createModelEntry();
$aclEntry = ModelEntry::toAclEntry($entry, $acl);
2016-02-11 19:14:03 +01:00
$this->assertInstanceOf('Propel\Bundle\PropelBundle\Security\Acl\Domain\Entry', $aclEntry);
2013-12-14 12:49:10 +01:00
$this->assertSame($acl, $aclEntry->getAcl());
$this->assertEquals(42, $aclEntry->getId());
$this->assertTrue($aclEntry->isAuditFailure());
$this->assertFalse($aclEntry->isAuditSuccess());
$this->assertEquals('all', $aclEntry->getStrategy());
$this->assertTrue($aclEntry->isGranting());
$this->assertEquals(64, $aclEntry->getMask());
return $aclEntry;
}
/**
* @depends testToAclEntry
*/
public function testToAclEntryFieldEntry()
{
2016-02-11 19:14:03 +01:00
$acl = $this->getMock('Propel\Bundle\PropelBundle\Security\Acl\Domain\AuditableAcl', array(), array(), '', false, false);
2013-12-14 12:49:10 +01:00
$entry = $this->createModelEntry();
$entry->setFieldName('name');
$aclEntry = ModelEntry::toAclEntry($entry, $acl);
2016-02-11 19:14:03 +01:00
$this->assertInstanceOf('Propel\Bundle\PropelBundle\Security\Acl\Domain\FieldEntry', $aclEntry);
2013-12-14 12:49:10 +01:00
}
/**
* @depends testToAclEntry
*/
public function testFromAclEntry($aclEntry)
{
$modelEntry = ModelEntry::fromAclEntry($aclEntry);
2016-02-11 19:14:03 +01:00
$this->assertInstanceOf('Propel\Bundle\PropelBundle\Model\Acl\Entry', $modelEntry);
2013-12-14 12:49:10 +01:00
$this->assertEquals(42, $modelEntry->getId());
$this->assertTrue($modelEntry->getAuditFailure());
$this->assertFalse($modelEntry->getAuditSuccess());
$this->assertEquals('all', $modelEntry->getGrantingStrategy());
$this->assertTrue($modelEntry->getGranting());
$this->assertEquals(64, $modelEntry->getMask());
}
protected function createModelEntry()
{
$entry = new ModelEntry();
$entry
->setId(42)
->setAclClass($this->getAclClass())
->setSecurityIdentity(SecurityIdentity::fromAclIdentity($this->getRoleSecurityIdentity()))
->setAuditFailure(true)
->setAuditSuccess(false)
->setGrantingStrategy('all')
->setGranting(true)
->setMask(64)
;
return $entry;
}
}