propel-bundle/Tests/Model/ObjectIdentityQueryTest.php
Drew Brown ea6a359272 Symfony 4.0 updates (#483)
* 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
2018-02-10 01:25:14 +01:00

135 lines
5 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\AclClass;
use Propel\Bundle\PropelBundle\Model\Acl\ObjectIdentityQuery;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Propel\Bundle\PropelBundle\Tests\AclTestCase;
/**
* @author Toni Uebernickel <tuebernickel@gmail.com>
*/
class ObjectIdentityQueryTest extends AclTestCase
{
public function testFilterByAclObjectIdentity()
{
$aclObj = new ObjectIdentity(1, 'Propel\Bundle\PropelBundle\Tests\Fixtures\Model\Book');
$aclClass = AclClass::fromAclObjectIdentity($aclObj, $this->con);
$this->assertInstanceOf('Propel\Bundle\PropelBundle\Model\Acl\AclClass', $aclClass);
// None given.
$result = ObjectIdentityQuery::create()->filterByAclObjectIdentity($aclObj, $this->con)->find($this->con);
$this->assertCount(0, $result);
$this->createModelObjectIdentity(1);
$result = ObjectIdentityQuery::create()->filterByAclObjectIdentity($aclObj, $this->con)->find($this->con);
$this->assertCount(1, $result);
$this->assertEquals($aclClass->getId(), $result->getFirst()->getClassId());
$this->assertEquals(1, $result->getFirst()->getIdentifier());
// Change the entity.
$aclObj = new ObjectIdentity(2, 'Propel\Bundle\PropelBundle\Tests\Fixtures\Model\Book');
$result = ObjectIdentityQuery::create()->filterByAclObjectIdentity($aclObj, $this->con)->find($this->con);
$this->assertCount(0, $result);
}
/**
* @depends testFilterByAclObjectIdentity
*/
public function testFindOneByAclObjectIdentity()
{
$aclObj = new ObjectIdentity(1, 'Propel\Bundle\PropelBundle\Tests\Fixtures\Model\Book');
$result = ObjectIdentityQuery::create()->findOneByAclObjectIdentity($aclObj, $this->con);
$this->assertEmpty($result);
$objIdentity = $this->createModelObjectIdentity(1);
$result = ObjectIdentityQuery::create()->findOneByAclObjectIdentity($aclObj, $this->con);
$this->assertInstanceOf('Propel\Bundle\PropelBundle\Model\Acl\ObjectIdentity', $result);
$this->assertSame($objIdentity, $result);
}
/**
* @depends testFindOneByAclObjectIdentity
*/
public function testFindChildren()
{
list($objIdentity, $childObjIdentity) = $this->createObjectIdentities();
// Parent not set, yet.
$result = ObjectIdentityQuery::create()->findChildren($objIdentity, $this->con);
$this->assertCount(0, $result);
$childObjIdentity->setObjectIdentityRelatedByParentObjectIdentityId($objIdentity)->save($this->con);
$result = ObjectIdentityQuery::create()->findChildren($objIdentity, $this->con);
$this->assertCount(1, $result);
$this->assertInstanceOf('Propel\Bundle\PropelBundle\Model\Acl\ObjectIdentity', $result->getFirst());
$this->assertEquals($childObjIdentity, $result->getFirst());
$this->assertSame($objIdentity, $result->getFirst()->getObjectIdentityRelatedByParentObjectIdentityId());
}
/**
* @depends testFindOneByAclObjectIdentity
*/
public function testFindGrandChildren()
{
list($objIdentity, $childObjIdentity, $grandChildObjIdentity) = $this->createObjectIdentities();
// Parents not set, yet.
$result = ObjectIdentityQuery::create()->findGrandChildren($objIdentity, $this->con);
$this->assertCount(0, $result);
$childObjIdentity->setObjectIdentityRelatedByParentObjectIdentityId($objIdentity)->save($this->con);
$result = ObjectIdentityQuery::create()->findGrandChildren($objIdentity, $this->con);
$this->assertCount(1, $result);
$grandChildObjIdentity->setObjectIdentityRelatedByParentObjectIdentityId($childObjIdentity)->save($this->con);
$result = ObjectIdentityQuery::create()->findGrandChildren($objIdentity, $this->con);
$this->assertCount(2, $result);
}
/**
* @depends testFindOneByAclObjectIdentity
*/
public function testFindAncestors()
{
list($objIdentity, $childObjIdentity) = $this->createObjectIdentities();
// Parents not set, yet.
$result = ObjectIdentityQuery::create()->findAncestors($childObjIdentity, $this->con);
$this->assertCount(0, $result);
$childObjIdentity->setObjectIdentityRelatedByParentObjectIdentityId($objIdentity)->save($this->con);
$result = ObjectIdentityQuery::create()->findAncestors($childObjIdentity, $this->con);
$this->assertCount(1, $result);
}
protected function createObjectIdentities()
{
return array(
$this->createModelObjectIdentity(1),
$this->createModelObjectIdentity(2),
$this->createModelObjectIdentity(3),
);
}
}