Skip to content

Commit

Permalink
CustomEntriesTableTest-test_createSearchIndex (#2746)
Browse files Browse the repository at this point in the history
  • Loading branch information
nghiem-mb authored Sep 22, 2023
1 parent 45ca0f4 commit 589de68
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public function initialize(array $config): void
*
* @param CustomEntry $entry
* @return array|false
* @noTodo
* @checked
* @unitTest
*/
public function createSearchIndex(CustomEntry $entry)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@

namespace BcCustomContent\Test\TestCase\Model\Table;

use BaserCore\Service\BcDatabaseServiceInterface;
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
use BcCustomContent\Model\Entity\CustomEntry;
use BcCustomContent\Model\Table\CustomEntriesTable;
use BcCustomContent\Service\CustomEntriesService;
use BcCustomContent\Service\CustomEntriesServiceInterface;
use BcCustomContent\Service\CustomTablesServiceInterface;
use BcCustomContent\Test\Scenario\CustomContentsScenario;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
* CustomEntriesTableTest
* @property CustomEntriesTable $CustomEntriesTable
* @property CustomEntriesService $CustomEntriesService
*/
class CustomEntriesTableTest extends BcTestCase
{
Expand All @@ -35,7 +42,7 @@ class CustomEntriesTableTest extends BcTestCase
public function setUp(): void
{
parent::setUp();
$this->CustomEntriesTable = $this->getTableLocator()->get('BcCustomContent.CustomEntriesTable');
$this->CustomEntriesTable = new CustomEntriesTable();
$this->loadFixtureScenario(InitAppScenario::class);
}

Expand All @@ -62,11 +69,34 @@ public function test_initialize()
public function test_createSearchIndex()
{
//準備

$dataBaseService = $this->getService(BcDatabaseServiceInterface::class);
$customTable = $this->getService(CustomTablesServiceInterface::class);
$customTable->create([
'id' => 1,
'name' => 'recruit',
'title' => '求人情報',
'type' => '1',
'display_field' => 'title',
'has_child' => 0
]);
$this->loadFixtureScenario(CustomContentsScenario::class);
$entry = new CustomEntry(
[
'id' => 1,
'custom_table_id' => 1,
'published' => '2023-02-14 13:57:29',
'modified' => '2023-02-14 13:57:29',
'created' => '2023-01-30 07:09:22',
'name' => 'プログラマー',
'recruit_category' => '1',
]
);
//正常系実行

//異常系実行

$result = $this->CustomEntriesTable->createSearchIndex($entry);
$this->assertEquals('カスタムコンテンツ', $result['type']);
$this->assertEquals(1, $result['model_id']);
//不要なテーブルを削除
$dataBaseService->dropTable('custom_entry_1_recruit');

}

Expand Down

0 comments on commit 589de68

Please sign in to comment.