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

BcEditorTemplateを全体テストの実行対象に追加する #2820

Merged
merged 13 commits into from
Nov 2, 2023
6 changes: 3 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<!-- <testsuite name="BcCustomContent">-->
<!-- <directory>plugins/bc-custom-content/tests/TestCase</directory>-->
<!-- </testsuite>-->
<!-- <testsuite name="BcEditorTemplate">-->
<!-- <directory>plugins/bc-editor-template/tests/TestCase</directory>-->
<!-- </testsuite>-->
<testsuite name="BcEditorTemplate">
<directory>plugins/bc-editor-template/tests/TestCase</directory>
</testsuite>
<!-- <testsuite name="BcFavorite">-->
<!-- <directory>plugins/bc-favorite/tests/TestCase</directory>-->
<!-- </testsuite>-->
Expand Down
121 changes: 121 additions & 0 deletions plugins/baser-core/config/Seeds/PluginsSeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,127 @@ public function run(): void
'priority' => '2',
'created' => NULL,
'modified' => NULL,
],
[
ryuring marked this conversation as resolved.
Show resolved Hide resolved
'id' => '3',
'name' => 'BcContentLink',
'title' => 'BcContentLink',
'version' => '2.0.0',
'status' => '1',
'db_init' => '1',
'priority' => '3',
'created' => NULL,
'modified' => NULL,
],
[
'id' => '4',
'name' => 'BcCustomContent',
'title' => 'BcCustomContent',
'version' => '2.0.0',
'status' => '1',
'db_init' => '1',
'priority' => '4',
'created' => NULL,
'modified' => NULL,
],
[
'id' => '5',
'name' => 'BcEditorTemplate',
'title' => 'BcEditorTemplate',
'version' => '2.0.0',
'status' => '1',
'db_init' => '1',
'priority' => '5',
'created' => NULL,
'modified' => NULL,
],
[
'id' => '6',
'name' => 'BcFavorite',
'title' => 'BcFavorite',
'version' => '2.0.0',
'status' => '1',
'db_init' => '1',
'priority' => '6',
'created' => NULL,
'modified' => NULL,
],
[
'id' => '7',
'name' => 'BcInstaller',
'title' => 'BcInstaller',
'version' => '2.0.0',
'status' => '1',
'db_init' => '1',
'priority' => '7',
'created' => NULL,
'modified' => NULL,
],
[
'id' => '8',
'name' => 'BcMail',
'title' => 'BcMail',
'version' => '2.0.0',
'status' => '1',
'db_init' => '1',
'priority' => '8',
'created' => NULL,
'modified' => NULL,
],
[
'id' => '9',
'name' => 'BcSearchIndex',
'title' => 'BcSearchIndex',
'version' => '2.0.0',
'status' => '1',
'db_init' => '1',
'priority' => '9',
'created' => NULL,
'modified' => NULL,
],
[
'id' => '10',
'name' => 'BcThemeConfig',
'title' => 'BcThemeConfig',
'version' => '2.0.0',
'status' => '1',
'db_init' => '1',
'priority' => '10',
'created' => NULL,
'modified' => NULL,
],
[
'id' => '11',
'name' => 'BcThemeFile',
'title' => 'BcThemeFile',
'version' => '2.0.0',
'status' => '1',
'db_init' => '1',
'priority' => '11',
'created' => NULL,
'modified' => NULL,
],
[
'id' => '12',
'name' => 'BcUploader',
'title' => 'BcUploader',
'version' => '2.0.0',
'status' => '1',
'db_init' => '1',
'priority' => '12',
'created' => NULL,
'modified' => NULL,
],
[
'id' => '13',
'name' => 'BcWidgetArea',
'title' => 'BcWidgetArea',
'version' => '2.0.0',
'status' => '1',
'db_init' => '1',
'priority' => '13',
'created' => NULL,
'modified' => NULL,
]
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

namespace BcCustomContent\Test\Scenario;

