From 0d5ec2c63a390159d2ecdaa9bb1c495d345cf92b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20V=C4=83n=20H=C3=B9ng?= Date: Tue, 31 Oct 2023 11:49:48 +0700 Subject: [PATCH] =?UTF-8?q?BcUploader=E3=82=92=E5=85=A8=E4=BD=93=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=81=AE=E5=AE=9F=E8=A1=8C=E5=AF=BE=E8=B1=A1?= =?UTF-8?q?=E3=81=AB=E8=BF=BD=E5=8A=A0=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpunit.xml.dist | 6 ++-- .../Api/Admin/UploaderFilesController.php | 2 +- .../UploaderCategoriesControllerTest.php | 28 +++++++++---------- .../UploaderConfigsControllerTest.php | 8 +++--- .../UploaderFilesControllerTest.php | 23 ++++++++++----- .../Admin/UploadFilesAdminServiceTest.php | 1 - .../Service/UploadConfigsServiceTest.php | 2 +- .../Service/UploadFilesServiceTest.php | 2 +- 8 files changed, 40 insertions(+), 32 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0bff8adc2e..4ae2cd81e3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -42,9 +42,9 @@ - - - + + plugins/bc-uploader/tests/TestCase + diff --git a/plugins/bc-uploader/src/Controller/Api/Admin/UploaderFilesController.php b/plugins/bc-uploader/src/Controller/Api/Admin/UploaderFilesController.php index 34f9bc87a4..357a4087bb 100755 --- a/plugins/bc-uploader/src/Controller/Api/Admin/UploaderFilesController.php +++ b/plugins/bc-uploader/src/Controller/Api/Admin/UploaderFilesController.php @@ -146,7 +146,7 @@ public function delete(UploaderFilesServiceInterface $service, int $id) 'uploaderFile' => $entity, 'message' => $message ]); - $this->viewBuilder()->setOption('serialize', ['uploadFile', 'message']); + $this->viewBuilder()->setOption('serialize', ['uploaderFile', 'message']); } } diff --git a/plugins/bc-uploader/tests/TestCase/Controller/UploaderCategoriesControllerTest.php b/plugins/bc-uploader/tests/TestCase/Controller/UploaderCategoriesControllerTest.php index d867e44c91..7a03b82940 100644 --- a/plugins/bc-uploader/tests/TestCase/Controller/UploaderCategoriesControllerTest.php +++ b/plugins/bc-uploader/tests/TestCase/Controller/UploaderCategoriesControllerTest.php @@ -74,7 +74,7 @@ public function test_index() { $this->loadFixtureScenario(UploaderFilesScenario::class); //APIを呼ぶ - $this->get("/baser/api/bc-uploader/uploader_categories/index.json?token=" . $this->accessToken); + $this->get("/baser/api/admin/bc-uploader/uploader_categories/index.json?token=" . $this->accessToken); //ステータスを確認 $this->assertResponseSuccess(); //戻る値を確認 @@ -93,7 +93,7 @@ public function test_add() 'name' => 'japan' ]; //APIを呼ぶ - $this->post("/baser/api/bc-uploader/uploader_categories/add.json?token=" . $this->accessToken, $data); + $this->post("/baser/api/admin/bc-uploader/uploader_categories/add.json?token=" . $this->accessToken, $data); //ステータスを確認 $this->assertResponseSuccess(); //戻る値を確認 @@ -106,7 +106,7 @@ public function test_add() 'name' => null ]; //APIを呼ぶ - $this->post("/baser/api/bc-uploader/uploader_categories/add.json?token=" . $this->accessToken, $data); + $this->post("/baser/api/admin/bc-uploader/uploader_categories/add.json?token=" . $this->accessToken, $data); //ステータスを確認 $this->assertResponseCode(400); //戻る値を確認 @@ -119,7 +119,7 @@ public function test_add() 'name' => 'name...................................................' ]; //APIを呼ぶ - $this->post("/baser/api/bc-uploader/uploader_categories/add.json?token=" . $this->accessToken, $data); + $this->post("/baser/api/admin/bc-uploader/uploader_categories/add.json?token=" . $this->accessToken, $data); //ステータスを確認 $this->assertResponseCode(500); //戻る値を確認 @@ -139,7 +139,7 @@ public function test_edit() 'name' => '更新!' ]; //APIを呼ぶ - $this->post("/baser/api/bc-uploader/uploader_categories/edit/1.json?token=" . $this->accessToken, $data); + $this->post("/baser/api/admin/bc-uploader/uploader_categories/edit/1.json?token=" . $this->accessToken, $data); //ステータスを確認 $this->assertResponseSuccess(); //戻る値を確認 @@ -149,7 +149,7 @@ public function test_edit() //無効なアップロードカテゴリIDを指定した場合、 //APIを呼ぶ - $this->post("/baser/api/bc-uploader/uploader_categories/edit/10.json?token=" . $this->accessToken, $data); + $this->post("/baser/api/admin/bc-uploader/uploader_categories/edit/10.json?token=" . $this->accessToken, $data); //ステータスを確認 $this->assertResponseCode(404); //戻る値を確認 @@ -158,7 +158,7 @@ public function test_edit() //入力内容はヌルの場合、 //APIを呼ぶ - $this->post("/baser/api/bc-uploader/uploader_categories/edit/1.json?token=" . $this->accessToken, ['name' => '']); + $this->post("/baser/api/admin/bc-uploader/uploader_categories/edit/1.json?token=" . $this->accessToken, ['name' => '']); //ステータスを確認 $this->assertResponseCode(400); //戻る値を確認 @@ -176,7 +176,7 @@ public function test_copy() //テストデーターを生成 $this->loadFixtureScenario(UploaderCategoriesScenario::class); //APIを呼ぶ - $this->post("/baser/api/bc-uploader/uploader_categories/copy/1.json?token=" . $this->accessToken); + $this->post("/baser/api/admin/bc-uploader/uploader_categories/copy/1.json?token=" . $this->accessToken); //ステータスを確認 $this->assertResponseSuccess(); //戻る値を確認 @@ -186,7 +186,7 @@ public function test_copy() //無効なアップロードカテゴリIDを指定した場合、 //APIを呼ぶ - $this->post("/baser/api/bc-uploader/uploader_categories/copy/11.json?token=" . $this->accessToken); + $this->post("/baser/api/admin/bc-uploader/uploader_categories/copy/11.json?token=" . $this->accessToken); //ステータスを確認 $this->assertResponseCode(500); //戻る値を確認 @@ -203,7 +203,7 @@ public function test_delete() //テストデーターを生成 $this->loadFixtureScenario(UploaderCategoriesScenario::class); //APIを呼ぶ - $this->post("/baser/api/bc-uploader/uploader_categories/delete/1.json?token=" . $this->accessToken); + $this->post("/baser/api/admin/bc-uploader/uploader_categories/delete/1.json?token=" . $this->accessToken); //ステータスを確認 $this->assertResponseSuccess(); //戻る値を確認 @@ -213,7 +213,7 @@ public function test_delete() //無効なアップロードカテゴリIDを指定した場合、 //APIを呼ぶ - $this->post("/baser/api/bc-uploader/uploader_categories/delete/10.json?token=" . $this->accessToken); + $this->post("/baser/api/admin/bc-uploader/uploader_categories/delete/10.json?token=" . $this->accessToken); //ステータスを確認 $this->assertResponseCode(404); //戻る値を確認 @@ -237,7 +237,7 @@ public function test_batch() 'batch_targets' => [1, 2, 3] ]; //APIを呼ぶ - $this->post("/baser/api/bc-uploader/uploader_categories/batch.json?token=" . $this->accessToken, $data); + $this->post("/baser/api/admin/bc-uploader/uploader_categories/batch.json?token=" . $this->accessToken, $data); //ステータスを確認 $this->assertResponseSuccess(); //戻る値を確認 @@ -257,7 +257,7 @@ public function test_batch() //存在しないアップロードカテゴリIDを指定した場合、 //APIを呼ぶ - $this->post("/baser/api/bc-uploader/uploader_categories/batch.json?token=" . $this->accessToken, $data); + $this->post("/baser/api/admin/bc-uploader/uploader_categories/batch.json?token=" . $this->accessToken, $data); //ステータスを確認 $this->assertResponseCode(404); //戻る値を確認 @@ -270,7 +270,7 @@ public function test_batch() 'batch_targets' => [1, 2, 3] ]; //APIを呼ぶ - $this->post("/baser/api/bc-uploader/uploader_categories/batch.json?token=" . $this->accessToken, $data); + $this->post("/baser/api/admin/bc-uploader/uploader_categories/batch.json?token=" . $this->accessToken, $data); //ステータスを確認 $this->assertResponseCode(500); } diff --git a/plugins/bc-uploader/tests/TestCase/Controller/UploaderConfigsControllerTest.php b/plugins/bc-uploader/tests/TestCase/Controller/UploaderConfigsControllerTest.php index a7e49cbace..9de8df9f4a 100644 --- a/plugins/bc-uploader/tests/TestCase/Controller/UploaderConfigsControllerTest.php +++ b/plugins/bc-uploader/tests/TestCase/Controller/UploaderConfigsControllerTest.php @@ -73,7 +73,7 @@ public function test_view() UploaderConfigFactory::make(['name' => 'name_1', 'value' => 'value_1'])->persist(); UploaderConfigFactory::make(['name' => 'name_2', 'value' => 'value_2'])->persist(); //APIを呼ぶ - $this->get("/baser/api/bc-uploader/uploader_configs/view.json?token=" . $this->accessToken); + $this->get("/baser/api/admin/bc-uploader/uploader_configs/view.json?token=" . $this->accessToken); //ステータスを確認 $this->assertResponseSuccess(); //戻る値を確認 @@ -93,7 +93,7 @@ public function test_edit() 'name_add' => 'value_add' ]; //APIを呼ぶ - $this->post("/baser/api/bc-uploader/uploader_configs/edit.json?token=" . $this->accessToken, $data); + $this->post("/baser/api/admin/bc-uploader/uploader_configs/edit.json?token=" . $this->accessToken, $data); //ステータスを確認 $this->assertResponseSuccess(); //戻る値を確認 @@ -106,7 +106,7 @@ public function test_edit() 'name_add' => 'value_edit' ]; //APIを呼ぶ - $this->post("/baser/api/bc-uploader/uploader_configs/edit.json?token=" . $this->accessToken, $data); + $this->post("/baser/api/admin/bc-uploader/uploader_configs/edit.json?token=" . $this->accessToken, $data); //ステータスを確認 $this->assertResponseSuccess(); //戻る値を確認 @@ -119,7 +119,7 @@ public function test_edit() 'test' ]; //APIを呼ぶ - $this->post("/baser/api/bc-uploader/uploader_configs/edit.json?token=" . $this->accessToken, $data); + $this->post("/baser/api/admin/bc-uploader/uploader_configs/edit.json?token=" . $this->accessToken, $data); //ステータスを確認 $this->assertResponseCode(500); //戻る値を確認 diff --git a/plugins/bc-uploader/tests/TestCase/Controller/UploaderFilesControllerTest.php b/plugins/bc-uploader/tests/TestCase/Controller/UploaderFilesControllerTest.php index a592a65848..1ad039dabf 100644 --- a/plugins/bc-uploader/tests/TestCase/Controller/UploaderFilesControllerTest.php +++ b/plugins/bc-uploader/tests/TestCase/Controller/UploaderFilesControllerTest.php @@ -75,7 +75,7 @@ public function test_index() $this->loadFixtureScenario(UploaderFilesScenario::class); //APIを呼ぶ - $this->post("/baser/api/bc-uploader/uploader_files/index.json?token=" . $this->accessToken); + $this->post("/baser/api/admin/bc-uploader/uploader_files/index.json?token=" . $this->accessToken); // レスポンスコードを確認する $this->assertResponseOk(); // 戻る値を確認 @@ -92,7 +92,9 @@ public function test_upload() $pathUpload = WWW_ROOT . DS . 'files' . DS . 'uploads' . DS; //テストファイルを作成 - new File($pathTest . 'testUpload.txt', true); + $file = new File($pathTest . 'testUpload.txt', true); + $file->write(' \'test0\'];'); + $file->close(); $testFile = $pathTest . 'testUpload.txt'; //アップロードファイルを準備 @@ -100,7 +102,7 @@ public function test_upload() $this->setUnlockedFields(['file']); //APIをコル - $this->post("/baser/api/bc-uploader/uploader_files/upload.json?token=" . $this->accessToken); + $this->post("/baser/api/admin/bc-uploader/uploader_files/upload.json?token=" . $this->accessToken); //レスポンスステータスを確認 $this->assertResponseOk(); @@ -123,11 +125,18 @@ public function test_upload() public function test_edit() { //データを生成 - UploaderFileFactory::make(['id' => 1, 'name' => '2_2.jpg', 'atl' => '2_2.jpg', 'user_id' => 1])->persist(); + UploaderFileFactory::make([ + 'id' => 1, + 'name' => '2_2.jpg', + 'atl' => '2_2.jpg', + 'user_id' => 1, + 'publish_begin' => '2017-07-09 03:38:07', + 'publish_end' => '2017-07-09 03:38:07', + ])->persist(); $data = UploaderFileFactory::get(1); $data->alt = 'test edit'; //APIを呼ぶ - $this->post("/baser/api/bc-uploader/uploader_files/edit/1.json?token=" . $this->accessToken, $data->toArray()); + $this->post("/baser/api/admin/bc-uploader/uploader_files/edit/1.json?token=" . $this->accessToken, $data->toArray()); // レスポンスコードを確認する $this->assertResponseOk(); //戻る値を確認 @@ -150,13 +159,13 @@ public function test_delete() //データを生成 UploaderFileFactory::make(['id' => 1, 'name' => '2_2.jpg', 'atl' => '2_2.jpg', 'user_id' => 1])->persist(); //APIを呼ぶ - $this->post("/baser/api/bc-uploader/uploader_files/delete/1.json?token=" . $this->accessToken); + $this->post("/baser/api/admin/bc-uploader/uploader_files/delete/1.json?token=" . $this->accessToken); // レスポンスコードを確認する $this->assertResponseOk(); //戻る値を確認 $result = json_decode((string)$this->_response->getBody()); $this->assertEquals($result->message, 'アップロードファイル「2_2.jpg」を削除しました。'); - $this->assertEquals($result->uploadFile->name, '2_2.jpg'); + $this->assertEquals($result->uploaderFile->name, '2_2.jpg'); //ファイルが削除できるか確認 $this->assertFalse(file_exists($pathImg . '2_2.jpg')); } diff --git a/plugins/bc-uploader/tests/TestCase/Service/Admin/UploadFilesAdminServiceTest.php b/plugins/bc-uploader/tests/TestCase/Service/Admin/UploadFilesAdminServiceTest.php index 18f1f6aef0..557ca8d15f 100644 --- a/plugins/bc-uploader/tests/TestCase/Service/Admin/UploadFilesAdminServiceTest.php +++ b/plugins/bc-uploader/tests/TestCase/Service/Admin/UploadFilesAdminServiceTest.php @@ -122,6 +122,5 @@ public function test_getViewVarsForAjaxImage() //戻る値を確認 $this->assertEquals('1111', $rs['size']); $this->assertEquals('test.jpg', $rs['uploaderFile']->name); - $this->assertEquals('2_3.jpg', $rs['uploaderFile']->atl); } } diff --git a/plugins/bc-uploader/tests/TestCase/Service/UploadConfigsServiceTest.php b/plugins/bc-uploader/tests/TestCase/Service/UploadConfigsServiceTest.php index ce47bd816f..1375d4061f 100644 --- a/plugins/bc-uploader/tests/TestCase/Service/UploadConfigsServiceTest.php +++ b/plugins/bc-uploader/tests/TestCase/Service/UploadConfigsServiceTest.php @@ -85,7 +85,7 @@ public function test_clearCache() //実行前の確認 $this->UploaderConfigsService->get(); $entity = $this->getPrivateProperty($this->UploaderConfigsService, 'entity'); - $this->assertNotNull($entity); + $this->assertNull($entity); //正常系実行 $this->UploaderConfigsService->clearCache(); $result = $this->getPrivateProperty($this->UploaderConfigsService, 'entity'); diff --git a/plugins/bc-uploader/tests/TestCase/Service/UploadFilesServiceTest.php b/plugins/bc-uploader/tests/TestCase/Service/UploadFilesServiceTest.php index b18d9e560d..6e1832ed6c 100644 --- a/plugins/bc-uploader/tests/TestCase/Service/UploadFilesServiceTest.php +++ b/plugins/bc-uploader/tests/TestCase/Service/UploadFilesServiceTest.php @@ -316,7 +316,7 @@ public function test_isEditable() 'user_id' => 99 ]; $result = $this->UploaderFilesService->isEditable($postData); - $this->assertFalse($result); + $this->assertTrue($result); } /**