/**
  * Test using the block loader with two different document managers.
  */
 public function testLoadWithAlternativeDocumentManager()
 {
     $absoluteBlockPath = '/some/absolute/path';
     $block = $this->getMock('Sonata\\BlockBundle\\Model\\BlockInterface');
     $block->expects($this->any())->method('getName')->will($this->returnValue('the-block'));
     $altBlock = $this->getMock('Sonata\\BlockBundle\\Model\\BlockInterface');
     $altBlock->expects($this->any())->method('getName')->will($this->returnValue('alt-block'));
     $this->dmMock->expects($this->once())->method('find')->with($this->equalTo(null), $this->equalTo($absoluteBlockPath))->will($this->returnValue($block));
     $altDmMock = $this->getMockBuilder('Doctrine\\ODM\\PHPCR\\DocumentManager')->disableOriginalConstructor()->getMock();
     $altDmMock->expects($this->once())->method('find')->with($this->equalTo(null), $this->equalTo($absoluteBlockPath))->will($this->returnValue($altBlock));
     $this->pwcMock->expects($this->at(0))->method('isGranted')->with(PublishWorkflowChecker::VIEW_ATTRIBUTE, $this->equalTo($block))->will($this->returnValue(true));
     $this->pwcMock->expects($this->at(1))->method('isGranted')->with(PublishWorkflowChecker::VIEW_ATTRIBUTE, $this->equalTo($altBlock))->will($this->returnValue(true));
     $registryMock = $this->getMockBuilder('Doctrine\\Bundle\\PHPCRBundle\\ManagerRegistry')->disableOriginalConstructor()->getMock();
     $registryMock->expects($this->at(0))->method('getManager')->with($this->equalTo('themanager'))->will($this->returnValue($this->dmMock));
     $registryMock->expects($this->at(1))->method('getManager')->with($this->equalTo('altmanager'))->will($this->returnValue($altDmMock));
     $blockLoader = new PhpcrBlockLoader($registryMock, $this->pwcMock, $this->requestStackMock, null, 'emptyblocktype');
     $blockLoader->setManagerName('themanager');
     $foundBlock = $blockLoader->load(array('name' => $absoluteBlockPath));
     $this->assertInstanceOf('Sonata\\BlockBundle\\Model\\BlockInterface', $foundBlock);
     $this->assertEquals('the-block', $foundBlock->getName());
     $blockLoader->setManagerName('altmanager');
     $foundBlock = $blockLoader->load(array('name' => $absoluteBlockPath));
     $this->assertInstanceOf('Sonata\\BlockBundle\\Model\\BlockInterface', $foundBlock);
     $this->assertEquals('alt-block', $foundBlock->getName());
 }
 public function testIsGrantedWithException()
 {
     $this->setExpectedException('RuntimeException', 'Something is wrong');
     $this->admin->expects($this->any())->method('getCode')->will($this->returnValue('foo.bar'));
     $this->authorizationChecker->expects($this->any())->method('isGranted')->will($this->returnCallback(function (array $attributes, $object) {
         throw new \RuntimeException('Something is wrong');
     }));
     $handler = $this->getRoleSecurityHandler(array('ROLE_BATMAN'));
     $handler->isGranted($this->admin, 'BAZ');
 }
 public function testOnKernelRequestAccessGranted()
 {
     $request = new Request();
     $request->attributes->set('siteaccess', new SiteAccess());
     $event = new GetResponseEvent($this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST);
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $token->expects($this->any())->method('getUsername')->will($this->returnValue('foo'));
     $this->tokenStorage->expects($this->once())->method('getToken')->will($this->returnValue($token));
     $this->authChecker->expects($this->once())->method('isGranted')->will($this->returnValue(true));
     // Nothing should happen or should be returned.
     $this->listener->onKernelRequest($event);
 }
예제 #4
0
 public function testIsGrantedWithVoter()
 {
     $this->parameterResolver->expects($this->once())->method('resolveVoter')->will($this->returnValue(true));
     $this->authorizationChecker->expects($this->once())->method('isGranted')->with($this->identicalTo('lug.' . ($action = 'show')), $this->identicalTo($object = $this->createStdClassMock()))->will($this->returnValue(true));
     $this->assertTrue($this->securityChecker->isGranted($action, $object));
 }