From 99238886378845741f22d1dfc15f2970d72202ef Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 29 Mar 2013 03:22:50 +0400 Subject: [PATCH] More Model tests --- tests/unit/data/base/InvalidRulesModel.php | 17 ++++++++++++++++ tests/unit/data/base/Singer.php | 21 ++++++++++++++++++++ tests/unit/data/base/Speaker.php | 3 +-- tests/unit/framework/base/ModelTest.php | 31 ++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 tests/unit/data/base/InvalidRulesModel.php create mode 100644 tests/unit/data/base/Singer.php diff --git a/tests/unit/data/base/InvalidRulesModel.php b/tests/unit/data/base/InvalidRulesModel.php new file mode 100644 index 0000000..f5a8438 --- /dev/null +++ b/tests/unit/data/base/InvalidRulesModel.php @@ -0,0 +1,17 @@ + 'Lennon'), + array('lastName', 'required'), + array('underscore_style', 'yii\validators\CaptchaValidator'), + ); + } +} \ No newline at end of file diff --git a/tests/unit/data/base/Speaker.php b/tests/unit/data/base/Speaker.php index 240b691..93dd496 100644 --- a/tests/unit/data/base/Speaker.php +++ b/tests/unit/data/base/Speaker.php @@ -1,11 +1,10 @@ assertNull($speaker['firstName']); $this->assertFalse(isset($speaker['firstName'])); } + + public function testDefaults() + { + $singer = new Model(); + $this->assertEquals(array(), $singer->rules()); + $this->assertEquals(array(), $singer->attributeLabels()); + } + + public function testDefaultScenarios() + { + $singer = new Singer(); + $this->assertEquals(array('default' => array('lastName', 'underscore_style')), $singer->scenarios()); + } + + public function testIsAttributeRequired() + { + $singer = new Singer(); + $this->assertFalse($singer->isAttributeRequired('firstName')); + $this->assertTrue($singer->isAttributeRequired('lastName')); + } + + public function testCreateValidators() + { + $this->setExpectedException('yii\base\InvalidConfigException', 'Invalid validation rule: a rule must be an array specifying both attribute names and validator type.'); + + $invalid = new InvalidRulesModel(); + $invalid->createValidators(); + } }