Skip to content

Commit

Permalink
ユニットテストを調整
Browse files Browse the repository at this point in the history
  • Loading branch information
dovanhung committed Nov 7, 2023
1 parent aeebde6 commit f26030b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
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 @@ -64,6 +64,7 @@ public function tearDown(): void
{
parent::tearDown();
$this->truncateTable('uploader_categories');
$this->truncateTable('uploader_files');
}

/**
Expand Down Expand Up @@ -126,14 +127,7 @@ public function test_upload()
public function test_edit()
{
//データを生成
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();
$this->loadFixtureScenario(UploaderFilesScenario::class);
$data = UploaderFileFactory::get(1);
$data->alt = 'test edit';
//APIを呼ぶ
Expand All @@ -143,7 +137,7 @@ public function test_edit()
//戻る値を確認
$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 @@ -156,17 +150,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/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->uploaderFile->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

0 comments on commit f26030b

Please sign in to comment.