소스 검색

[HttpFoundation] fixed locale accessor after session clear

Kris Wallsmith 14 년 전
부모
커밋
ed8ecab7ea
2개의 변경된 파일10개의 추가작업 그리고 0개의 파일을 삭제
  1. 4 0
      src/Symfony/Component/HttpFoundation/Session.php
  2. 6 0
      tests/Symfony/Tests/Component/HttpFoundation/SessionTest.php

+ 4 - 0
src/Symfony/Component/HttpFoundation/Session.php

@@ -194,6 +194,10 @@ class Session implements \Serializable
      */
     public function getLocale()
     {
+        if (!isset($this->attributes['_locale'])) {
+            $this->attributes['_locale'] = $this->defaultLocale;
+        }
+
         return $this->attributes['_locale'];
     }
 

+ 6 - 0
tests/Symfony/Tests/Component/HttpFoundation/SessionTest.php

@@ -172,6 +172,12 @@ class SessionTest extends \PHPUnit_Framework_TestCase
         $this->assertSame('fr', $this->session->getLocale(), 'locale is fr');
     }
 
+    public function testLocaleAfterClear()
+    {
+        $this->session->clear();
+        $this->assertEquals('en', $this->session->getLocale());
+    }
+
     public function testGetId()
     {
         $this->assertSame(null, $this->session->getId());