<commit_before><?php

namespace Oro\Bundle\SecurityBundle\Tests\Unit\Acl\Voter;

use Oro\Bundle\SecurityBundle\Acl\AccessLevel;
use Oro\Bundle\SecurityBundle\Acl\Voter\AclVoter;

class AclVoterTest extends \PHPUnit_Framework_TestCase
{
    public function testVote()
    {
        $selector = $this->getMockBuilder('Oro\Bundle\SecurityBundle\Acl\Extension\AclExtensionSelector')
            ->disableOriginalConstructor()
            ->getMock();
        $permissionMap = $this->getMock('Symfony\Component\Security\Acl\Permission\PermissionMapInterface');
        $voter = new AclVoter(
            $this->getMock('Symfony\Component\Security\Acl\Model\AclProviderInterface'),
            $this->getMock('Symfony\Component\Security\Acl\Model\ObjectIdentityRetrievalStrategyInterface'),
            $this->getMock('Symfony\Component\Security\Acl\Model\SecurityIdentityRetrievalStrategyInterface'),
            $permissionMap
        );
        $voter->setAclExtensionSelector($selector);

        $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
        $object = new \stdClass();
        $extension = $this->getMock('Oro\Bundle\SecurityBundle\Acl\Extension\AclExtensionInterface');
        $extension->expects($this->once())
            ->method('getAccessLevel')
            ->with($this->equalTo(1))
            ->will($this->returnValue(AccessLevel::LOCAL_LEVEL));

        $isGrantedObserver = $this->getMockBuilder('Oro\Bundle\SecurityBundle\Acl\Domain\OneShotIsGrantedObserver')
            ->disableOriginalConstructor()
            ->getMock();
        $voter->addOneShotIsGrantedObserver($isGrantedObserver);

        $isGrantedObserver->expects($this->once())
            ->method('setAccessLevel')
            ->with($this->equalTo(AccessLevel::LOCAL_LEVEL));

        $selector->expects($this->exactly(2))
            ->method('select')
            ->with($this->identicalTo($object))
            ->will($this->returnValue($extension));

        $inVoteToken = null;
        $inVoteObject = null;
        $inVoteExtension = null;

        $permissionMap->expects($this->exactly(2))
            ->method('getMasks')
            ->will(
                $this->returnCallback(
                    function () use (&$voter, &$inVoteToken, &$inVoteObject, &$inVoteExtension) {
                        $inVoteToken = $voter->getSecurityToken();
                        $inVoteObject = $voter->getObject();
                        $inVoteExtension = $voter->getAclExtension();
                        $voter->setTriggeredMask(1);

                        return null;
                    }
                )
            );

        $this->assertNull($voter->getSecurityToken());
        $this->assertNull($voter->getObject());
        $this->assertNull($voter->getAclExtension());

        $voter->vote($token, $object, array('test'));

        $this->assertNull($voter->getSecurityToken());
        $this->assertNull($voter->getObject());
        $this->assertNull($voter->getAclExtension());

        $this->assertTrue($token === $inVoteToken);
        $this->assertTrue($object === $inVoteObject);
        $this->assertTrue($extension === $inVoteExtension);

        // call the vote method one more time to ensure that OneShotIsGrantedObserver was removed from the voter
        $voter->vote($token, $object, array('test'));
    }
}<commit_msg>BAP-4970: Upgrade to Symfony 2.3.18 - fix unit tests<commit_after><?php

namespace Oro\Bundle\SecurityBundle\Tests\Unit\Acl\Voter;

use Oro\Bundle\SecurityBundle\Acl\AccessLevel;
use Oro\Bundle\SecurityBundle\Acl\Voter\AclVoter;

class AclVoterTest extends \PHPUnit_Framework_TestCase
{
    public function testVote()
    {
        $selector = $this->getMockBuilder('Oro\Bundle\SecurityBundle\Acl\Extension\AclExtensionSelector')
            ->disableOriginalConstructor()
            ->getMock();
        $permissionMap = $this->getMock('Symfony\Component\Security\Acl\Permission\PermissionMapInterface');
        $voter = new AclVoter(
            $this->getMock('Symfony\Component\Security\Acl\Model\AclProviderInterface'),
            $this->getMock('Symfony\Component\Security\Acl\Model\ObjectIdentityRetrievalStrategyInterface'),
            $this->getMock('Symfony\Component\Security\Acl\Model\SecurityIdentityRetrievalStrategyInterface'),
            $permissionMap
        );
        $voter->setAclExtensionSelector($selector);

        $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
        $object = new \stdClass();
        $extension = $this->getMock('Oro\Bundle\SecurityBundle\Acl\Extension\AclExtensionInterface');
        $extension->expects($this->once())
            ->method('getAccessLevel')
            ->with($this->equalTo(1))
            ->will($this->returnValue(AccessLevel::LOCAL_LEVEL));

        $isGrantedObserver = $this->getMockBuilder('Oro\Bundle\SecurityBundle\Acl\Domain\OneShotIsGrantedObserver')
            ->disableOriginalConstructor()
            ->getMock();
        $voter->addOneShotIsGrantedObserver($isGrantedObserver);

        $isGrantedObserver->expects($this->once())
            ->method('setAccessLevel')
            ->with($this->equalTo(AccessLevel::LOCAL_LEVEL));

        $selector->expects($this->exactly(2))
            ->method('select')
            ->with($this->identicalTo($object))
            ->will($this->returnValue($extension));

        $inVoteToken = null;
        $inVoteObject = null;
        $inVoteExtension = null;

        $permissionMap->expects($this->exactly(2))
            ->method('contains')
            ->with('test')
            ->will($this->returnValue(true));

        $permissionMap->expects($this->exactly(2))
            ->method('getMasks')
            ->will(
                $this->returnCallback(
                    function () use (&$voter, &$inVoteToken, &$inVoteObject, &$inVoteExtension) {
                        $inVoteToken = $voter->getSecurityToken();
                        $inVoteObject = $voter->getObject();
                        $inVoteExtension = $voter->getAclExtension();
                        $voter->setTriggeredMask(1);

                        return null;
                    }
                )
            );

        $this->assertNull($voter->getSecurityToken());
        $this->assertNull($voter->getObject());
        $this->assertNull($voter->getAclExtension());

        $voter->vote($token, $object, array('test'));

        $this->assertNull($voter->getSecurityToken());
        $this->assertNull($voter->getObject());
        $this->assertNull($voter->getAclExtension());

        $this->assertSame($token, $inVoteToken);
        $this->assertSame($object, $inVoteObject);
        $this->assertSame($extension, $inVoteExtension);

        // call the vote method one more time to ensure that OneShotIsGrantedObserver was removed from the voter
        $voter->vote($token, $object, array('test'));
    }
}
{'fraction_non_alphanumeric': 0.14786716289722301, 'fraction_numerical': 0.002433438305181792, 'mean_word_length': 2.614588722193482, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 127, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6744194', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1924, 'n_words': 231}