diff --git a/plugins/bc-blog/src/Model/Table/BlogCommentsTable.php b/plugins/bc-blog/src/Model/Table/BlogCommentsTable.php index eef4a52906..88a23dd891 100755 --- a/plugins/bc-blog/src/Model/Table/BlogCommentsTable.php +++ b/plugins/bc-blog/src/Model/Table/BlogCommentsTable.php @@ -32,6 +32,7 @@ class BlogCommentsTable extends BlogAppTable * @return Validator * @checked * @noTodo + * @unitTest */ public function validationDefault(Validator $validator): Validator { diff --git a/plugins/bc-blog/tests/TestCase/Model/BlogCommentsTableTest.php b/plugins/bc-blog/tests/TestCase/Model/BlogCommentsTableTest.php index 5cd4ee49e6..a2e7f6f2f0 100755 --- a/plugins/bc-blog/tests/TestCase/Model/BlogCommentsTableTest.php +++ b/plugins/bc-blog/tests/TestCase/Model/BlogCommentsTableTest.php @@ -57,79 +57,53 @@ public function test_initialize() /* * validate */ - public function test空チェック() + public function test_validationDefaultEmptyCheck() { - $this->markTestIncomplete('こちらのテストはまだ未確認です'); - $this->BlogComment->create([ - 'BlogComment' => [ - 'name' => '', - 'message' => '', - ] + $validator = $this->BlogCommentsTable->getValidator('default'); + $errors = $validator->validate([ + 'name' => '', + 'message' => '' ]); - - $this->assertFalse($this->BlogComment->validates()); - - $this->assertArrayHasKey('name', $this->BlogComment->validationErrors); - $this->assertEquals('お名前を入力してください。', current($this->BlogComment->validationErrors['name'])); - - $this->assertArrayHasKey('message', $this->BlogComment->validationErrors); - $this->assertEquals('コメントを入力してください。', current($this->BlogComment->validationErrors['message'])); + $this->assertEquals('お名前を入力してください。', current($errors['name'])); + $this->assertEquals('コメントを入力してください。', current($errors['message'])); } - public function test桁数チェック異常系() + public function test_validationDefaultMaxLength() { - $this->markTestIncomplete('こちらのテストはまだ未確認です'); - $this->BlogComment->create([ - 'BlogComment' => [ - 'name' => '123456789012345678901234567890123456789012345678901', - 'email' => '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456@example.com', - 'url' => 'http://example.com/1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456', - ] + $validator = $this->BlogCommentsTable->getValidator('default'); + $errors = $validator->validate([ + 'name' => str_repeat('a', 51), + 'email' => str_repeat('a', 246) . '@gmail.com', + 'url' => 'http://example.com/' . str_repeat('a', 237) ]); - $this->assertFalse($this->BlogComment->validates()); - - $this->assertArrayHasKey('name', $this->BlogComment->validationErrors); - $this->assertEquals('お名前は50文字以内で入力してください。', current($this->BlogComment->validationErrors['name'])); - $this->assertArrayHasKey('email', $this->BlogComment->validationErrors); - $this->assertEquals('Eメールは255文字以内で入力してください。', current($this->BlogComment->validationErrors['email'])); - - - $this->assertArrayHasKey('url', $this->BlogComment->validationErrors); - $this->assertEquals('URLは255文字以内で入力してください。', current($this->BlogComment->validationErrors['url'])); + $this->assertEquals('お名前は50文字以内で入力してください。', current($errors['name'])); + $this->assertEquals('Eメールは255文字以内で入力してください。', current($errors['email'])); + $this->assertEquals('URLは255文字以内で入力してください。', current($errors['url'])); } - public function test桁数チェック正常系() + public function test_validationDefaultNotError() { - $this->markTestIncomplete('こちらのテストはまだ未確認です'); - $this->BlogComment->create([ - 'BlogComment' => [ - 'name' => '12345678901234567890123456789012345678901234567890', - 'email' => '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@example.com', - 'url' => 'http://example.com/123456789012345678901234567890123456789012345678901234567890123456789012345678901234567567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456' - ] + $validator = $this->BlogCommentsTable->getValidator('default'); + $errors = $validator->validate([ + 'name' => str_repeat('a', 50), + 'email' => str_repeat('a', 245) . '@gmail.com', + 'url' => 'http://example.com/' . str_repeat('a', 236) ]); - $this->assertTrue($this->BlogComment->validates()); + $this->assertCount(0, $errors); } - public function testその他異常系() + public function test_validationDefaultOtherErrors() { - $this->markTestIncomplete('こちらのテストはまだ未確認です'); - // 形式チェック - $this->BlogComment->create([ - 'BlogComment' => [ - 'email' => 'hoge', - 'url' => 'hoge' - ] + $validator = $this->BlogCommentsTable->getValidator('default'); + $errors = $validator->validate([ + 'name' => str_repeat('a', 5), + 'email' => str_repeat('a', 10), + 'url' => str_repeat('a', 10) ]); - $this->assertFalse($this->BlogComment->validates()); - - $this->assertArrayHasKey('email', $this->BlogComment->validationErrors); - $this->assertEquals('Eメールの形式が不正です。', current($this->BlogComment->validationErrors['email'])); - - $this->assertArrayHasKey('url', $this->BlogComment->validationErrors); - $this->assertEquals('URLの形式が不正です。', current($this->BlogComment->validationErrors['url'])); + $this->assertEquals('Eメールの形式が不正です。', current($errors['email'])); + $this->assertEquals('URLの形式が不正です。', current($errors['url'])); } /**