Update unit tests base

This commit is contained in:
Romain Neutron
2013-05-03 01:43:01 +02:00
parent 58df66b68b
commit bbda53d484
2 changed files with 52 additions and 0 deletions

View File

@@ -894,6 +894,22 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
->method('deliver')
->with($this->isInstanceOf($expectedMail), $this->equalTo($receipt));
}
protected function mockNotificationsDeliverer(array &$expectedMails)
{
self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer')
->disableOriginalConstructor()
->getMock();
$phpunit = $this;
self::$DI['app']['notification.deliverer']->expects($this->any())
->method('deliver')
->will($this->returnCallback(function ($email, $receipt) use ($phpunit, &$expectedMails) {
$phpunit->assertTrue(isset($expectedMails[get_class($email)]));
$expectedMails[get_class($email)]++;
}));
}
}
class CsrfTestProvider implements CsrfProviderInterface

View File

@@ -150,6 +150,29 @@ abstract class PhraseanetWebTestCaseAuthenticatedAbstract extends PhraseanetPHPU
$stmt->closeCursor();
}
public function provideFlashMessages()
{
return array(
array('warning', 'Be careful !'),
array('error', 'An error occured'),
array('info', 'You need to do something more'),
array('success', "Success operation !"),
);
}
protected function assertFormOrAngularError(Crawler $crawler, $quantity)
{
$total = $crawler->filter('form div:not(div[ng-show]) > div.popover.field-error')->count();
$total += $crawler->filter('phraseanet-flash[type="error"]')->count();
$this->assertEquals($quantity, $total);
}
protected function assertFormError(Crawler $crawler, $quantity)
{
$this->assertEquals($quantity, $crawler->filter('form div:not(div[ng-show]) > div.popover.field-error')->count());
}
protected function assertFlashMessage(Crawler $crawler, $flashType, $quantity, $message = null, $offset = 0)
{
if (!preg_match('/[a-zA-Z]+/', $flashType)) {
@@ -163,6 +186,19 @@ abstract class PhraseanetWebTestCaseAuthenticatedAbstract extends PhraseanetPHPU
}
}
protected function assertAngularFlashMessage(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('phraseanet-flash[type="'.$flashType.'"]')->count());
if (null !== $message) {
$this->assertEquals($message, $crawler->filter('phraseanet-flash[type="'.$flashType.'"]')->eq($offset)->text());
}
}
protected function assertFlashMessagePopulated(Application $app, $flashType, $quantity)
{
if (!preg_match('/[a-zA-Z]+/', $flashType)) {