Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cde9784
BooleanValidatorTest
suralc Jul 29, 2013
09c5e61
fix test
suralc Jul 29, 2013
fc1d2af
UrlValidator Tests
suralc Jul 29, 2013
ec1dfea
Ignoring javascript generating methods in coverage for now.
suralc Jul 29, 2013
1c6b64e
Added CompareValidatorTest and improved BooleanValidatorTest and UrlV…
suralc Jul 31, 2013
777ff79
DateValidatorTest
suralc Jul 31, 2013
1c57661
Merge branch 'add-tests' of github.com:suralc/yii2 into add-tests
suralc Jul 31, 2013
1ce7344
Additional tests in EmailValidator.
suralc Jul 31, 2013
467d88f
Added StringValidatorTest
suralc Jul 31, 2013
f7bb54b
Test fix for Php 5.3
suralc Jul 31, 2013
f78a77d
Merge branch 'master' of github.com:yiisoft/yii2 into add-tests
suralc Aug 6, 2013
8f8de7c
Added NumberValidatorTest
suralc Aug 6, 2013
b5472c2
Typo fix
suralc Aug 6, 2013
a81480d
Improved ValidatorTest organization.
suralc Aug 6, 2013
d9f87f4
Added RequiredValidatorTest
suralc Aug 13, 2013
bae79cd
Added ValidatorTest
suralc Aug 13, 2013
02c92fe
Merge remote-tracking branch 'upstream/master' into add-tests
suralc Aug 13, 2013
8e48f01
Add RegularExpressionValidatorTest
suralc Aug 14, 2013
0133069
Merge remote-tracking branch 'upstream/master' into add-tests
suralc Aug 14, 2013
5c8927a
Added ExistValidatorTest and added new option to DatabaseTestCase
suralc Aug 16, 2013
0c45765
Added tests for uncovered lines.
suralc Aug 18, 2013
3469b2c
RangeValidator tests.
suralc Aug 22, 2013
3b07e4a
Added FileValidator tests.
suralc Aug 23, 2013
7d5bb08
FilterValidator test
suralc Aug 23, 2013
24e2f88
Renamed validator test models to be less specific.
suralc Aug 23, 2013
c189e5a
UniqueValidator test.
suralc Aug 23, 2013
06682d0
coverage improvements
suralc Aug 23, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions framework/yii/captcha/CaptchaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function getCaptchaAction()
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @codeCoverageIgnore
*/
public function clientValidateAttribute($object, $attribute, $view)
{
Expand Down
1 change: 1 addition & 0 deletions framework/yii/validators/BooleanValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function validateValue($value)
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @codeCoverageIgnore
*/
public function clientValidateAttribute($object, $attribute, $view)
{
Expand Down
1 change: 1 addition & 0 deletions framework/yii/validators/CompareValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public function validateValue($value)
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @throws InvalidConfigException if CompareValidator::operator is invalid
* @codeCoverageIgnore
*/
public function clientValidateAttribute($object, $attribute, $view)
{
Expand Down
3 changes: 3 additions & 0 deletions framework/yii/validators/EmailValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public function init()
{
parent::init();
if ($this->enableIDN && !function_exists('idn_to_ascii')) {
// @codeCoverageIgnoreStart
throw new InvalidConfigException('In order to use IDN validation intl extension must be installed and enabled.');
// @codeCoverageIgnoreEnd
}
if ($this->message === null) {
$this->message = Yii::t('yii', '{attribute} is not a valid email address.');
Expand Down Expand Up @@ -122,6 +124,7 @@ public function validateValue($value)
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @codeCoverageIgnore
*/
public function clientValidateAttribute($object, $attribute, $view)
{
Expand Down
1 change: 1 addition & 0 deletions framework/yii/validators/NumberValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public function validateValue($value)
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @codeCoverageIgnore
*/
public function clientValidateAttribute($object, $attribute, $view)
{
Expand Down
1 change: 1 addition & 0 deletions framework/yii/validators/RangeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function validateValue($value)
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @codeCoverageIgnore
*/
public function clientValidateAttribute($object, $attribute, $view)
{
Expand Down
1 change: 1 addition & 0 deletions framework/yii/validators/RegularExpressionValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function validateValue($value)
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @throws InvalidConfigException if the "pattern" is not a valid regular expression
* @codeCoverageIgnore
*/
public function clientValidateAttribute($object, $attribute, $view)
{
Expand Down
1 change: 1 addition & 0 deletions framework/yii/validators/RequiredValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public function validateValue($value)
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @codeCoverageIgnore
*/
public function clientValidateAttribute($object, $attribute, $view)
{
Expand Down
1 change: 1 addition & 0 deletions framework/yii/validators/StringValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public function validateValue($value)
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @codeCoverageIgnore
*/
public function clientValidateAttribute($object, $attribute, $view)
{
Expand Down
3 changes: 3 additions & 0 deletions framework/yii/validators/UrlValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public function init()
{
parent::init();
if ($this->enableIDN && !function_exists('idn_to_ascii')) {
// @codeCoverageIgnoreStart
throw new InvalidConfigException('In order to use IDN validation intl extension must be installed and enabled.');
// @codeCoverageIgnoreEnd
}
if ($this->message === null) {
$this->message = Yii::t('yii', '{attribute} is not a valid URL.');
Expand Down Expand Up @@ -119,6 +121,7 @@ public function validateValue($value)
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @see \yii\Web\ActiveForm::enableClientValidation
* @codeCoverageIgnore
*/
public function clientValidateAttribute($object, $attribute, $view)
{
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/data/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,35 @@ INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 4,
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0);


/**
* (MySQL-)Database Schema for validator tests
*/

DROP TABLE IF EXISTS tbl_validator_main CASCADE;
DROP TABLE IF EXISTS tbl_validator_ref CASCADE;

CREATE TABLE tbl_validator_main (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`field1` VARCHAR(255),
PRIMARY KEY (`id`)
) ENGINE =InnoDB DEFAULT CHARSET =utf8;

CREATE TABLE tbl_validator_ref (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`a_field` VARCHAR(255),
`ref` INT(11),
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO tbl_validator_main (id, field1) VALUES (1, 'just a string1');
INSERT INTO tbl_validator_main (id, field1) VALUES (2, 'just a string2');
INSERT INTO tbl_validator_main (id, field1) VALUES (3, 'just a string3');
INSERT INTO tbl_validator_main (id, field1) VALUES (4, 'just a string4');
INSERT INTO tbl_validator_ref (a_field, ref) VALUES ('ref_to_2', 2);
INSERT INTO tbl_validator_ref (a_field, ref) VALUES ('ref_to_2', 2);
INSERT INTO tbl_validator_ref (a_field, ref) VALUES ('ref_to_3', 3);
INSERT INTO tbl_validator_ref (a_field, ref) VALUES ('ref_to_4', 4);
INSERT INTO tbl_validator_ref (a_field, ref) VALUES ('ref_to_4', 4);
INSERT INTO tbl_validator_ref (a_field, ref) VALUES ('ref_to_5', 5);
29 changes: 29 additions & 0 deletions tests/unit/data/postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,32 @@ INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 4,
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0);

/**
* (Postgres-)Database Schema for validator tests
*/

DROP TABLE IF EXISTS tbl_validator_main CASCADE;
DROP TABLE IF EXISTS tbl_validator_ref CASCADE;

CREATE TABLE tbl_validator_main (
id integer not null primary key,
field1 VARCHAR(255)
);

CREATE TABLE tbl_validator_ref (
id integer not null primary key,
a_field VARCHAR(255),
ref integer
);

INSERT INTO tbl_validator_main (id, field1) VALUES (1, 'just a string1');
INSERT INTO tbl_validator_main (id, field1) VALUES (2, 'just a string2');
INSERT INTO tbl_validator_main (id, field1) VALUES (3, 'just a string3');
INSERT INTO tbl_validator_main (id, field1) VALUES (4, 'just a string4');
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (1, 'ref_to_2', 2);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (2, 'ref_to_2', 2);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (3, 'ref_to_3', 3);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (4, 'ref_to_4', 4);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (5, 'ref_to_4', 4);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (6, 'ref_to_5', 5);
31 changes: 30 additions & 1 deletion tests/unit/data/sqlite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,33 @@ INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (1, 2,
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 4, 1, 10.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 5, 1, 15.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 3, 1, 8.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0);
INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0);

/**
* (SqLite-)Database Schema for validator tests
*/

DROP TABLE IF EXISTS tbl_validator_main;
DROP TABLE IF EXISTS tbl_validator_ref;

CREATE TABLE tbl_validator_main (
id INTEGER PRIMARY KEY ,
field1 VARCHAR(255)
);

CREATE TABLE tbl_validator_ref (
id INTEGER PRIMARY KEY ,
a_field VARCHAR(255),
ref INT(11)
);

INSERT INTO tbl_validator_main (id, field1) VALUES (1, 'just a string1');
INSERT INTO tbl_validator_main (id, field1) VALUES (2, 'just a string2');
INSERT INTO tbl_validator_main (id, field1) VALUES (3, 'just a string3');
INSERT INTO tbl_validator_main (id, field1) VALUES (4, 'just a string4');
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (1, 'ref_to_2', 2);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (2, 'ref_to_2', 2);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (3, 'ref_to_3', 3);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (4, 'ref_to_4', 4);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (5, 'ref_to_4', 4);
INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (6, 'ref_to_5', 5);
44 changes: 44 additions & 0 deletions tests/unit/data/validators/TestValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace yiiunit\data\validators;


use yii\validators\Validator;

class TestValidator extends Validator
{
private $_validatedAttributes = array();
private $_setErrorOnValidateAttribute = false;

public function validateAttribute($object, $attribute)
{
$this->markAttributeValidated($attribute);
if ($this->_setErrorOnValidateAttribute == true) {
$this->addError($object, $attribute, sprintf('%s##%s', $attribute, get_class($object)));
}
}

protected function markAttributeValidated($attr, $increaseBy = 1)
{
if (!isset($this->_validatedAttributes[$attr])) {
$this->_validatedAttributes[$attr] = 1;
} else {
$this->_validatedAttributes[$attr] = $this->_validatedAttributes[$attr] + $increaseBy;
}
}

public function countAttributeValidations($attr)
{
return isset($this->_validatedAttributes[$attr]) ? $this->_validatedAttributes[$attr] : 0;
}

public function isAttributeValidated($attr)
{
return isset($this->_validatedAttributes[$attr]);
}

public function enableErrorOnValidateAttribute()
{
$this->_setErrorOnValidateAttribute = true;
}
}
66 changes: 66 additions & 0 deletions tests/unit/data/validators/models/FakedValidationModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace yiiunit\data\validators\models;

use yii\base\Model;

/**
* @codeCoverageIgnore
*/
class FakedValidationModel extends Model
{
public $val_attr_a;
public $val_attr_b;
public $val_attr_c;
public $val_attr_d;
private $attr = array();

/**
* @param array $attributes
* @return self
*/
public static function createWithAttributes($attributes = array())
{
$m = new static();
foreach ($attributes as $attribute => $value) {
$m->$attribute = $value;
}
return $m;
}

public function rules()
{
return array(
array('val_attr_a, val_attr_b', 'required', 'on' => 'reqTest'),
array('val_attr_c', 'integer'),
);
}

public function inlineVal($attribute, $params = array())
{
return true;
}

public function __get($name)
{
if (stripos($name, 'attr') === 0) {
return isset($this->attr[$name]) ? $this->attr[$name] : null;
}

return parent::__get($name);
}

public function __set($name, $value)
{
if (stripos($name, 'attr') === 0) {
$this->attr[$name] = $value;
} else {
parent::__set($name, $value);
}
}

public function getAttributeLabel($attr)
{
return $attr;
}
}
21 changes: 21 additions & 0 deletions tests/unit/data/validators/models/ValidatorTestMainModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace yiiunit\data\validators\models;


use yii\db\ActiveRecord;

class ValidatorTestMainModel extends ActiveRecord
{
public $testMainVal = 1;

public static function tableName()
{
return 'tbl_validator_main';
}

public function getReferences()
{
return $this->hasMany(ValidatorTestRefModel::className(), array('ref' => 'id'));
}
}
23 changes: 23 additions & 0 deletions tests/unit/data/validators/models/ValidatorTestRefModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace yiiunit\data\validators\models;


use yii\db\ActiveRecord;

class ValidatorTestRefModel extends ActiveRecord
{

public $test_val = 2;
public $test_val_fail = 99;

public static function tableName()
{
return 'tbl_validator_ref';
}

public function getMain()
{
return $this->hasOne(ValidatorTestMainModel::className(), array('id' => 'ref'));
}
}
6 changes: 5 additions & 1 deletion tests/unit/framework/db/DatabaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ abstract class DatabaseTestCase extends TestCase
protected $database;
protected $driverName = 'mysql';
protected $db;
protected $initializeAppWithDb = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about naming, or if this is to be avoided.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we don't need it. You can assign ActiveRecord::$db with $this->getConnection(), like ActiveRecordTest.


protected function setUp()
{
Expand All @@ -18,7 +19,10 @@ protected function setUp()
$pdo_database = 'pdo_'.$this->driverName;

if (!extension_loaded('pdo') || !extension_loaded($pdo_database)) {
$this->markTestSkipped('pdo and pdo_'.$pdo_database.' extension are required.');
$this->markTestSkipped('pdo and '.$pdo_database.' extension are required.');
}
if ($this->initializeAppWithDb === true) {
\Yii::$app->setComponent('db', $this->getConnection());
}
}

Expand Down
Loading