diff --git a/plugins/bc-blog/src/Service/BlogCommentsService.php b/plugins/bc-blog/src/Service/BlogCommentsService.php index 985cd75455..c7e6278690 100755 --- a/plugins/bc-blog/src/Service/BlogCommentsService.php +++ b/plugins/bc-blog/src/Service/BlogCommentsService.php @@ -144,6 +144,7 @@ public function getNew() * @param array $postData * @return EntityInterface * @checked + * @unitTest */ public function add(int $blogContentId, int $blogPostId, array $postData) { diff --git a/plugins/bc-blog/tests/TestCase/Service/BlogCommentsServiceTest.php b/plugins/bc-blog/tests/TestCase/Service/BlogCommentsServiceTest.php index 998b5ab429..502a61d2d1 100755 --- a/plugins/bc-blog/tests/TestCase/Service/BlogCommentsServiceTest.php +++ b/plugins/bc-blog/tests/TestCase/Service/BlogCommentsServiceTest.php @@ -13,6 +13,7 @@ use BaserCore\TestSuite\BcTestCase; use BcBlog\Service\BlogCommentsService; +use BcBlog\Test\Factory\BlogCommentFactory; use BcBlog\Test\Factory\BlogPostFactory; use BcBlog\Test\Scenario\BlogCommentsScenario; use BcBlog\Test\Scenario\BlogCommentsServiceScenario; @@ -256,4 +257,46 @@ public function testGetNew() $result = $this->BlogCommentsService->getNew(); $this->assertEquals('NO NAME', $result['name']); } + /** + * add + * @return void + */ + public function testAdd() + { + //data test + $this->loadFixtureScenario( + BlogContentScenario::class, + 1, // id + 1, // siteId + null, // parentId + 'news1', // name + '/news/' // url + ); + BlogPostFactory::make(['id' => 1, 'blog_content_id' => 1])->persist(); + $data = [ + 'name' => 'baserCMS', + ]; + $result = $this->BlogCommentsService->add(1, 1, $data); + + //check result return + $this->assertEquals('baserCMS', $result['name']); + + //confirm result add + $comment = BlogCommentFactory::get(1); + $this->assertEquals($data['name'], $comment['name']); + $this->assertEquals(1, $comment['blog_content_id']); + + // null name + $data = [ + 'name' => null, + ]; + $this->expectExceptionMessage("お名前を入力してください。"); + $this->BlogCommentsService->add(1, 1, $data); + + //Exception + $this->expectException("Cake\ORM\Exception\PersistenceFailedException"); + $this->expectExceptionMessage("関連するコンテンツがありません"); + $this->BlogCommentsService->add(1, 1, []); + } + }