Вход Регистрация
Файл: symfony-2.7/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/GlobalVariablesTest.php
Строк: 136
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SymfonyBundleFrameworkBundleTestsTemplating;

use 
SymfonyBundleFrameworkBundleTemplatingGlobalVariables;
use 
SymfonyBundleFrameworkBundleTestsTestCase;
use 
SymfonyComponentDependencyInjectionContainer;

class 
GlobalVariablesTest extends TestCase
{
    private 
$container;
    private 
$globals;

    public function 
setUp()
    {
        
$this->container = new Container();
        
$this->globals = new GlobalVariables($this->container);
    }

    public function 
testLegacyGetSecurity()
    {
        
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);

        
$securityContext = $this->getMock('SymfonyComponentSecurityCoreSecurityContextInterface');

        
$this->assertNull($this->globals->getSecurity());
        
$this->container->set('security.context', $securityContext);
        
$this->assertSame($securityContext, $this->globals->getSecurity());
    }

    public function 
testGetUserNoTokenStorage()
    {
        
$this->assertNull($this->globals->getUser());
    }

    public function 
testGetUserNoToken()
    {
        
$tokenStorage = $this->getMock('SymfonyComponentSecurityCoreAuthenticationTokenStorageTokenStorageInterface');
        
$this->container->set('security.token_storage', $tokenStorage);
        
$this->assertNull($this->globals->getUser());
    }

    
/**
     * @dataProvider getUserProvider
     */
    
public function testGetUser($user, $expectedUser)
    {
        
$tokenStorage = $this->getMock('SymfonyComponentSecurityCoreAuthenticationTokenStorageTokenStorageInterface');
        
$token = $this->getMock('SymfonyComponentSecurityCoreAuthenticationTokenTokenInterface');

        
$this->container->set('security.token_storage', $tokenStorage);

        
$token
            
->expects($this->once())
            ->
method('getUser')
            ->
will($this->returnValue($user));

        
$tokenStorage
            
->expects($this->once())
            ->
method('getToken')
            ->
will($this->returnValue($token));

        
$this->assertSame($expectedUser, $this->globals->getUser());
    }

    public function 
getUserProvider()
    {
        
$user = $this->getMock('SymfonyComponentSecurityCoreUserUserInterface');
        
$std = new stdClass();
        
$token = $this->getMock('SymfonyComponentSecurityCoreAuthenticationTokenTokenInterface');

        return array(
            array(
$user, $user),
            array(
$std, $std),
            array(
$token, $token),
            array(
'Anon.', null),
            array(
null, null),
            array(
10, null),
            array(
true, null),
        );
    }
}
Онлайн: 1
Реклама