From 5805c280a07407e1ad3772c278ab370a0164fd82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Tue, 19 Sep 2023 19:34:55 +0700 Subject: [PATCH 1/5] =?UTF-8?q?CustomContentsController::initialize=20=20?= =?UTF-8?q?=E3=81=AE=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomContentsControllerTest.php | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php diff --git a/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php b/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php new file mode 100644 index 0000000000..dbfeb027d5 --- /dev/null +++ b/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php @@ -0,0 +1,87 @@ + + * Copyright (c) NPO baser foundation + * + * @copyright Copyright (c) NPO baser foundation + * @link https://basercms.net baserCMS Project + * @since 5.0.0 + * @license https://basercms.net/license/index.html MIT License + */ + +namespace BcCustomContent\Test\TestCase\Controller; + +use BaserCore\TestSuite\BcTestCase; +use BaserCore\Utility\BcContainerTrait; +use BcCustomContent\Controller\CustomContentController; +use Cake\Http\ServerRequest; +use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; + +/** + * CustomContentsControllerTest + */ +class CustomContentsControllerTest extends BcTestCase +{ + + /** + * ScenarioAwareTrait + */ + use ScenarioAwareTrait; + use BcContainerTrait; + + /** + * Test subject + * + * @var CustomContentController + */ + public $CustomContentsController; + + /** + * Test subject + * + * @var ServerRequest + */ + public $request; + + /** + * Set up + */ + public function setUp(): void + { + parent::setUp(); + $this->CustomContentsController = new CustomContentController($this->getRequest()); + } + + /** + * Tear down + */ + public function tearDown(): void + { + parent::tearDown(); + unset($this->CustomContentsController, $this->request); + } + + /** + * test initialize + */ + public function test_initialize() + { + $this->assertNotEmpty($this->CustomContentsController->BcFrontContents); + } + + /** + * test index + */ + public function test_index() + { + $this->markTestIncomplete('テストが未実装です'); + } + + /** + * test view + */ + public function test_view() + { + $this->markTestIncomplete('テストが未実装です'); + } +} From 87863651ca8b2e20937e5dd2f86b6beb11158419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Wed, 20 Sep 2023 08:01:20 +0700 Subject: [PATCH 2/5] =?UTF-8?q?CustomContentsController::index=20=20?= =?UTF-8?q?=E3=81=AE=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/CustomContentController.php | 3 ++ .../tests/Scenario/CustomContentsScenario.php | 19 +++++++--- .../CustomContentsControllerTest.php | 38 ++++++++++++++++++- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/plugins/bc-custom-content/src/Controller/CustomContentController.php b/plugins/bc-custom-content/src/Controller/CustomContentController.php index 09c1212ca9..93f669ee5b 100644 --- a/plugins/bc-custom-content/src/Controller/CustomContentController.php +++ b/plugins/bc-custom-content/src/Controller/CustomContentController.php @@ -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) { diff --git a/plugins/bc-custom-content/tests/Scenario/CustomContentsScenario.php b/plugins/bc-custom-content/tests/Scenario/CustomContentsScenario.php index 4bbce89a21..66bc35f223 100644 --- a/plugins/bc-custom-content/tests/Scenario/CustomContentsScenario.php +++ b/plugins/bc-custom-content/tests/Scenario/CustomContentsScenario.php @@ -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, @@ -46,6 +50,8 @@ public function load(...$args) 'lft' => 1, 'rght' => 2, 'entity_id' => 1, + "level"=> 1, + 'layout_template' => 'default', 'status' => true ])->persist(); @@ -53,10 +59,10 @@ public function load(...$args) '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', @@ -66,6 +72,7 @@ public function load(...$args) 'lft' => 3, 'rght' => 4, 'entity_id' => 2, + 'layout_template' => 'default', 'status' => true ])->persist(); } diff --git a/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php b/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php index dbfeb027d5..890551af3c 100644 --- a/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php @@ -11,9 +11,16 @@ 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\Factory\CustomLinkFactory; +use BcCustomContent\Test\Scenario\CustomContentsScenario; +use BcCustomContent\Test\Scenario\CustomEntriesScenario; +use BcCustomContent\Test\Scenario\CustomFieldsScenario; use Cake\Http\ServerRequest; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; @@ -74,7 +81,36 @@ public function test_initialize() */ public function test_index() { - $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 + ]); + $dataBaseService->addColumn('custom_entry_1_recruit_categories', 'recruit_category', 'integer'); + $this->loadFixtureScenario(CustomContentsScenario::class); + $this->loadFixtureScenario(CustomEntriesScenario::class); + $this->loadFixtureScenario(CustomFieldsScenario::class); + + + //対象URLをコル + $this->get('/test/view/プログラマー'); + $result = json_decode((string)$this->_response->getBody()); + $this->assertResponseCode(200); + //不要なテーブルを削除 + $dataBaseService->dropTable('custom_entry_1_recruit_categories'); } /** From 2b3a6733db33c8ebf85e7399e0a9ad9723f47155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Wed, 20 Sep 2023 12:03:20 +0700 Subject: [PATCH 3/5] =?UTF-8?q?CustomContentsController::index=20=20?= =?UTF-8?q?=E3=81=AE=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/CustomContentController.php | 3 +++ .../tests/Scenario/CustomContentsScenario.php | 27 ++++++++++++++++++- .../CustomContentsControllerTest.php | 15 ++++++++--- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/plugins/bc-custom-content/src/Controller/CustomContentController.php b/plugins/bc-custom-content/src/Controller/CustomContentController.php index 93f669ee5b..19f2b55d95 100644 --- a/plugins/bc-custom-content/src/Controller/CustomContentController.php +++ b/plugins/bc-custom-content/src/Controller/CustomContentController.php @@ -44,6 +44,9 @@ public function initialize(): void * * @param CustomContentFrontServiceInterface $service * @return \Cake\Http\Response + * @checked + * @noTodo + * @unitTest */ public function index(CustomContentFrontServiceInterface $service) { diff --git a/plugins/bc-custom-content/tests/Scenario/CustomContentsScenario.php b/plugins/bc-custom-content/tests/Scenario/CustomContentsScenario.php index 66bc35f223..2280e83fb5 100644 --- a/plugins/bc-custom-content/tests/Scenario/CustomContentsScenario.php +++ b/plugins/bc-custom-content/tests/Scenario/CustomContentsScenario.php @@ -50,7 +50,7 @@ public function load(...$args) 'lft' => 1, 'rght' => 2, 'entity_id' => 1, - "level"=> 1, + "level" => 1, 'layout_template' => 'default', 'status' => true ])->persist(); @@ -75,5 +75,30 @@ public function load(...$args) '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', + '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(); } } diff --git a/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php b/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php index 890551af3c..1feb12795c 100644 --- a/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php @@ -99,16 +99,25 @@ public function test_index() 'publish_end' => '9999-11-30 23:59:59', 'has_child' => 0 ]); - $dataBaseService->addColumn('custom_entry_1_recruit_categories', 'recruit_category', 'integer'); $this->loadFixtureScenario(CustomContentsScenario::class); $this->loadFixtureScenario(CustomEntriesScenario::class); $this->loadFixtureScenario(CustomFieldsScenario::class); - //対象URLをコル $this->get('/test/view/プログラマー'); - $result = json_decode((string)$this->_response->getBody()); + $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/'); + $this->assertResponseCode(404); + $this->assertEquals( + 'カスタムコンテンツにカスタムテーブルが紐付けられていません。カスタムコンテンツの編集画面よりカスタムテーブルを選択してください。', + $_SESSION['Flash']['flash'][0]['message'] + ); //不要なテーブルを削除 $dataBaseService->dropTable('custom_entry_1_recruit_categories'); } From cf7fc1cbd0c076c47aa57dece2df3281b50a0f06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Wed, 20 Sep 2023 20:08:54 +0700 Subject: [PATCH 4/5] =?UTF-8?q?CustomContentsController::index=20=20?= =?UTF-8?q?=E3=81=AE=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Controller/CustomContentController.php | 3 --- .../TestCase/Controller/CustomContentsControllerTest.php | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/plugins/bc-custom-content/src/Controller/CustomContentController.php b/plugins/bc-custom-content/src/Controller/CustomContentController.php index 19f2b55d95..37b800d3ed 100644 --- a/plugins/bc-custom-content/src/Controller/CustomContentController.php +++ b/plugins/bc-custom-content/src/Controller/CustomContentController.php @@ -78,9 +78,6 @@ public function index(CustomContentFrontServiceInterface $service) * * @param CustomContentFrontServiceInterface $service * @return \Cake\Http\Response - * @checked - * @noTodo - * @unitTest */ public function view(CustomContentFrontServiceInterface $service, $entryId) { diff --git a/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php b/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php index 1feb12795c..901fc83398 100644 --- a/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php +++ b/plugins/bc-custom-content/tests/TestCase/Controller/CustomContentsControllerTest.php @@ -104,12 +104,12 @@ public function test_index() $this->loadFixtureScenario(CustomFieldsScenario::class); //対象URLをコル - $this->get('/test/view/プログラマー'); + $this->get('/test/'); $vars = $this->_controller->viewBuilder()->getVars(); $this->assertResponseCode(200); $this->assertEquals('サービスタイトル', $vars['title']); $this->assertNotNull($vars['customContent']); - $this->assertNotNull($vars['customEntry']); + $this->assertNotNull($vars['customEntries']); //存在しないURLを指定した場合、 $this->get('/test-false/'); From a07220cbf7a28078d65e3c492a72c7e79974915f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Fri, 22 Sep 2023 12:37:08 +0700 Subject: [PATCH 5/5] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bc-custom-content/tests/Scenario/CustomContentsScenario.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/bc-custom-content/tests/Scenario/CustomContentsScenario.php b/plugins/bc-custom-content/tests/Scenario/CustomContentsScenario.php index 2280e83fb5..896cd48c88 100644 --- a/plugins/bc-custom-content/tests/Scenario/CustomContentsScenario.php +++ b/plugins/bc-custom-content/tests/Scenario/CustomContentsScenario.php @@ -87,7 +87,7 @@ public function load(...$args) ])->persist(); ContentFactory::make([ 'url' => '/test-false/', - 'name' => 'test', + 'name' => 'test-false', 'plugin' => 'BcCustomContent', 'type' => 'CustomContent', 'site_id' => 1,