Skip to content

Commit

Permalink
BcUploaderを全体テストの実行対象に追加する
Browse files Browse the repository at this point in the history
  • Loading branch information
dovanhung committed Oct 31, 2023
1 parent a76d8e5 commit 0d5ec2c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 32 deletions.
6 changes: 3 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
<!-- <testsuite name="BcThemeFile">-->
<!-- <directory>plugins/bc-theme-file/tests/TestCase</directory>-->
<!-- </testsuite>-->
<!-- <testsuite name="BcUploader">-->
<!-- <directory>plugins/bc-uploader/tests/TestCase</directory>-->
<!-- </testsuite>-->
<testsuite name="BcUploader">
<directory>plugins/bc-uploader/tests/TestCase</directory>
</testsuite>
<!-- <testsuite name="BcWidgetArea">-->
<!-- <directory>plugins/bc-widget-area/tests/TestCase</directory>-->
<!-- </testsuite>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
//戻る値を確認
Expand All @@ -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();
//戻る値を確認
Expand All @@ -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);
//戻る値を確認
Expand All @@ -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);
//戻る値を確認
Expand All @@ -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();
//戻る値を確認
Expand All @@ -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);
//戻る値を確認
Expand All @@ -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);
//戻る値を確認
Expand All @@ -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();
//戻る値を確認
Expand All @@ -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);
//戻る値を確認
Expand All @@ -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();
//戻る値を確認
Expand All @@ -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);
//戻る値を確認
Expand All @@ -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();
//戻る値を確認
Expand All @@ -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);
//戻る値を確認
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
//戻る値を確認
Expand All @@ -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();
//戻る値を確認
Expand All @@ -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();
//戻る値を確認
Expand All @@ -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);
//戻る値を確認
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
// 戻る値を確認
Expand All @@ -92,15 +92,17 @@ 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('<?php return [\'updateMessage\' => \'test0\'];');
$file->close();
$testFile = $pathTest . 'testUpload.txt';

//アップロードファイルを準備
$this->setUploadFileToRequest('file', $testFile);
$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();
Expand All @@ -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();
//戻る値を確認
Expand All @@ -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'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public function test_isEditable()
'user_id' => 99
];
$result = $this->UploaderFilesService->isEditable($postData);
$this->assertFalse($result);
$this->assertTrue($result);
}

/**
Expand Down

0 comments on commit 0d5ec2c

Please sign in to comment.