From 805dd76fcd9b9cab8c67df5704638d8261931c2a Mon Sep 17 00:00:00 2001 From: Drak Date: Sun, 12 Feb 2012 10:23:04 +0545 Subject: [PATCH] [HttpFoundation] Added tests for Session class. --- .../HttpFoundation/Session/SessionTest.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/Symfony/Tests/Component/HttpFoundation/Session/SessionTest.php b/tests/Symfony/Tests/Component/HttpFoundation/Session/SessionTest.php index 3f57670581..a7f91692ea 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/Session/SessionTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/Session/SessionTest.php @@ -168,4 +168,54 @@ class SessionTest extends \PHPUnit_Framework_TestCase $this->session->start(); $this->assertNotEquals('', $this->session->getId()); } + + // deprecated since 2.1, will be removed from 2.3 + + public function testGetSetFlashes() + { + $array = array('notice' => 'hello', 'error' => 'none'); + $this->assertEquals(array(), $this->session->getFlashes()); + $this->session->setFlashes($array); + $this->assertEquals($array, $this->session->getFlashes()); + $this->assertEquals(array(), $this->session->getFlashes()); + } + + public function testGetSetFlash() + { + $this->assertNull($this->session->getFlash('notice')); + $this->assertEquals('default', $this->session->getFlash('notice', 'default')); + $this->session->setFlash('notice', 'foo'); + $this->assertEquals('foo', $this->session->getFlash('notice')); + $this->assertNull($this->session->getFlash('notice')); + } + + public function testHasFlash() + { + $this->assertFalse($this->session->hasFlash('notice')); + $this->session->setFlash('notice', 'foo'); + $this->assertTrue($this->session->hasFlash('notice')); + } + + public function testRemoveFlash() + { + $this->session->setFlash('notice', 'foo'); + $this->session->setFlash('error', 'bar'); + $this->assertTrue($this->session->hasFlash('notice')); + $this->session->removeFlash('error'); + $this->assertTrue($this->session->hasFlash('notice')); + $this->assertFalse($this->session->hasFlash('error')); + } + + public function testClearFlashes() + { + $this->assertFalse($this->session->hasFlash('notice')); + $this->assertFalse($this->session->hasFlash('error')); + $this->session->setFlash('notice', 'foo'); + $this->session->setFlash('error', 'bar'); + $this->assertTrue($this->session->hasFlash('notice')); + $this->assertTrue($this->session->hasFlash('error')); + $this->session->clearFlashes(); + $this->assertFalse($this->session->hasFlash('notice')); + $this->assertFalse($this->session->hasFlash('error')); + } }