Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Admin_EditorTemplatesController_add #3338

Merged
merged 11 commits into from
May 24, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function index(EditorTemplatesServiceInterface $service)
* @param EditorTemplatesService $service
* @checked
* @noTodo
* @UnitTest
*/
public function add(EditorTemplatesServiceInterface $service)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace BcEditorTemplate\Test\TestCase\Controller\Admin;

use BaserCore\Service\SiteConfigsServiceInterface;
use BaserCore\Test\Factory\SiteConfigFactory;
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
Expand Down Expand Up @@ -112,6 +114,31 @@ public function testAfterAddEvent()
$this->assertEquals(1, $query->count());
}

/**
* Test add
*/
public function testAdmin_add()
{
$this->enableSecurityToken();
$this->enableCsrfToken();

SiteConfigFactory::make(['name' => 'editor', 'value' => 'BaserCore.BcCkeditor'])->persist();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HungDV2022 @thangnnmd この行は無くてもテストは動きませんか?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryuring
#3338 (comment)
この行はなし場合は画像のようにエラーを発生しました。
確認お願いします。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HungDV2022 そのエラーが出る方が問題のような気がしますね。一度調べてみます。

Copy link
Collaborator

@ryuring ryuring May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HungDV2022 @thangnnmd 調べました。本体に問題がありました。
plugins/bc-editor-template/src/Controller/Admin/EditorTemplatesController.php を次のように修正してください。

76行目、119行目に return を追加

return $this->redirect(['action' => 'index']);

87行目、130行目を削除(なくてもブラウザで正常に動作しました)

$this->viewBuilder()->addHelper(BcSiteConfig::get('editor'));

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そうすると SiteConfigFactory は不要になります。


//正常系実行
$this->post('/baser/admin/bc-editor-template/editor_templates/add', ['name' => 'test', 'description' => 'test description']);
$this->assertResponseCode(302);
$this->assertFlashMessage('テンプレート「test」を追加しました');
$this->assertRedirect(['action' => 'index']);

//異常系実行
$this->post('/baser/admin/bc-editor-template/editor_templates/add', ['name' => '']);
$this->assertResponseCode(200);

//エラーメッセージを確認
$vars = $this->_controller->viewBuilder()->getVars();
$this->assertEquals(['name' => ['_empty' => "テンプレート名を入力してください。"]], $vars['editorTemplate']->getErrors());
}

/**
* Test beforeAddEvent
*/
Expand Down
Loading