assertFalse($app['debug']); $app = new Application('prod'); $this->assertFalse($app['debug']); $app = new Application('test'); $this->assertTrue($app['debug']); $app = new Application('dev'); $this->assertTrue($app['debug']); } /** * @covers Alchemy\Phrasea\Application */ public function testTestLocale() { $app = new Application(); } /** * @covers Alchemy\Phrasea\Application */ public function testCookie() { $app = $this->getApp(); $client = $this->getClientWithCookie($app); $client->request('GET', '/'); $response = $client->getResponse(); $cookies = $response->headers->getCookies(ResponseHeaderBag::COOKIES_ARRAY); $this->assertEquals(2, count($cookies['']['/'])); } /** * @covers Alchemy\Phrasea\Application */ public function testTestDisableCookie() { $app = $this->getApp(); $app->disableCookies(); $client = $this->getClientWithCookie($app); $client->request('GET', '/'); $response = $client->getResponse(); $cookies = $response->headers->getCookies(ResponseHeaderBag::COOKIES_ARRAY); $this->assertEquals(0, count($cookies)); } /** * @covers Alchemy\Phrasea\Application */ public function testCookieLocale() { $app = $this->getAppThatReturnLocale(); foreach (array('fr_FR', 'en_GB', 'de_DE') as $locale) { $client = $this->getClientWithCookie($app, $locale); $client->request('GET', '/'); $this->assertEquals($locale, $client->getResponse()->getContent()); } } /** * @covers Alchemy\Phrasea\Application */ public function testNoCookieLocaleReturnsDefaultLocale() { $app = $this->getAppThatReturnLocale(); $this->mockRegistryAndReturnLocale($app, 'en_USA'); $client = $this->getClientWithCookie($app, null); $client->request('GET', '/'); $this->assertEquals('en_USA', $client->getResponse()->getContent()); } /** * @covers Alchemy\Phrasea\Application */ public function testWrongCookieLocaleReturnsDefaultLocale() { $app = $this->getAppThatReturnLocale(); $this->mockRegistryAndReturnLocale($app, 'en_USA'); $client = $this->getClientWithCookie($app, 'de_PL'); $client->request('GET', '/'); $this->assertEquals('en_USA', $client->getResponse()->getContent()); } /** * @covers Alchemy\Phrasea\Application */ public function testNoCookieReturnsContentNegotiated() { $app = $this->getAppThatReturnLocale(); $this->mockRegistryAndReturnLocale($app, 'en_USA'); $client = $this->getClientWithCookie($app, null); $client->request('GET', '/', array(), array(), array('accept_language' => 'en-US;q=0.75,en;q=0.8,fr-FR;q=0.9')); $this->assertEquals('fr_FR', $client->getResponse()->getContent()); } /** * @covers Alchemy\Phrasea\Application */ public function testFlashSession() { $app = new Application('test'); $sessionId = null; $app->post('/prod/upload/', function(Application $app) use (&$sessionId) { $sessionId = $app['session']->getId(); }); $client = new Client($app); $client->request('POST', '/prod/upload/', array('php_session_id'=>'123456'), array(), array('HTTP_USER_AGENT'=>'flash')); $this->assertEquals('123456', $sessionId); } public function testWebProfilerDisableByDefault() { $app = new Application('prod'); $this->assertFalse(isset($app['profiler'])); $app = new Application('test'); $this->assertFalse(isset($app['profiler'])); } public function testWebProfilerEnableInDevMode() { $app = new Application('dev'); $this->assertTrue(isset($app['profiler'])); } public function testGeneratePath() { $generator = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGenerator') ->disableOriginalConstructor() ->getMock(); $app = new Application(); $app['url_generator'] = $generator; $ret = 'retval-' . mt_rand(); $route = 'route'; $generator->expects($this->once()) ->method('generate') ->with($this->equalTo($route), $this->equalTo(array()), $this->equalTo(UrlGenerator::ABSOLUTE_PATH)) ->will($this->returnValue($ret)); $this->assertEquals($ret, $app->path($route)); } public function testGenerateUrl() { $generator = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGenerator') ->disableOriginalConstructor() ->getMock(); $app = new Application(); $app['url_generator'] = $generator; $ret = 'retval-' . mt_rand(); $route = 'route'; $generator->expects($this->once()) ->method('generate') ->with($this->equalTo($route), $this->equalTo(array()), $this->equalTo(UrlGenerator::ABSOLUTE_URL)) ->will($this->returnValue($ret)); $this->assertEquals($ret, $app->url($route)); } public function addSetFlash() { $app = new Application('test'); $this->assertEquals(array(), $app->getFlash('hello')); $this->assertEquals('BOUM', $app->getFlash('hello', 'BOUM')); $app->setFlash('notice', 'BAMBA'); $this->assertEquals(array('BAMBA'), $app->getFlash('notice')); } private function getAuthMock() { $auth = $this->getMockBuilder('Session_Authentication_Interface') ->disableOriginalConstructor() ->getMock(); $auth->expects($this->any()) ->method('get_user') ->will($this->returnValue(self::$DI['user'])); return $auth; } private function getApp() { $app = new Application('test'); $app->get('/', function(Application $app, Request $request) { $app['session']->set('usr_id', 5); $response = new Response('hello'); $response->headers->setCookie(new Cookie('key', 'value')); return $response; }); unset($app['exception_handler']); return $app; } private function getClientWithCookie(Application $app) { $cookieJar = new CookieJar(); return new Client($app, array(), null, $cookieJar); } }