mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
58 lines
1.4 KiB
PHP
58 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Alchemy\Tests\Phrasea\Form\Constraint;
|
|
|
|
use Alchemy\Phrasea\Form\Constraint\NewEmailValidator;
|
|
|
|
/**
|
|
* @group functional
|
|
* @group legacy
|
|
*/
|
|
class NewEmailValidatorTest extends \PhraseanetTestCase
|
|
{
|
|
/**
|
|
* @dataProvider provideValidationData
|
|
*/
|
|
public function testValidate($value, $alreadyRegistered)
|
|
{
|
|
$context = $this->getMock('Symfony\Component\Validator\ExecutionContextInterface');
|
|
$builder = $context
|
|
->expects($this->exactly($alreadyRegistered ? 1 : 0))
|
|
->method('addViolation');
|
|
|
|
if ($alreadyRegistered) {
|
|
$builder->with($this->isType('string'));
|
|
}
|
|
|
|
$validator = new NewEmailValidator();
|
|
$validator->initialize($context);
|
|
|
|
$constraint = $this->getConstraint();
|
|
$constraint
|
|
->expects($this->once())
|
|
->method('isAlreadyRegistered')
|
|
->with($value)
|
|
->will($this->returnValue($alreadyRegistered));
|
|
|
|
$validator->validate($value, $constraint);
|
|
}
|
|
|
|
public function provideValidationData()
|
|
{
|
|
return [
|
|
['romain@neutron.io', true],
|
|
['romain@neutron.io', false],
|
|
['', false],
|
|
[null, false],
|
|
];
|
|
}
|
|
|
|
private function getConstraint()
|
|
{
|
|
return $this
|
|
->getMockBuilder('Alchemy\Phrasea\Form\Constraint\NewEmail')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
}
|
|
}
|