From 5ca96242055dead5a8024c86cf9d9834110243f6 Mon Sep 17 00:00:00 2001 From: Maxim Mironyuk Date: Wed, 15 Jul 2015 19:08:28 +0300 Subject: [PATCH] not validate embedded, if attribute is not safe * --- AbstractEmbeddedBehavior.php | 8 +++++--- composer.json | 4 +++- tests/_bootstrap.php | 4 ++-- tests/_config.php | 2 +- tests/models/SlaveEmbeddedClass.php | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/AbstractEmbeddedBehavior.php b/AbstractEmbeddedBehavior.php index bb15c46..e1ff4ba 100644 --- a/AbstractEmbeddedBehavior.php +++ b/AbstractEmbeddedBehavior.php @@ -105,9 +105,11 @@ public function proxy($event) */ public function validate() { - $this->storage->setScenario($this->owner->scenario); - if (!$this->storage->validate()) { - $this->owner->addError($this->attribute, \Yii::t('yii', 'Embedded document in {attribute} must be valid.')); + if ($this->owner->isAttributeSafe($this->fakeAttribute)) { + $this->storage->setScenario($this->owner->scenario); + if (!$this->storage->validate()) { + $this->owner->addError($this->attribute, \Yii::t('yii', 'Embedded document in {attribute} must be valid.')); + } } } diff --git a/composer.json b/composer.json index c024aa3..749011d 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,9 @@ "minimum-stability": "dev", "require": { "yiisoft/yii2": "*", - "yiisoft/yii2-mongodb": "*" + "yiisoft/yii2-mongodb": "*", + "yiisoft/yii2-codeception": "*", + "codeception/codeception": "*" }, "autoload": { "psr-4": { diff --git a/tests/_bootstrap.php b/tests/_bootstrap.php index 236f902..ce7ca57 100644 --- a/tests/_bootstrap.php +++ b/tests/_bootstrap.php @@ -9,9 +9,9 @@ defined('YII_ENV') or define('YII_ENV', 'test'); -require_once(__DIR__ . '/../../../../vendor/autoload.php'); +require_once(__DIR__ . '/../vendor/autoload.php'); -require_once(__DIR__ . '/../../../../vendor/yiisoft/yii2/Yii.php'); +require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); $config = require('_config.php'); diff --git a/tests/_config.php b/tests/_config.php index 5a05721..ae2307b 100644 --- a/tests/_config.php +++ b/tests/_config.php @@ -14,7 +14,7 @@ ], 'mongodb' => [ 'class' => 'yii\mongodb\Connection', - 'dsn' => 'mongodb://mongo:27017/mongodb_embedded_test', + 'dsn' => 'mongodb://localhost:27018/mongodb_embedded_test', ], ], ]; diff --git a/tests/models/SlaveEmbeddedClass.php b/tests/models/SlaveEmbeddedClass.php index 1229b0d..770d37f 100644 --- a/tests/models/SlaveEmbeddedClass.php +++ b/tests/models/SlaveEmbeddedClass.php @@ -22,8 +22,8 @@ class SlaveEmbeddedClass extends EmbeddedDocument public function rules() { return [ - ['value', 'boolean', 'on' => 'requiredValue'], ['name', 'integer', 'on' => 'requiredName'], + ['value', 'boolean', 'on' => 'requiredValue'], [['name', 'value'], 'safe', 'on'=>'default'] ]; }