From 3b35b83a45656623d49170dfb0c5359b4927baae Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 26 Jan 2012 14:24:12 +0100 Subject: [PATCH] Add MustacheLoader tests --- .../Controller/Prod/MustacheLoader.php | 4 +- .../Controller/Prod/MustacheLoaderTest.php | 61 +++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 lib/unitTest/Alchemy/Phrasea/Controller/Prod/MustacheLoaderTest.php diff --git a/lib/Alchemy/Phrasea/Controller/Prod/MustacheLoader.php b/lib/Alchemy/Phrasea/Controller/Prod/MustacheLoader.php index 78c33dae7e..f727aa6bf7 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/MustacheLoader.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/MustacheLoader.php @@ -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; diff --git a/lib/unitTest/Alchemy/Phrasea/Controller/Prod/MustacheLoaderTest.php b/lib/unitTest/Alchemy/Phrasea/Controller/Prod/MustacheLoaderTest.php new file mode 100644 index 0000000000..f6a23a001a --- /dev/null +++ b/lib/unitTest/Alchemy/Phrasea/Controller/Prod/MustacheLoaderTest.php @@ -0,0 +1,61 @@ +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()); + } + +}