Skip to content

Commit

Permalink
CustomContentsController::view のユニットテスト (#2756)
Browse files Browse the repository at this point in the history
Co-authored-by: Đỗ Văn Hùng <[email protected]>
Co-authored-by: ryuring <[email protected]>
  • Loading branch information
3 people authored Sep 25, 2023
1 parent 284e92e commit e4eec77
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public function index(CustomContentFrontServiceInterface $service)
*
* @param CustomContentFrontServiceInterface $service
* @return \Cake\Http\Response
* @checked
* @noTodo
* @unitTest
*/
public function view(CustomContentFrontServiceInterface $service, $entryId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,44 @@ public function test_index()
*/
public function test_view()
{
$this->markTestIncomplete('テストが未実装です');
$this->enableSecurityToken();
$this->enableCsrfToken();
//データーを生成
$this->loadFixtureScenario(InitAppScenario::class);
$dataBaseService = $this->getService(BcDatabaseServiceInterface::class);
$customTable = $this->getService(CustomTablesServiceInterface::class);

//カスタムテーブルとカスタムエントリテーブルを生成
$customTable->create([
'id' => 1,
'name' => 'recruit_categories',
'title' => '求人情報',
'type' => '1',
'display_field' => 'title',
'publish_begin' => '2021-10-01 00:00:00',
'publish_end' => '9999-11-30 23:59:59',
'has_child' => 0
]);
$this->loadFixtureScenario(CustomContentsScenario::class);
$this->loadFixtureScenario(CustomEntriesScenario::class);
$this->loadFixtureScenario(CustomFieldsScenario::class);

//対象URLをコル
$this->get('/test/view/プログラマー');
$vars = $this->_controller->viewBuilder()->getVars();
$this->assertResponseCode(200);
$this->assertEquals('サービスタイトル', $vars['title']);
$this->assertNotNull($vars['customContent']);
$this->assertNotNull($vars['customEntry']);

//存在しないURLを指定した場合、
$this->get('/test-false/view/プログラマー');
$this->assertResponseCode(404);
$this->assertEquals(
'カスタムコンテンツにカスタムテーブルが紐付けられていません。カスタムコンテンツの編集画面よりカスタムテーブルを選択してください。',
$_SESSION['Flash']['flash'][0]['message']
);
//不要なテーブルを削除
$dataBaseService->dropTable('custom_entry_1_recruit_categories');
}
}

0 comments on commit e4eec77

Please sign in to comment.