Ver Fonte

[HttpFoundation] fixed locale accessor after session clear

Kris Wallsmith há 14 anos atrás
pai
commit
ed8ecab7ea

+ 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());