Skip to content

Commit

Permalink
unitTest_CustomContentTable_createSearchIndex (#3393)
Browse files Browse the repository at this point in the history
Co-authored-by: thangnn <[email protected]>
  • Loading branch information
thangnnmd and thangnn authored Apr 29, 2024
1 parent 73a8f0b commit 9783c4e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function beforeSave(EventInterface $event, EntityInterface $entity, \Arra
* @return array|false
* @checked
* @noTodo
* @unitTest
*/
public function createSearchIndex($entity)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,6 +25,11 @@
class CustomContentsTableTest extends BcTestCase
{

/**
* ScenarioAwareTrait
*/
use ScenarioAwareTrait;

/**
* Set up
*/
Expand Down Expand 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');
}
}

0 comments on commit 9783c4e

Please sign in to comment.