Commit b71fe7ed authored by Fabien Potencier's avatar Fabien Potencier

Merge remote branch 'igorw/extension-tests'

* igorw/extension-tests:
  [UrlGeneratorExtension] initial test case
  [SessionExtension] initial test case
  [TwigExtension] initial test case
parents fbb5a69d be020168
......@@ -28,3 +28,6 @@
[submodule "vendor/pimple"]
path = vendor/pimple
url = https://github.com/fabpot/Pimple
[submodule "vendor/twig"]
path = vendor/twig
url = https://github.com/fabpot/Twig
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Silex\Tests;
use Silex\Application;
use Silex\Extension\SessionExtension;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\SessionStorage\ArraySessionStorage;
/**
* SessionExtension test cases.
*
* @author Igor Wiedler <igor@wiedler.ch>
*/
class SessionExtensionTest extends \PHPUnit_Framework_TestCase
{
public function testRegister()
{
$app = new Application();
$app->register(new SessionExtension());
$app['session.storage'] = $app->share(function() use ($app) {
return new ArraySessionStorage();
});
$app->get('/login', function() use ($app) {
$app['session']->set('logged_in', true);
return 'Logged in successfully.';
});
$app->get('/account', function() use ($app) {
if (!$app['session']->get('logged_in')) {
return 'You are not in.';
}
return 'This is your account.';
});
$request = Request::create('/login');
$response = $app->handle($request);
$this->assertEquals('Logged in successfully.', $response->getContent());
$request = Request::create('/account');
$response = $app->handle($request);
$this->assertEquals('This is your account.', $response->getContent());
}
}
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Silex\Tests;
use Silex\Application;
use Silex\Extension\TwigExtension;
use Symfony\Component\HttpFoundation\Request;
/**
* TwigExtension test cases.
*
* @author Igor Wiedler <igor@wiedler.ch>
*/
class TwigExtensionTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
if (!is_dir(__DIR__.'/../../../../vendor/twig')) {
$this->markTestSkipped('Twig submodule was not installed.');
}
}
public function testRegisterAndRender()
{
$app = new Application();
$app->register(new TwigExtension(), array(
'twig.templates' => array('hello' => 'Hello {{ name }}!'),
'twig.class_path' => __DIR__.'/../../../../vendor/twig/lib',
));
$app->get('/hello/{name}', function($name) use ($app) {
return $app['twig']->render('hello', array('name' => $name));
});
$request = Request::create('/hello/john');
$response = $app->handle($request);
$this->assertEquals('Hello john!', $response->getContent());
}
}
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Silex\Tests;
use Silex\Application;
use Silex\Extension\UrlGeneratorExtension;
use Symfony\Component\HttpFoundation\Request;
/**
* UrlGeneratorExtension test cases.
*
* @author Igor Wiedler <igor@wiedler.ch>
*/
class UrlGeneratorExtensionTest extends \PHPUnit_Framework_TestCase
{
public function testRegister()
{
$app = new Application();
$app->register(new UrlGeneratorExtension());
$app->get('/hello/{name}', function($name) {})
->bind('hello');
$app->get('/', function() use ($app) {
return $app['url_generator']->generate('hello', array('name' => 'john'));
});
$request = Request::create('/');
$response = $app->handle($request);
$this->assertEquals('/hello/john', $response->getContent());
}
}
Subproject commit 2f106a80cc13b4260074e573fa017a770fe20350
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment