Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CustomContentsController::view のユニットテスト #2756

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,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 @@ -32,12 +32,16 @@ public function load(...$args)
'id' => 1,
'custom_table_id' => 1,
'description' => 'サービステスト',
'template' => 'template_1',
'template' => 'default',
"widget_area" => null,
"list_count" => 10,
"list_order" => "id",
"list_direction" => "DESC"
])->persist();
ContentFactory::make([
'id' => 1,
'url' => '/',
'name' => '',
'id' => 100,
'url' => '/test/',
'name' => 'test',
'plugin' => 'BcCustomContent',
'type' => 'CustomContent',
'site_id' => 1,
Expand All @@ -46,17 +50,19 @@ public function load(...$args)
'lft' => 1,
'rght' => 2,
'entity_id' => 1,
"level" => 1,
'layout_template' => 'default',
'status' => true
])->persist();

CustomContentFactory::make([
'id' => 2,
'custom_table_id' => 2,
'description' => '求人',
'template' => 'template_2',
'template' => 'default',
])->persist();
ContentFactory::make([
'id' => 2,
'id' => 102,
'url' => '/recruit/',
'plugin' => 'BcCustomContent',
'type' => 'CustomContent',
Expand All @@ -66,6 +72,32 @@ public function load(...$args)
'lft' => 3,
'rght' => 4,
'entity_id' => 2,
'layout_template' => 'default',
'status' => true
])->persist();

CustomContentFactory::make([
'id' => 3,
'description' => 'サービステスト',
'template' => 'default',
"widget_area" => null,
"list_count" => 10,
"list_order" => "id",
"list_direction" => "DESC"
])->persist();
ContentFactory::make([
'url' => '/test-false/',
'name' => 'test',
ryuring marked this conversation as resolved.
Show resolved Hide resolved
'plugin' => 'BcCustomContent',
'type' => 'CustomContent',
'site_id' => 1,
'parent_id' => null,
'title' => 'サービスタイトル',
'lft' => 11,
'rght' => 21,
'entity_id' => 3,
"level" => 1,
'layout_template' => 'default',
'status' => true
])->persist();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@

namespace BcCustomContent\Test\TestCase\Controller;

use BaserCore\Service\BcDatabaseServiceInterface;
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
use BcCustomContent\Controller\CustomContentController;
use BcCustomContent\Service\CustomTablesServiceInterface;
use BcCustomContent\Test\Scenario\CustomContentsScenario;
use BcCustomContent\Test\Scenario\CustomEntriesScenario;
use BcCustomContent\Test\Scenario\CustomFieldsScenario;
use Cake\Http\ServerRequest;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

Expand Down Expand Up @@ -82,6 +88,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');
}
}