Skip to content

Commit

Permalink
BcEditorTemplateを全体テストの実行対象に追加する (#2820)
Browse files Browse the repository at this point in the history
Co-authored-by: Đỗ Văn Hùng <[email protected]>
Co-authored-by: ryuring <[email protected]>
  • Loading branch information
3 people authored Nov 2, 2023
1 parent 29248d2 commit a2f258e
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 26 deletions.
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
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);
}

}
1 change: 1 addition & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
(new Migrator())->runMany([
['plugin' => 'BaserCore'],
['plugin' => 'BcBlog'],
['plugin' => 'BcEditorTemplate'],
['plugin' => 'BcSearchIndex'],
['plugin' => 'BcFavorite'],
['plugin' => 'BcContentLink'],
Expand Down

0 comments on commit a2f258e

Please sign in to comment.