Skip to content

Commit

Permalink
[HttpFoundation] replaced the option argument of Session by defaultLo…
Browse files Browse the repository at this point in the history
…cale
  • Loading branch information
fabpot committed Mar 30, 2011
1 parent 5e0c046 commit f77b940
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
18 changes: 9 additions & 9 deletions src/Symfony/Component/HttpFoundation/Session.php
Expand Up @@ -24,18 +24,18 @@ class Session implements \Serializable
protected $attributes;
protected $oldFlashes;
protected $started;
protected $options;
protected $defaultLocale;

/**
* Constructor.
*
* @param SessionStorageInterface $session A SessionStorageInterface instance
* @param array $options An array of options
* @param SessionStorageInterface $session A SessionStorageInterface instance
* @param string $defaultLocale The default locale
*/
public function __construct(SessionStorageInterface $storage, array $options = array())
public function __construct(SessionStorageInterface $storage, $defaultLocale = 'en')
{
$this->storage = $storage;
$this->options = $options;
$this->defaultLocale = $defaultLocale;
$this->attributes = array('_flash' => array(), '_locale' => $this->getDefaultLocale());
$this->started = false;
}
Expand Down Expand Up @@ -288,18 +288,18 @@ public function __destruct()

public function serialize()
{
return serialize(array($this->storage, $this->options));
return serialize(array($this->storage, $this->defaultLocale));
}

public function unserialize($serialized)
{
list($this->storage, $this->options) = unserialize($serialized);
list($this->storage, $this->defaultLocale) = unserialize($serialized);
$this->attributes = array();
$this->started = false;
}

protected function getDefaultLocale()
private function getDefaultLocale()
{
return isset($this->options['default_locale']) ? $this->options['default_locale'] : 'en';
return $this->defaultLocale;
}
}
24 changes: 12 additions & 12 deletions tests/Symfony/Tests/Component/HttpFoundation/SessionTest.php
Expand Up @@ -123,34 +123,34 @@ public function testMigrateAndInvalidate()

public function testSerialize()
{
$options = array('foo' => 'bar');
$this->session = new Session($this->storage, $options);
$defaultLocale = 'en';
$this->session = new Session($this->storage, $defaultLocale);

$compare = serialize(array($this->storage, $options));
$compare = serialize(array($this->storage, $defaultLocale));

$this->assertSame($compare, $this->session->serialize());

$this->session->unserialize($compare);

$_options = new \ReflectionProperty(get_class($this->session), 'options');
$_options->setAccessible(true);
$_defaultLocale = new \ReflectionProperty(get_class($this->session), 'defaultLocale');
$_defaultLocale->setAccessible(true);

$_storage = new \ReflectionProperty(get_class($this->session), 'storage');
$_storage->setAccessible(true);

$this->assertEquals($_options->getValue($this->session), $options, 'options match');
$this->assertEquals($_defaultLocale->getValue($this->session), $defaultLocale, 'options match');
$this->assertEquals($_storage->getValue($this->session), $this->storage, 'storage match');
}

public function testSave()
{
$this->storage = new ArraySessionStorage();
$options = array('foo' => 'bar');
$this->session = new Session($this->storage, $options);
$defaultLocale = 'fr';
$this->session = new Session($this->storage, $defaultLocale);
$this->session->set('foo', 'bar');

$this->session->save();
$compare = array('_symfony2' => array('_flash' => array() ,'_locale' => 'en', 'foo' => 'bar'));
$compare = array('_symfony2' => array('_flash' => array(), '_locale' => 'fr', 'foo' => 'bar'));

$r = new \ReflectionObject($this->storage);
$p = $r->getProperty('data');
Expand All @@ -161,15 +161,15 @@ public function testSave()

public function testLocale()
{
$this->assertSame('en', $this->session->getLocale(),'default locale is en');
$this->assertSame('en', $this->session->getLocale(), 'default locale is en');

$this->session->set('_locale','de');

$this->assertSame('de', $this->session->getLocale(),'locale is de');
$this->assertSame('de', $this->session->getLocale(), 'locale is de');

$this->session = $this->getSession();
$this->session->setLocale('fr');
$this->assertSame('fr', $this->session->getLocale(),'locale is fr');
$this->assertSame('fr', $this->session->getLocale(), 'locale is fr');
}

public function testGetId()
Expand Down

0 comments on commit f77b940

Please sign in to comment.