Skip to content

Commit

Permalink
add unitTest_UploaderCategoriesController_add
Browse files Browse the repository at this point in the history
  • Loading branch information
thangnn committed May 13, 2024
1 parent cdc17ed commit a408b8d
Showing 1 changed file with 12 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,39 +148,26 @@ public function testAfterEditEvent()
* test add
* @return void
*/
public function testAdd()
{
public function test_add(){
$this->enableSecurityToken();
$this->enableCsrfToken();

$this->get('/baser/admin/bc-uploader/uploader_categories/add');
$this->assertResponseOk();

$this->post('/baser/admin/bc-uploader/uploader_categories/add', [
'name' => 'uploader add test',
]);

//Redirect url
//正常系実行
$data = [
'name' => 'japan'
];
$this->post('/baser/admin/bc-uploader/uploader_categories/add', $data);
$this->assertResponseCode(302);
$this->assertRedirect(['action' => 'index']);

//check message
$this->assertFlashMessage('アップロードカテゴリ「uploader add test」を追加しました。');

//get data after when add and compare data
$uploads = $this->getTableLocator()->get('BcUploader.UploaderCategories');
$item = $uploads->find()->where([
'name' => 'uploader add test',
])->first();
$this->assertEquals($item['name'], 'uploader add test');
$this->assertFlashMessage('アップロードカテゴリ「japan」を追加しました。');
$this->assertRedirect('/baser/admin/bc-uploader/uploader_categories/index');

//異常系実行
$data = [
'name' => null
'name' => ''
];
$this->post('/baser/admin/bc-uploader/uploader_categories/add', $data);
//check message
$vars = $this->_controller->viewBuilder()->getVars();
$this->assertEquals(['name' => ['_empty' => "カテゴリ名を入力してください。"]], $vars['uploaderCategory']->getErrors());
$this->assertResponseCode(200);
$errors = $this->_controller->viewBuilder()->getVars()['uploaderCategory']->getErrors();
$this->assertEquals(['_empty' => 'カテゴリ名を入力してください。'], $errors['name']);
}
}

0 comments on commit a408b8d

Please sign in to comment.