Add MustacheLoader tests

This commit is contained in:
Romain Neutron
2012-01-26 14:24:12 +01:00
parent 71c0c27660
commit 3b35b83a45
2 changed files with 63 additions and 2 deletions

View File

@@ -33,7 +33,7 @@ class MustacheLoader implements ControllerProviderInterface
{
$template_name = $request->get('template');
if (!preg_match('/[a-zA-Z0-9-_]+/', $template_name))
if (!preg_match('/^[a-zA-Z0-9-_]+$/', $template_name))
{
throw new \Exception_BadRequest('Wrong template name : ' . $template_name);
}
@@ -45,7 +45,7 @@ class MustacheLoader implements ControllerProviderInterface
throw new \Exception_NotFound('Template does not exists : ' . $template_path);
}
return new \Symfony\Component\HttpFoundation\Response(include $template_path);
return new \Symfony\Component\HttpFoundation\Response(file_get_contents($template_path));
});
return $controllers;

View File

@@ -0,0 +1,61 @@
<?php
require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
/**
* Test class for MustacheLoader.
* Generated by PHPUnit on 2012-01-26 at 14:04:04.
*/
class MustacheLoaderTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{
protected $client;
public function createApplication()
{
return require __DIR__ . '/../../../../../Alchemy/Phrasea/Application/Prod.php';
}
public function setUp()
{
parent::setUp();
$this->client = $this->createClient();
}
public function testRouteSlash()
{
$this->client->request('GET', '/MustacheLoader/');
$response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(400, $response->getStatusCode());
$this->assertFalse($response->isOk());
$this->client->request('GET', '/MustacheLoader/', array('template' => '/../../../../config/config.yml'));
$response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(400, $response->getStatusCode());
$this->assertFalse($response->isOk());
$this->client->request('GET', '/MustacheLoader/', array('template' => 'patator_lala'));
$response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(404, $response->getStatusCode());
$this->assertFalse($response->isOk());
$this->client->request('GET', '/MustacheLoader/', array('template' => 'Push-Badge'));
$response = $this->client->getResponse();
/* @var $response \Symfony\Component\HttpFoundation\Response */
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue($response->isOk());
}
}