Created
January 29, 2013 02:43
-
-
Save dai199/4661275 to your computer and use it in GitHub Desktop.
CakePHP2でmodelのバリデーションテストを行う
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // app/Model/User.php | |
| class User extends AppModel { | |
| public $validate = array( | |
| 'email' => 'email' | |
| ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // app/Test/Case/Model/UserTest.php | |
| App::uses('User', 'Model'); | |
| class UserTest extends CakeTestCase { | |
| public $fixtures = array( | |
| 'app.user' | |
| ); | |
| public function setUp(){ | |
| parent::setUp(); | |
| $this->User = ClassRegistry::init('User'); | |
| } | |
| public function tearDown(){ | |
| unset($this->User); | |
| parent::tearDown(); | |
| } | |
| public function testValidation(){ | |
| $data = array('User' => | |
| array( | |
| 'email' => 'test' // error | |
| ) | |
| ); | |
| $this->User->create($data); | |
| $result = $this->User->validates(); // true if there are no errors | |
| $this->assertFalse($result); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment