Neos\FluidAdaptor\ViewHelpers\Security\IfHasRoleViewHelper::render PHP Method

render() public method

renders child if the role could be found in the security context, otherwise renders child.
public render ( ) : string
return string the rendered string
    public function render()
    {
        if (static::evaluateCondition($this->arguments, $this->renderingContext)) {
            return $this->renderThenChild();
        }
        return $this->renderElseChild();
    }

Usage Example

 /**
  * @test
  */
 public function viewHelperUsesSpecifiedAccountForCheck()
 {
     $mockAccount = $this->createMock(\Neos\Flow\Security\Account::class);
     $mockAccount->expects($this->any())->method('hasRole')->will($this->returnCallback(function (Role $role) {
         switch ($role->getIdentifier()) {
             case 'Neos.FluidAdaptor:Administrator':
                 return true;
         }
     }));
     $this->mockViewHelper->expects($this->any())->method('renderThenChild')->will($this->returnValue('true'));
     $this->mockViewHelper->expects($this->any())->method('renderElseChild')->will($this->returnValue('false'));
     $arguments = ['role' => new Role('Neos.FluidAdaptor:Administrator'), 'packageKey' => null, 'account' => $mockAccount];
     $this->mockViewHelper->setArguments($arguments);
     $actualResult = $this->mockViewHelper->render();
     $this->assertEquals('true', $actualResult, 'Full role identifier in role argument is accepted');
 }