You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
282 lines
7.4 KiB
282 lines
7.4 KiB
<?php
|
|
|
|
/*
|
|
* To change this template, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
require_once dirname(__FILE__) . '/../../form/Form.php';
|
|
require_once dirname(__FILE__) . '/../../form/FormField.php';
|
|
require_once dirname(__FILE__) . '/../../session/Session.php';
|
|
|
|
|
|
class FormTest extends PHPUnit_Framework_TestCase
|
|
{
|
|
public function testIsValidWithNotArray()
|
|
{
|
|
$form = new NotEmptyForm();
|
|
|
|
$this->setExpectedException('Exception');
|
|
$form->isValid('');
|
|
}
|
|
|
|
public function testIsValidCorrectFields()
|
|
{
|
|
$form = new NotEmptyForm();
|
|
|
|
$test_array = array(
|
|
'login'=> 'login',
|
|
'password'=> 'password'
|
|
);
|
|
|
|
$this->assertSame(1, $form->isValid($test_array));
|
|
}
|
|
|
|
public function testIsValidMissingField()
|
|
{
|
|
$form = new NotEmptyForm();
|
|
|
|
$test_array = array(
|
|
'password'=> 'password'
|
|
);
|
|
|
|
$this->assertSame(0, $form->isValid($test_array));
|
|
}
|
|
|
|
public function testGetValues()
|
|
{
|
|
$form = new NotEmptyForm();
|
|
|
|
$fields = array(
|
|
'login'=> 'login',
|
|
'password'=>'password'
|
|
);
|
|
|
|
$obj_fields = $form->getProp('fields');
|
|
|
|
$this->assertTrue(!$obj_fields['login']->isIgnored());
|
|
$this->assertTrue(!$obj_fields['password']->isIgnored());
|
|
|
|
$this->assertSame(1, $form->isValid($fields));
|
|
|
|
$this->assertEquals($fields, $form->getValues());
|
|
}
|
|
|
|
|
|
public function testGetValueCorrect()
|
|
{
|
|
$form = new NotEmptyForm();
|
|
|
|
$fields = array(
|
|
'login'=> 'login',
|
|
'password'=>'password'
|
|
);
|
|
|
|
$this->assertSame(1, $form->isValid($fields));
|
|
|
|
$this->assertEquals($fields['login'], $form->getValue('login'));
|
|
$this->assertEquals($fields['password'], $form->getValue('password'));
|
|
}
|
|
|
|
|
|
public function testGetValueMissing()
|
|
{
|
|
$form = new NotEmptyForm();
|
|
|
|
$fields = array(
|
|
'login'=> ''
|
|
);
|
|
|
|
$this->assertSame(0, $form->isValid($fields));
|
|
|
|
$this->assertEquals('', $form->getValue('login'));
|
|
$this->assertEquals('', $form->getValue('password'));
|
|
}
|
|
|
|
|
|
public function testGetValueMissingFieldLogin()
|
|
{
|
|
$form = new NotEmptyForm();
|
|
|
|
$fields = array(
|
|
'login'=> ''
|
|
);
|
|
|
|
$this->assertSame(0, $form->isValid($fields));
|
|
|
|
$this->assertFalse($form->getValue('loginw'));
|
|
|
|
$this->assertEquals('', $form->getValue('passwordw'));
|
|
}
|
|
|
|
|
|
public function testGetValueMissingFieldPassword()
|
|
{
|
|
$form = new NotEmptyForm();
|
|
|
|
$fields = array(
|
|
'login'=> ''
|
|
);
|
|
|
|
$this->assertSame(0, $form->isValid($fields));
|
|
|
|
$this->assertFalse($form->getValue('loginw'));
|
|
|
|
$this->assertEquals('', $form->getValue('password'));
|
|
}
|
|
|
|
public function testGetMessageTypeCorrect()
|
|
{
|
|
$form = new NotEmptyForm();
|
|
|
|
$fields = array(
|
|
'login'=> 'login',
|
|
'password'=>'password'
|
|
);
|
|
|
|
$this->assertEquals(1, $form->isValid($fields));
|
|
|
|
$this->assertEquals('success', Form::SUCCESS);
|
|
|
|
$this->assertEquals($form->getMessageType(), Form::SUCCESS);
|
|
}
|
|
|
|
public function testGetMessageTypeMissing()
|
|
{
|
|
$form = new NotEmptyForm();
|
|
|
|
$fields = array(
|
|
'login'=> '',
|
|
'password'=>''
|
|
);
|
|
|
|
$this->assertSame(0, $form->isValid($fields));
|
|
|
|
$this->assertSame(0, $form->getProp('valid'));
|
|
|
|
$this->assertEquals('error', Form::ERROR);
|
|
|
|
$this->assertEquals($form->getMessageType(), Form::ERROR);
|
|
}
|
|
|
|
|
|
public function testGetMessageCorrect()
|
|
{
|
|
$form = new NotEmptyForm();
|
|
|
|
$fields = array(
|
|
'login'=> 'login',
|
|
'password'=>'password'
|
|
);
|
|
|
|
$this->assertSame(1, $form->isValid($fields));
|
|
|
|
$messages = $form->getProp('messages');
|
|
|
|
$this->assertEquals($messages[Form::SUCCESS], $form->getMessage());
|
|
}
|
|
|
|
|
|
public function testGetMessageMissing()
|
|
{
|
|
$form = new NotEmptyForm();
|
|
|
|
$fields = array(
|
|
'login'=> ''
|
|
);
|
|
|
|
$this->assertSame(0, $form->isValid($fields));
|
|
|
|
$messages = $form->getProp('messages');//attributeEq ?
|
|
|
|
$this->assertEquals($messages[Form::ERROR], $form->getMessage());
|
|
}
|
|
|
|
|
|
public function testSetSuccessMessage()
|
|
{
|
|
$form = new NotEmptyForm();
|
|
|
|
$fields = array(
|
|
'login'=> 'login',
|
|
'password'=>'password'
|
|
);
|
|
|
|
$this->assertSame(1, $form->isValid($fields));
|
|
|
|
$message = 'Form data valid';
|
|
|
|
$form->setSuccessMessage($message);
|
|
|
|
$this->assertNotNull($form->getMessage());
|
|
}
|
|
|
|
public function testSetErrorMessage()
|
|
{
|
|
$form = new NotEmptyForm();
|
|
|
|
$fields = array(
|
|
'login'=> ''
|
|
);
|
|
|
|
$this->assertSame(0, $form->isValid($fields));
|
|
|
|
$message = 'Form data invalid';
|
|
|
|
$form->setErrorMessage($message);
|
|
|
|
$this->assertNotNull($form->getMessage());
|
|
}
|
|
}
|
|
|
|
require_once '/var/www/majesticV/lib/core/validator/iValidator.php';
|
|
require_once '/var/www/majesticV/lib/core/validator/Validator.php';
|
|
require_once '/var/www/majesticV/lib/core/validator/NotEmptyValidator.php';
|
|
|
|
class NotEmptyForm extends Form
|
|
{
|
|
public function init()
|
|
{
|
|
///*
|
|
$validator = new NotEmptyValidator();
|
|
$validator->setMessage('Enter login name.');
|
|
$this->addField('login')->addValidator($validator);
|
|
|
|
// User password
|
|
$validator = new NotEmptyValidator();
|
|
$validator->setMessage('Enter your password.');
|
|
$this->addField('password')->addValidator($validator);
|
|
}
|
|
|
|
public function getProp($name)
|
|
{
|
|
return $this->$name;
|
|
}
|
|
}
|
|
|
|
require_once dirname(__FILE__) . '/../../validator/RegexValidator.php';
|
|
require_once dirname(__FILE__) . '/../../validator/EmailValidator.php';
|
|
|
|
class DiffForm extends Form
|
|
{
|
|
public function init()
|
|
{
|
|
///*
|
|
$validator = new EmailValidator();
|
|
$validator->setMessage('Enter login name.');
|
|
|
|
$this->addField('login')->addValidator($validator);
|
|
|
|
// User password
|
|
$validator = new NotEmptyValidator();
|
|
$validator->setMessage('Enter your password.');
|
|
$this->addField('password')->addValidator($validator);
|
|
|
|
}
|
|
|
|
public function getProp($name)
|
|
{
|
|
return $this->$name;
|
|
}
|
|
|
|
}
|