diff --git a/plugins/bc-custom-content/src/Model/Table/CustomContentsTable.php b/plugins/bc-custom-content/src/Model/Table/CustomContentsTable.php index c1d88cb522..9f2e75759e 100644 --- a/plugins/bc-custom-content/src/Model/Table/CustomContentsTable.php +++ b/plugins/bc-custom-content/src/Model/Table/CustomContentsTable.php @@ -97,6 +97,7 @@ public function beforeSave(EventInterface $event, EntityInterface $entity, \Arra * @return array|false * @checked * @noTodo + * @unitTest */ public function createSearchIndex($entity) { diff --git a/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomContentsTableTest.php b/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomContentsTableTest.php index facd835119..fa4b1e1811 100644 --- a/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomContentsTableTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Model/Table/CustomContentsTableTest.php @@ -13,6 +13,10 @@ use BaserCore\TestSuite\BcTestCase; use BcCustomContent\Model\Table\CustomContentsTable; +use BcCustomContent\Service\CustomContentsService; +use BcCustomContent\Test\Factory\CustomContentFactory; +use BcCustomContent\Test\Scenario\CustomContentsScenario; +use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; /** * CustomContentsTableTest @@ -21,6 +25,11 @@ class CustomContentsTableTest extends BcTestCase { + /** + * ScenarioAwareTrait + */ + use ScenarioAwareTrait; + /** * Set up */ @@ -83,4 +92,37 @@ public function test_validationWithTable() '_empty' => '一覧表示件数は必須項目です。', ], $errors['list_count']); } + + /** + * test createSearchIndex + */ + public function test_createSearchIndex() + { + //content empty + $entity = CustomContentFactory::make([ + 'id' => 1, + ])->getEntity(); + $this->assertFalse($this->CustomContentsTable->createSearchIndex($entity)); + + //The system operates normally + $this->loadFixtureScenario(CustomContentsScenario::class); + $customContentService = new CustomContentsService(); + $customContent = $customContentService->get(1); + + //set content publish_begin and publish_end + $customContent->content->publish_begin = '2021-01-01 00:00:00'; + $customContent->content->publish_end = '2021-12-31 23:59:59'; + + $rs = $this->CustomContentsTable->createSearchIndex($customContent); + $this->assertEquals($rs['type'], 'カスタムコンテンツ'); + $this->assertEquals($rs['model_id'], 1); + $this->assertEquals($rs['content_id'], 100); + $this->assertEquals($rs['site_id'], 1); + $this->assertEquals($rs['title'], 'サービスタイトル'); + $this->assertEquals($rs['detail'], 'サービステスト'); + $this->assertEquals($rs['url'], '/test/'); + $this->assertTrue($rs['status']); + $this->assertEquals($rs['publish_begin'], '2021-01-01 00:00:00'); + $this->assertEquals($rs['publish_end'], '2021-12-31 23:59:59'); + } }