Skip to content

Commit

Permalink
BcUploaderを全体テストの実行対象に追加する (#2838)
Browse files Browse the repository at this point in the history
  • Loading branch information
HungDV2022 authored Nov 15, 2023
1 parent 4b426a9 commit 8c41b21
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 56 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 @@ -50,7 +50,6 @@ public function index(UploaderFilesServiceInterface $service)
* @param UploaderFilesServiceInterface $service
* @checked
* @noTodo
* @unitTest
*/
public function upload(UploaderFilesServiceInterface $service)
{
Expand Down Expand Up @@ -146,7 +145,7 @@ public function delete(UploaderFilesServiceInterface $service, int $id)
'uploaderFile' => $entity,
'message' => $message
]);
$this->viewBuilder()->setOption('serialize', ['uploadFile', 'message']);
$this->viewBuilder()->setOption('serialize', ['uploaderFile', 'message']);
}

}
1 change: 0 additions & 1 deletion plugins/bc-uploader/src/Service/UploaderFilesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ public function update(EntityInterface $entity, array $postData)
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public function isEditable(array $postData)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function load(...$args)
UploaderCategoryFactory::make(['id' => 2, 'name' => 'contact'])->persist();

//アップロードファイルデータを生成
UploaderFileFactory::make(['id' => 1, 'name' => 'social_new.jpg', 'atl' => 'social_new.jpg', 'uploader_category_id' => 1, 'user_id' => 1])->persist();
UploaderFileFactory::make(['id' => 1, 'name' => 'social_new.jpg', 'atl' => 'social_new.jpg', 'uploader_category_id' => 1, 'user_id' => 1, 'publish_begin' => '2017-07-09 03:38:07', 'publish_end' => '2017-07-09 03:38:07'])->persist();
UploaderFileFactory::make(['id' => 2, 'name' => 'widget-hero.jpg', 'atl' => 'widget-hero.jpg', 'uploader_category_id' => 1, 'user_id' => 1])->persist();
UploaderFileFactory::make(['id' => 3, 'name' => 'logo-48x48_c.png', 'atl' => 'logo-48x48_c.jpg', 'uploader_category_id' => 2, 'user_id' => 1])->persist();
UploaderFileFactory::make(['id' => 4, 'name' => '2_1.jpg', 'atl' => '2_1.jpg', 'user_id' => 1])->persist();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public function setUp(): void
public function tearDown(): void
{
parent::tearDown();
$this->truncateTable('uploader_categories');
$this->truncateTable('uploader_files');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @license https://basercms.net/license/index.html MIT License
*/

namespace BcUploader\Test\TestCase\Controller\Api;
namespace BcUploader\Test\TestCase\Controller;

use BaserCore\Service\DblogsServiceInterface;
use BaserCore\Test\Scenario\InitAppScenario;
Expand Down Expand Up @@ -64,6 +64,8 @@ public function setUp(): void
public function tearDown(): void
{
parent::tearDown();
$this->truncateTable('uploader_categories');
$this->truncateTable('uploader_files');
}

/**
Expand All @@ -74,7 +76,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 +95,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 +108,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 +121,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 +141,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 +151,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 +160,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 +178,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 +188,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 +205,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 +215,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 +239,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 +259,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 +272,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 @@ -9,7 +9,7 @@
* @license https://basercms.net/license/index.html MIT License
*/

namespace BcUploader\Test\TestCase\Controller\Api;
namespace BcUploader\Test\TestCase\Controller;

use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
Expand Down Expand Up @@ -61,6 +61,8 @@ public function setUp(): void
public function tearDown(): void
{
parent::tearDown();
$this->truncateTable('uploader_categories');
$this->truncateTable('uploader_files');
}

/**
Expand All @@ -73,7 +75,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 +95,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 +108,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 +121,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 @@ -9,7 +9,7 @@
* @license https://basercms.net/license/index.html MIT License
*/

namespace BcUploader\Test\TestCase\Controller\Api;
namespace BcUploader\Test\TestCase\Controller;

use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
Expand Down Expand Up @@ -63,6 +63,8 @@ public function setUp(): void
public function tearDown(): void
{
parent::tearDown();
$this->truncateTable('uploader_categories');
$this->truncateTable('uploader_files');
}

/**
Expand All @@ -75,7 +77,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 @@ -88,19 +90,22 @@ public function test_index()
*/
public function test_upload()
{
$this->markTestIncomplete('こちらのテストはまだ未確認です');
$pathTest = TMP . 'test' . DS;
$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,17 +128,17 @@ public function test_upload()
public function test_edit()
{
//データを生成
UploaderFileFactory::make(['id' => 1, 'name' => '2_2.jpg', 'atl' => '2_2.jpg', 'user_id' => 1])->persist();
$this->loadFixtureScenario(UploaderFilesScenario::class);
$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();
//戻る値を確認
$result = json_decode((string)$this->_response->getBody());
//メッセージを確認
$this->assertEquals($result->message, 'アップロードファイル「2_2.jpg」を更新しました。');
$this->assertEquals($result->message, 'アップロードファイル「social_new.jpg」を更新しました。');
//値が変更されるか確認
$this->assertEquals($result->uploaderFile->alt, 'test edit');
}
Expand All @@ -146,17 +151,17 @@ public function test_delete()
{
$pathImg = WWW_ROOT . DS . 'files' . DS . 'uploads' . DS;
//テストファイルを作成
new File($pathImg . '2_2.jpg', true);
new File($pathImg . 'social_new.jpg', true);
//データを生成
UploaderFileFactory::make(['id' => 1, 'name' => '2_2.jpg', 'atl' => '2_2.jpg', 'user_id' => 1])->persist();
$this->loadFixtureScenario(UploaderFilesScenario::class);
//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->message, 'アップロードファイル「social_new.jpg」を削除しました。');
$this->assertEquals($result->uploaderFile->name, 'social_new.jpg');
//ファイルが削除できるか確認
$this->assertFalse(file_exists($pathImg . '2_2.jpg'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public function tearDown(): void
{
unset($this->UploaderCategoriesTable);
parent::tearDown();
$this->truncateTable('uploader_categories');
$this->truncateTable('uploader_files');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public function tearDown(): void
{
unset($this->UploaderFilesAdminService);
parent::tearDown();
$this->truncateTable('uploader_categories');
$this->truncateTable('uploader_files');
}

/**
Expand Down Expand Up @@ -122,6 +124,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 @@ -53,6 +53,8 @@ public function tearDown(): void
{
unset($this->UploaderCategoriesService);
parent::tearDown();
$this->truncateTable('uploader_categories');
$this->truncateTable('uploader_files');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public function setUp(): void
public function tearDown(): void
{
parent::tearDown();
$this->truncateTable('uploader_files');
$this->truncateTable('uploader_categories');
}

/**
Expand Down
Loading

0 comments on commit 8c41b21

Please sign in to comment.