2011-03-16 13:47:21 +00:00
|
|
|
<?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 Symfony\Bundle\FrameworkBundle\Tests\Templating;
|
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\PhpEngine;
|
|
|
|
use Symfony\Component\DependencyInjection\Container;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Session;
|
2012-01-02 15:32:41 +00:00
|
|
|
use Symfony\Component\HttpFoundation\SessionStorage\MockArraySessionStorage;
|
2011-03-16 13:47:21 +00:00
|
|
|
use Symfony\Component\Templating\TemplateNameParser;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
[FrameworkBundle] Refactored code for changes to HttpFoundation component.
Native PHP sessions stored to file are done with session.storage.native_file
Functional testing is done with session.storage.mock_file
Default flash message implementation done with FlashBag (session.flash_bag)
Default attribute storage implementation with AttributeBag (session.attribute_bag)
Services added: session.storage.native_file, session.storage.native_memcache, session.storage.native_memcache,
session.storage.native_sqlite, session.storage.memcache, session.storage.memcached, session.storage.null,
session.storage.mock_file, session.flash_bag, session.attribute_bag
Services removed: session.storage.native, session.storage.filesystem
2011-12-15 08:46:43 +00:00
|
|
|
use Symfony\Component\HttpFoundation\FlashBag;
|
|
|
|
use Symfony\Component\HttpFoundation\AttributeBag;
|
2011-03-16 13:47:21 +00:00
|
|
|
|
|
|
|
class PhpEngineTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testEvaluateAddsAppGlobal()
|
|
|
|
{
|
|
|
|
$container = $this->getContainer();
|
|
|
|
$loader = $this->getMockForAbstractClass('Symfony\Component\Templating\Loader\Loader');
|
|
|
|
$engine = new PhpEngine(new TemplateNameParser(), $container, $loader, $app = new GlobalVariables($container));
|
|
|
|
$globals = $engine->getGlobals();
|
|
|
|
$this->assertSame($app, $globals['app']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEvaluateWithoutAvailableRequest()
|
|
|
|
{
|
|
|
|
$container = new Container();
|
|
|
|
$loader = $this->getMockForAbstractClass('Symfony\Component\Templating\Loader\Loader');
|
2011-04-30 20:40:15 +01:00
|
|
|
$engine = new PhpEngine(new TemplateNameParser(), $container, $loader, new GlobalVariables($container));
|
2011-03-16 13:47:21 +00:00
|
|
|
|
|
|
|
$container->set('request', null);
|
|
|
|
|
|
|
|
$globals = $engine->getGlobals();
|
|
|
|
$this->assertEmpty($globals['app']->getRequest());
|
|
|
|
}
|
|
|
|
|
2011-06-11 08:56:09 +01:00
|
|
|
/**
|
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testGetInvalidHelper()
|
|
|
|
{
|
|
|
|
$container = $this->getContainer();
|
|
|
|
$loader = $this->getMockForAbstractClass('Symfony\Component\Templating\Loader\Loader');
|
|
|
|
$engine = new PhpEngine(new TemplateNameParser(), $container, $loader);
|
|
|
|
|
|
|
|
$engine->get('non-existing-helper');
|
|
|
|
}
|
|
|
|
|
2011-03-16 13:47:21 +00:00
|
|
|
/**
|
|
|
|
* Creates a Container with a Session-containing Request service.
|
|
|
|
*
|
|
|
|
* @return Container
|
|
|
|
*/
|
|
|
|
protected function getContainer()
|
|
|
|
{
|
|
|
|
$container = new Container();
|
|
|
|
$request = new Request();
|
2012-01-02 15:32:41 +00:00
|
|
|
$session = new Session(new MockArraySessionStorage(new AttributeBag(), new FlashBag()));
|
2011-03-16 13:47:21 +00:00
|
|
|
|
|
|
|
$request->setSession($session);
|
|
|
|
$container->set('request', $request);
|
|
|
|
|
|
|
|
return $container;
|
|
|
|
}
|
|
|
|
}
|