use BcCustomContent\Test\Factory\CustomFieldFactory;
use BcCustomContent\Test\Factory\CustomLinkFactory;
use BaserCore\Test\Factory\PluginFactory;
use BcCustomContent\Test\Factory\CustomTableFactory;
use CakephpFixtureFactories\Scenario\FixtureScenarioInterface;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EditorTemplatesScenario implements FixtureScenarioInterface
public function load(...$args)
{
EditorTemplateFactory::make([
'id' => '1',
'id' => '11',
'name' => '画像(左)とテキスト',
'image' => 'template1.gif',
'description' => '画像を左に配置し、その右にテキストを配置するブロックです。',
Expand All @@ -44,7 +44,7 @@ public function load(...$args)
'created' => '2015-01-27 12:56:52'
])->persist();
EditorTemplateFactory::make([
'id' => '2',
'id' => '12',
'name' => '画像(右)とテキスト',
'image' => 'template2.gif',
'description' => '画像を右に配置し、その左にテキストを配置するブロックです。',
Expand All @@ -61,7 +61,7 @@ public function load(...$args)
'created' => '2015-01-27 12:56:52'
])->persist();
EditorTemplateFactory::make([
'id' => '3',
'id' => '13',
'name' => 'テキスト2段組',
'image' => 'template3.gif',
'description' => 'テキストを左右に2段組するブロックです。',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
use BcEditorTemplate\Test\Scenario\EditorTemplatesScenario;
use Cake\Datasource\ConnectionManager;
use Cake\Event\Event;
Expand All @@ -30,6 +31,7 @@ class EditorTemplatesControllerTest extends BcTestCase
* ScenarioAwareTrait
*/
use ScenarioAwareTrait;
use BcContainerTrait;
use IntegrationTestTrait;

/**
Expand All @@ -51,6 +53,7 @@ public function setUp(): void
public function tearDown(): void
{
parent::tearDown();
$this->truncateTable('editor_templates');
}

/**
Expand Down Expand Up @@ -112,7 +115,7 @@ public function testBeforeEditEvent()
$data = [
'name' => 'japan'
];
$this->post('/baser/admin/bc-editor-template/editor_templates/edit/1', $data);
$this->post('/baser/admin/bc-editor-template/editor_templates/edit/11', $data);
$editorTemplates = $this->getTableLocator()->get('BcEditorTemplate.EditorTemplates');
$query = $editorTemplates->find()->where(['name' => 'beforeAdd']);
$this->assertEquals(1, $query->count());
Expand All @@ -135,7 +138,7 @@ public function testAfterEditEvent()
$data = [
'name' => 'japan2'
];
$this->post('/baser/admin/bc-editor-template/editor_templates/edit/1', $data);
$this->post('/baser/admin/bc-editor-template/editor_templates/edit/11', $data);
$editorTemplates = $this->getTableLocator()->get('BcEditorTemplate.EditorTemplates');
$query = $editorTemplates->find()->where(['name' => 'afterAdd']);
$this->assertEquals(1, $query->count());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
use BcEditorTemplate\Test\Scenario\EditorTemplatesScenario;
use Cake\TestSuite\IntegrationTestTrait;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;
Expand All @@ -27,6 +28,7 @@ class EditorTemplatesControllerTest extends BcTestCase
* ScenarioAwareTrait
*/
use ScenarioAwareTrait;
use BcContainerTrait;
use IntegrationTestTrait;

/**
Expand Down Expand Up @@ -60,6 +62,7 @@ public function setUp(): void
public function tearDown(): void
{
parent::tearDown();
$this->truncateTable('editor_templates');
}

/**
Expand All @@ -83,7 +86,7 @@ public function test_view()
{
//データを生成
$this->loadFixtureScenario(EditorTemplatesScenario::class);
$this->get('/baser/api/admin/bc-editor-template/editor_templates/view/1.json?token=' . $this->accessToken);
$this->get('/baser/api/admin/bc-editor-template/editor_templates/view/11.json?token=' . $this->accessToken);
//ステータスを確認
$this->assertResponseOk();
//戻る値を確認
Expand Down Expand Up @@ -135,7 +138,7 @@ public function test_add()
public function test_edit()
{
$this->loadFixtureScenario(EditorTemplatesScenario::class);
$this->post('/baser/api/admin/bc-editor-template/editor_templates/edit/1.json?token=' . $this->accessToken, ['name' => 'name edit']);
$this->post('/baser/api/admin/bc-editor-template/editor_templates/edit/11.json?token=' . $this->accessToken, ['name' => 'name edit']);
//ステータスを確認
$this->assertResponseOk();
//戻る値を確認
Expand All @@ -152,7 +155,7 @@ public function test_edit()
$this->assertEquals('データが見つかりません。', $result->message);

//無効なIDを指定した場合、
$this->post('/baser/api/admin/bc-editor-template/editor_templates/edit/1.json?token=' . $this->accessToken, ['name' => '']);
$this->post('/baser/api/admin/bc-editor-template/editor_templates/edit/11.json?token=' . $this->accessToken, ['name' => '']);
//ステータスを確認
$this->assertResponseCode(400);
//戻る値を確認
Expand All @@ -168,7 +171,7 @@ public function test_delete()
{
//データを生成
$this->loadFixtureScenario(EditorTemplatesScenario::class);
$this->post('/baser/api/admin/bc-editor-template/editor_templates/delete/1.json?token=' . $this->accessToken);
$this->post('/baser/api/admin/bc-editor-template/editor_templates/delete/11.json?token=' . $this->accessToken);
//ステータスを確認
$this->assertResponseOk();
//戻る値を確認
Expand Down Expand Up @@ -198,6 +201,6 @@ public function test_list()
$this->assertResponseOk();
//戻る値を確認
$result = json_decode((string)$this->_response->getBody());
$this->assertEquals(get_object_vars($result->editorTemplates)[3], 'テキスト2段組');
$this->assertEquals(get_object_vars($result->editorTemplates)[13], 'テキスト2段組');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
namespace BcEditorTemplate\Test\TestCase\Service;

use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
use BcEditorTemplate\Service\EditorTemplatesService;
use BcEditorTemplate\Test\Scenario\EditorTemplatesScenario;
use Cake\TestSuite\IntegrationTestTrait;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
Expand All @@ -26,6 +28,8 @@ class EditorTemplatesServiceTest extends BcTestCase
* ScenarioAwareTrait
*/
use ScenarioAwareTrait;
use BcContainerTrait;
use IntegrationTestTrait;

/**
* set up
Expand All @@ -43,6 +47,7 @@ public function tearDown(): void
{
unset($this->EditorTemplatesService);
parent::tearDown();
$this->truncateTable('editor_templates');
}

/**
Expand All @@ -58,7 +63,7 @@ public function testConstruct()
*/
public function testGetNew()
{
$this->assertEquals($this->EditorTemplatesService->getNew()->toArray(), []);
$this->assertEquals($this->EditorTemplatesService->getNew()->toArray(), ['_bc_upload_id' => 1]);
}

/**
Expand All @@ -70,10 +75,10 @@ public function testGet()
$this->loadFixtureScenario(EditorTemplatesScenario::class);

//Getサービスをコル
$rs = $this->EditorTemplatesService->get(1);
$rs = $this->EditorTemplatesService->get(11);

//戻る値を確認
$this->assertEquals(1, $rs->id);
$this->assertEquals(11, $rs->id);
$this->assertEquals('画像(左)とテキスト', $rs->name);
}

Expand All @@ -90,7 +95,7 @@ public function testGetIndex()

//戻る値を確認
$this->assertEquals(3, $rs->count());
$this->assertEquals(1, $rs->all()->toArray()[0]->id);
$this->assertEquals(11, $rs->all()->toArray()[0]->id);
$this->assertEquals('画像(左)とテキスト', $rs->all()->toArray()[0]->name);
}

Expand All @@ -105,9 +110,9 @@ public function testGetList()
$rs = $this->EditorTemplatesService->getList();
//期待値
$expect = [
1 => '画像(左)とテキスト',
2 => '画像(右)とテキスト',
3 => 'テキスト2段組',
11 => '画像(左)とテキスト',
12 => '画像(右)とテキスト',
13 => 'テキスト2段組',
];
//期待値を戻るかどうか確認
$this->assertEquals($expect, $rs);
Expand Down Expand Up @@ -140,15 +145,15 @@ public function testUpdate()
//データを生成
$this->loadFixtureScenario(EditorTemplatesScenario::class);
//対象メソッドをコル
$rs = $this->EditorTemplatesService->update($this->EditorTemplatesService->get(1), ['name' => 'edited']);
$rs = $this->EditorTemplatesService->update($this->EditorTemplatesService->get(11), ['name' => 'edited']);
//エディターテンプレートの名前が変更されるか確認
$this->assertEquals('edited', $rs->name);

//異常テスト場合、
$this->expectException('Cake\ORM\Exception\PersistenceFailedException');
$this->expectExceptionMessage('Entity save failure. Found the following errors (name.maxLength: "テンプレート名は50文字以内で入力してください。');
$data['name'] = str_repeat('a', 51);
$this->EditorTemplatesService->update($this->EditorTemplatesService->get(1), $data);
$this->EditorTemplatesService->update($this->EditorTemplatesService->get(11), $data);
}

/**
Expand All @@ -159,13 +164,13 @@ public function testDelete()
//データを生成
$this->loadFixtureScenario(EditorTemplatesScenario::class);
//対象メソッドをコル
$rs = $this->EditorTemplatesService->delete(1);
$rs = $this->EditorTemplatesService->delete(11);
//戻り値を確認
$this->assertTrue($rs);

//削除したエディターテンプレートが存在しないか確認すること
$this->expectException("Cake\Datasource\Exception\RecordNotFoundException");
$this->EditorTemplatesService->get(1);
$this->EditorTemplatesService->get(11);
}

}
Loading