diff --git a/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php b/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php index 4db1cda1b2..10257847e8 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php +++ b/src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php @@ -93,13 +93,10 @@ class AutoExpireFlashBag implements FlashBagInterface */ public function get($type, $default = null) { - if (!$this->has($type)) { - return $default; - } + $return = $default; - $return = null; - if (isset($this->flashes['new'][$type])) { - unset($this->flashes['new'][$type]); + if (!$this->has($type)) { + return $return; } if (isset($this->flashes['display'][$type])) { diff --git a/tests/Symfony/Tests/Component/HttpFoundation/Session/Attribute/AttributeBagTest.php b/tests/Symfony/Tests/Component/HttpFoundation/Session/Attribute/AttributeBagTest.php index a5c921254c..5bf62110d9 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/Session/Attribute/AttributeBagTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/Session/Attribute/AttributeBagTest.php @@ -64,6 +64,13 @@ class AttributeBagTest extends \PHPUnit_Framework_TestCase $this->assertEquals('test', $attributeBag->getStorageKey()); } + public function testGetSetName() + { + $this->assertEquals('attributes', $this->bag->getName()); + $this->bag->setName('foo'); + $this->assertEquals('foo', $this->bag->getName()); + } + /** * @dataProvider attributesProvider */ diff --git a/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/AutoExpireFlashBagTest.php b/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/AutoExpireFlashBagTest.php index 3b12c0eaea..962635d333 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/AutoExpireFlashBagTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/AutoExpireFlashBagTest.php @@ -22,7 +22,7 @@ use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase { /** - * @var \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface + * @var \Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag */ private $bag; @@ -60,6 +60,20 @@ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase $this->assertEquals('a', $bag->peek('error')); } + public function testGetStorageKey() + { + $this->assertEquals('_sf2_flashes', $this->bag->getStorageKey()); + $attributeBag = new FlashBag('test'); + $this->assertEquals('test', $attributeBag->getStorageKey()); + } + + public function testGetSetName() + { + $this->assertEquals('flashes', $this->bag->getName()); + $this->bag->setName('foo'); + $this->assertEquals('foo', $this->bag->getName()); + } + public function testPeek() { $this->assertNull($this->bag->peek('non_existing')); @@ -116,6 +130,13 @@ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase $this->assertNull($this->bag->get('notice')); } + public function testSetAll() + { + $this->bag->setAll(array('a' => 'first', 'b' => 'second')); + $this->assertFalse($this->bag->has('a')); + $this->assertFalse($this->bag->has('b')); + } + public function testAll() { $this->bag->set('notice', 'Foo'); @@ -127,4 +148,9 @@ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array(), $this->bag->all()); } + + public function testClear() + { + $this->assertEquals(array('notice' => 'A previous flash message'), $this->bag->clear()); + } } diff --git a/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/FlashBagTest.php b/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/FlashBagTest.php index 3616ec9156..1ae73f8f0a 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/FlashBagTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/Session/Flash/FlashBagTest.php @@ -55,6 +55,20 @@ class FlashBagTest extends \PHPUnit_Framework_TestCase $this->assertEquals($array, $bag->peekAll()); } + public function testGetStorageKey() + { + $this->assertEquals('_sf2_flashes', $this->bag->getStorageKey()); + $attributeBag = new FlashBag('test'); + $this->assertEquals('test', $attributeBag->getStorageKey()); + } + + public function testGetSetName() + { + $this->assertEquals('flashes', $this->bag->getName()); + $this->bag->setName('foo'); + $this->assertEquals('foo', $this->bag->getName()); + } + public function testPeek() { $this->assertNull($this->bag->peek('non_existing')); diff --git a/tests/Symfony/Tests/Component/HttpFoundation/Session/SessionTest.php b/tests/Symfony/Tests/Component/HttpFoundation/Session/SessionTest.php index 20f5079150..9141c79fb9 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/Session/SessionTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/Session/SessionTest.php @@ -70,6 +70,16 @@ class SessionTest extends \PHPUnit_Framework_TestCase $this->assertEquals($value, $this->session->get($key)); } + /** + * @dataProvider setProvider + */ + public function testHas($key, $value) + { + $this->session->set($key, $value); + $this->assertTrue($this->session->has($key)); + $this->assertFalse($this->session->has($key.'non_value')); + } + public function testReplace() { $this->session->replace(array('happiness' => 'be good', 'symfony' => 'awesome')); @@ -139,6 +149,11 @@ class SessionTest extends \PHPUnit_Framework_TestCase $this->assertEquals(333, $this->session->get('migrate')); } + public function testSave() + { + $this->session->save(); + } + public function testGetId() { $this->assertEquals('', $this->session->getId()); @@ -146,6 +161,11 @@ class SessionTest extends \PHPUnit_Framework_TestCase $this->assertNotEquals('', $this->session->getId()); } + public function testGetFlashBag() + { + $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Session\\Flash\\FlashBagInterface', $this->session->getFlashBag()); + } + // deprecated since 2.1, will be removed from 2.3 public function testGetSetFlashes()