mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
Add MustacheLoader tests
This commit is contained in:
@@ -33,7 +33,7 @@ class MustacheLoader implements ControllerProviderInterface
|
|||||||
{
|
{
|
||||||
$template_name = $request->get('template');
|
$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);
|
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);
|
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;
|
return $controllers;
|
||||||
|
@@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user