* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Tests\Component\HttpFoundation\Session\Flash; use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag as FlashBag; use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; /** * AutoExpireFlashBagTest * * @author Drak */ class AutoExpireFlashBagTest extends \PHPUnit_Framework_TestCase { /** * @var \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface */ private $bag; /** * @var array */ protected $array = array(); public function setUp() { parent::setUp(); $this->bag = new FlashBag(); $this->array = array('new' => array('notice' => 'A previous flash message')); $this->bag->initialize($this->array); } public function tearDown() { $this->bag = null; parent::tearDown(); } public function testInitialize() { $bag = new FlashBag(); $array = array('new' => array('notice' => 'A previous flash message')); $bag->initialize($array); $this->assertEquals('A previous flash message', $bag->peek('notice')); $array = array('new' => array( 'notice' => 'Something else', 'error' => 'a', )); $bag->initialize($array); $this->assertEquals('Something else', $bag->peek('notice')); $this->assertEquals('a', $bag->peek('error')); } public function testPeek() { $this->assertNull($this->bag->peek('non_existing')); $this->assertEquals('default', $this->bag->peek('non_existing', 'default')); $this->assertEquals('A previous flash message', $this->bag->peek('notice')); $this->assertEquals('A previous flash message', $this->bag->peek('notice')); } public function testSet() { $this->bag->set('notice', 'Foo'); $this->assertNotEquals('Foo', $this->bag->peek('notice')); } public function testHas() { $this->assertFalse($this->bag->has('nothing')); $this->assertTrue($this->bag->has('notice')); } public function testKeys() { $this->assertEquals(array('notice'), $this->bag->keys()); } public function testPeekAll() { $array = array( 'new' => array( 'notice' => 'Foo', 'error' => 'Bar', ), ); $this->bag->initialize($array); $this->assertEquals(array( 'notice' => 'Foo', 'error' => 'Bar', ), $this->bag->peekAll() ); $this->assertEquals(array( 'notice' => 'Foo', 'error' => 'Bar', ), $this->bag->peekAll() ); } public function testGet() { $this->assertNull($this->bag->get('non_existing')); $this->assertEquals('default', $this->bag->get('non_existing', 'default')); $this->assertEquals('A previous flash message', $this->bag->get('notice')); $this->assertNull($this->bag->get('notice')); } public function testAll() { $this->bag->set('notice', 'Foo'); $this->bag->set('error', 'Bar'); $this->assertEquals(array( 'notice' => 'A previous flash message', ), $this->bag->all() ); $this->assertEquals(array(), $this->bag->all()); } }