mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
Add forms
This commit is contained in:
32
tests/Alchemy/Tests/Phrasea/Form/Constraint/NewEmailTest.php
Normal file
32
tests/Alchemy/Tests/Phrasea/Form/Constraint/NewEmailTest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Form\Constraint;
|
||||
|
||||
use Alchemy\Phrasea\Form\Constraint\NewEmail;
|
||||
|
||||
class NewEmailTest extends \PhraseanetPHPUnitAbstract
|
||||
{
|
||||
public function testAnUnknownAddressIsNotAlreadyRegistered()
|
||||
{
|
||||
$constraint = new NewEmail(self::$DI['app']);
|
||||
$this->assertFalse($constraint->isAlreadyRegistered('nonehere'));
|
||||
}
|
||||
|
||||
public function testARegisteredAddressIsAlreadyRegistered()
|
||||
{
|
||||
$constraint = new NewEmail(self::$DI['app']);
|
||||
$this->assertTrue($constraint->isAlreadyRegistered(self::$DI['user']->get_email()));
|
||||
}
|
||||
|
||||
public function testNullIsNotAlreadyRegistered()
|
||||
{
|
||||
$constraint = new NewEmail(self::$DI['app']);
|
||||
$this->assertFalse($constraint->isAlreadyRegistered('null'));
|
||||
}
|
||||
|
||||
public function testBlankIsNotAlreadyRegistered()
|
||||
{
|
||||
$constraint = new NewEmail(self::$DI['app']);
|
||||
$this->assertFalse($constraint->isAlreadyRegistered(''));
|
||||
}
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Form\Constraint;
|
||||
|
||||
use Alchemy\Phrasea\Form\Constraint\NewEmailValidator;
|
||||
|
||||
class NewEmailValidatorTest extends \PhraseanetPHPUnitAbstract
|
||||
{
|
||||
/**
|
||||
* @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 array(
|
||||
array('romain@neutron.io', true),
|
||||
array('romain@neutron.io', false),
|
||||
array('', false),
|
||||
array(null, false),
|
||||
);
|
||||
}
|
||||
|
||||
private function getConstraint()
|
||||
{
|
||||
return $this
|
||||
->getMockBuilder('Alchemy\Phrasea\Form\Constraint\NewEmail')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Form\Constraint;
|
||||
|
||||
use Alchemy\Phrasea\Form\Constraint\PasswordToken;
|
||||
|
||||
class PasswordTokenTest extends \PhraseanetPHPUnitAbstract
|
||||
{
|
||||
public function testInvalidTokenIsNotValid()
|
||||
{
|
||||
$random = $this
|
||||
->getMockBuilder('random')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('helloToken'))
|
||||
->getMock();
|
||||
|
||||
$token = \random::generatePassword();
|
||||
|
||||
$random
|
||||
->expects($this->once())
|
||||
->method('helloToken')
|
||||
->with(self::$DI['app'], $token)
|
||||
->will($this->throwException(new \Exception_NotFound('Token not found')));
|
||||
|
||||
$constraint = new PasswordToken(self::$DI['app'], $random);
|
||||
$this->assertFalse($constraint->isValid($token));
|
||||
}
|
||||
|
||||
public function testValidTokenIsValid()
|
||||
{
|
||||
$random = $this
|
||||
->getMockBuilder('random')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('helloToken'))
|
||||
->getMock();
|
||||
|
||||
$token = \random::generatePassword();
|
||||
|
||||
$random
|
||||
->expects($this->once())
|
||||
->method('helloToken')
|
||||
->with(self::$DI['app'], $token)
|
||||
->will($this->returnValue(array('usr_id' => mt_rand(), 'type' => \random::TYPE_PASSWORD)));
|
||||
|
||||
$constraint = new PasswordToken(self::$DI['app'], $random);
|
||||
$this->assertTrue($constraint->isValid($token));
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Form\Constraint;
|
||||
|
||||
use Alchemy\Phrasea\Form\Constraint\PasswordTokenValidator;
|
||||
|
||||
class PasswordTokenValidatorTest extends \PhraseanetPHPUnitAbstract
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideValidationData
|
||||
*/
|
||||
public function testValidate($value, $isValid)
|
||||
{
|
||||
$context = $this->getMock('Symfony\Component\Validator\ExecutionContextInterface');
|
||||
$builder = $context
|
||||
->expects($this->exactly($isValid ? 1 : 0))
|
||||
->method('addViolation');
|
||||
|
||||
if ($isValid) {
|
||||
$builder->with($this->isType('string'));
|
||||
}
|
||||
|
||||
$validator = new PasswordTokenValidator();
|
||||
$validator->initialize($context);
|
||||
|
||||
$constraint = $this->getConstraint();
|
||||
$constraint
|
||||
->expects($this->once())
|
||||
->method('isValid')
|
||||
->with($value)
|
||||
->will($this->returnValue($isValid));
|
||||
|
||||
$validator->validate($value, $constraint);
|
||||
}
|
||||
|
||||
public function provideValidationData()
|
||||
{
|
||||
return array(
|
||||
array(\random::generatePassword(), true),
|
||||
array(\random::generatePassword(), false),
|
||||
);
|
||||
}
|
||||
|
||||
private function getConstraint()
|
||||
{
|
||||
return $this
|
||||
->getMockBuilder('Alchemy\Phrasea\Form\Constraint\PasswordToken')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
}
|
26
tests/Alchemy/Tests/Phrasea/Form/FormTestCase.php
Normal file
26
tests/Alchemy/Tests/Phrasea/Form/FormTestCase.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Form;
|
||||
|
||||
abstract class FormTestCase extends \PhraseanetPHPUnitAbstract
|
||||
{
|
||||
public function testBuildForm()
|
||||
{
|
||||
$form = $this->getForm();
|
||||
|
||||
$builder = $this
|
||||
->getMockBuilder('Symfony\Component\Form\FormBuilder')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$form->buildForm($builder, array('disabled' => false));
|
||||
}
|
||||
|
||||
public function testGetName()
|
||||
{
|
||||
$form = $this->getForm();
|
||||
$this->assertNull($form->getName());
|
||||
}
|
||||
|
||||
abstract protected function getForm();
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Form\Login;
|
||||
|
||||
use Alchemy\Phrasea\Form\Login\PhraseaAuthenticationForm;
|
||||
use Alchemy\Tests\Phrasea\Form\FormTestCase;
|
||||
|
||||
class PhraseaAuthenticationFormTest extends FormTestCase
|
||||
{
|
||||
protected function getForm()
|
||||
{
|
||||
return new PhraseaAuthenticationForm();
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Form\Login;
|
||||
|
||||
use Alchemy\Phrasea\Form\Login\PhraseaAuthenticationWithMappingForm;;
|
||||
use Alchemy\Tests\Phrasea\Form\FormTestCase;
|
||||
|
||||
class PhraseaAuthenticationWithMappingFormTest extends FormTestCase
|
||||
{
|
||||
protected function getForm()
|
||||
{
|
||||
return new PhraseaAuthenticationWithMappingForm();
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Form\Login;
|
||||
|
||||
use Alchemy\Phrasea\Form\Login\PhraseaForgotPasswordForm;;
|
||||
use Alchemy\Tests\Phrasea\Form\FormTestCase;
|
||||
|
||||
class PhraseaForgotPasswordFormTest extends FormTestCase
|
||||
{
|
||||
protected function getForm()
|
||||
{
|
||||
return new PhraseaForgotPasswordForm();
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Form\Login;
|
||||
|
||||
use Alchemy\Phrasea\Form\Login\PhraseaRecoverPasswordForm;;
|
||||
use Alchemy\Tests\Phrasea\Form\FormTestCase;
|
||||
|
||||
class PhraseaRecoverPasswordFormTest extends FormTestCase
|
||||
{
|
||||
protected function getForm()
|
||||
{
|
||||
return new PhraseaRecoverPasswordForm(self::$DI['app']);
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Form\Login;
|
||||
|
||||
use Alchemy\Phrasea\Form\Login\PhraseaRegisterForm;;
|
||||
use Alchemy\Tests\Phrasea\Form\FormTestCase;
|
||||
|
||||
class PhraseaRegisterFormTest extends FormTestCase
|
||||
{
|
||||
protected function getForm()
|
||||
{
|
||||
$available = array(
|
||||
'parameter' => array(
|
||||
'type' => 'text',
|
||||
'label' => 'Yollah !',
|
||||
)
|
||||
);
|
||||
$params = array(
|
||||
array(
|
||||
'name' => 'parameter',
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
||||
return new PhraseaRegisterForm(self::$DI['app'], $available, $params, new \Alchemy\Phrasea\Utilities\String\Camelizer());
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Form\Login;
|
||||
|
||||
use Alchemy\Phrasea\Form\Login\PhraseaRenewPasswordForm;;
|
||||
use Alchemy\Tests\Phrasea\Form\FormTestCase;
|
||||
|
||||
class PhraseaRenewPasswordFormTest extends FormTestCase
|
||||
{
|
||||
protected function getForm()
|
||||
{
|
||||
return new PhraseaRenewPasswordForm();
|
||||
}
|
||||
}
|
20
tests/Alchemy/Tests/Phrasea/Form/Type/GeonameTypeTest.php
Normal file
20
tests/Alchemy/Tests/Phrasea/Form/Type/GeonameTypeTest.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Form\Type;
|
||||
|
||||
use Alchemy\Phrasea\Form\Type\GeonameType;
|
||||
|
||||
class GeonameTypeTest extends \PhraseanetPHPUnitAbstract
|
||||
{
|
||||
public function testGetParent()
|
||||
{
|
||||
$geoname = new GeonameType();
|
||||
$this->assertEquals('text', $geoname->getParent());
|
||||
}
|
||||
|
||||
public function testGetName()
|
||||
{
|
||||
$geoname = new GeonameType();
|
||||
$this->assertEquals('geoname', $geoname->getName());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user