From 3fd9adb8b7a47acf46058a3280ddd9a3ddde167e Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Wed, 1 May 2013 17:20:40 +0200 Subject: [PATCH] Add flash messages tests --- ...seanetWebTestCaseAuthenticatedAbstract.php | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/classes/PhraseanetWebTestCaseAuthenticatedAbstract.php b/tests/classes/PhraseanetWebTestCaseAuthenticatedAbstract.php index 42b92b0e7d..8f4bc8585d 100644 --- a/tests/classes/PhraseanetWebTestCaseAuthenticatedAbstract.php +++ b/tests/classes/PhraseanetWebTestCaseAuthenticatedAbstract.php @@ -1,8 +1,8 @@ execute(); $stmt->closeCursor(); } + + protected function assertFlashMessage(Crawler $crawler, $flashType, $quantity, $message = null, $offset = 0) + { + if (!preg_match('/[a-zA-Z]+/', $flashType)) { + $this->fail(sprintf('FlashType must be in the form of [a-zA-Z]+, %s given', $flashType)); + } + + $this->assertEquals($quantity, $crawler->filter('.alert.alert-'.$flashType)->count()); + + if (null !== $message) { + $this->assertEquals($message, $crawler->filter('.alert.alert-'.$flashType.' .alert-block-content')->eq($offset)->text()); + } + } + + protected function assertFlashMessagePopulated(Application $app, $flashType, $quantity) + { + if (!preg_match('/[a-zA-Z]+/', $flashType)) { + $this->fail(sprintf('FlashType must be in the form of [a-zA-Z]+, %s given', $flashType)); + } + + $this->assertEquals($quantity, count($app['session']->getFlashBag()->get($flashType))); + } }