diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0bff8adc2e..01c0e2d509 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -21,12 +21,12 @@ - - - - - - + + plugins/bc-editor-template/tests/TestCase + + + plugins/bc-favorite/tests/TestCase + plugins/bc-installer/tests/TestCase @@ -39,9 +39,9 @@ plugins/bc-theme-config/tests/TestCase - - - + + plugins/bc-theme-file/tests/TestCase + diff --git a/plugins/bc-custom-content/tests/Scenario/CustomTablesScenario.php b/plugins/bc-custom-content/tests/Scenario/CustomTablesScenario.php index 138d55954d..d64bf6f91c 100644 --- a/plugins/bc-custom-content/tests/Scenario/CustomTablesScenario.php +++ b/plugins/bc-custom-content/tests/Scenario/CustomTablesScenario.php @@ -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; diff --git a/plugins/bc-editor-template/tests/Scenario/EditorTemplatesScenario.php b/plugins/bc-editor-template/tests/Scenario/EditorTemplatesScenario.php index d768c12378..e3ac72004e 100644 --- a/plugins/bc-editor-template/tests/Scenario/EditorTemplatesScenario.php +++ b/plugins/bc-editor-template/tests/Scenario/EditorTemplatesScenario.php @@ -27,7 +27,7 @@ class EditorTemplatesScenario implements FixtureScenarioInterface public function load(...$args) { EditorTemplateFactory::make([ - 'id' => '1', + 'id' => '11', 'name' => '画像(左)とテキスト', 'image' => 'template1.gif', 'description' => '画像を左に配置し、その右にテキストを配置するブロックです。', @@ -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' => '画像を右に配置し、その左にテキストを配置するブロックです。', @@ -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段組するブロックです。', diff --git a/plugins/bc-editor-template/tests/TestCase/Controller/Admin/EditorTemplatesControllerTest.php b/plugins/bc-editor-template/tests/TestCase/Controller/Admin/EditorTemplatesControllerTest.php index 1a040d7ed3..353e11da69 100644 --- a/plugins/bc-editor-template/tests/TestCase/Controller/Admin/EditorTemplatesControllerTest.php +++ b/plugins/bc-editor-template/tests/TestCase/Controller/Admin/EditorTemplatesControllerTest.php @@ -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; @@ -30,6 +31,7 @@ class EditorTemplatesControllerTest extends BcTestCase * ScenarioAwareTrait */ use ScenarioAwareTrait; + use BcContainerTrait; use IntegrationTestTrait; /** @@ -51,6 +53,7 @@ public function setUp(): void public function tearDown(): void { parent::tearDown(); + $this->truncateTable('editor_templates'); } /** @@ -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()); @@ -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()); diff --git a/plugins/bc-editor-template/tests/TestCase/Controller/Api/Admin/EditorTemplatesControllerTest.php b/plugins/bc-editor-template/tests/TestCase/Controller/Api/Admin/EditorTemplatesControllerTest.php index 7376ca2694..5beb046bc5 100644 --- a/plugins/bc-editor-template/tests/TestCase/Controller/Api/Admin/EditorTemplatesControllerTest.php +++ b/plugins/bc-editor-template/tests/TestCase/Controller/Api/Admin/EditorTemplatesControllerTest.php @@ -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; @@ -27,6 +28,7 @@ class EditorTemplatesControllerTest extends BcTestCase * ScenarioAwareTrait */ use ScenarioAwareTrait; + use BcContainerTrait; use IntegrationTestTrait; /** @@ -60,6 +62,7 @@ public function setUp(): void public function tearDown(): void { parent::tearDown(); + $this->truncateTable('editor_templates'); } /** @@ -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(); //戻る値を確認 @@ -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(); //戻る値を確認 @@ -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); //戻る値を確認 @@ -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(); //戻る値を確認 @@ -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段組'); } } diff --git a/plugins/bc-editor-template/tests/TestCase/Service/EditorTemplatesServiceTest.php b/plugins/bc-editor-template/tests/TestCase/Service/EditorTemplatesServiceTest.php index 998eca259d..c40a059b07 100644 --- a/plugins/bc-editor-template/tests/TestCase/Service/EditorTemplatesServiceTest.php +++ b/plugins/bc-editor-template/tests/TestCase/Service/EditorTemplatesServiceTest.php @@ -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; /** @@ -26,6 +28,8 @@ class EditorTemplatesServiceTest extends BcTestCase * ScenarioAwareTrait */ use ScenarioAwareTrait; + use BcContainerTrait; + use IntegrationTestTrait; /** * set up @@ -43,6 +47,7 @@ public function tearDown(): void { unset($this->EditorTemplatesService); parent::tearDown(); + $this->truncateTable('editor_templates'); } /** @@ -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]); } /** @@ -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); } @@ -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); } @@ -105,9 +110,9 @@ public function testGetList() $rs = $this->EditorTemplatesService->getList(); //期待値 $expect = [ - 1 => '画像(左)とテキスト', - 2 => '画像(右)とテキスト', - 3 => 'テキスト2段組', + 11 => '画像(左)とテキスト', + 12 => '画像(右)とテキスト', + 13 => 'テキスト2段組', ]; //期待値を戻るかどうか確認 $this->assertEquals($expect, $rs); @@ -140,7 +145,7 @@ 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); @@ -148,7 +153,7 @@ public function testUpdate() $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); } /** @@ -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); } } diff --git a/plugins/bc-favorite/tests/Factory/FavoriteFactory.php b/plugins/bc-favorite/tests/Factory/FavoriteFactory.php new file mode 100644 index 0000000000..c9cd669250 --- /dev/null +++ b/plugins/bc-favorite/tests/Factory/FavoriteFactory.php @@ -0,0 +1,51 @@ + + * Copyright (c) NPO baser foundation + * + * @copyright Copyright (c) NPO baser foundation + * @link https://basercms.net baserCMS Project + * @since 5.0.0 + * @license https://basercms.net/license/index.html MIT License + */ + +namespace BcFavorite\Test\Factory; + +use CakephpFixtureFactories\Factory\BaseFactory as CakephpBaseFactory; +use Faker\Generator; + +/** + * BlogCategoryFactory + */ +class FavoriteFactory extends CakephpBaseFactory +{ + + /** + * Defines the Table Registry used to generate entities with + * + * @return string + */ + protected function getRootTableRegistryName(): string + { + return 'BcFavorite.Favorites'; + } + + /** + * Defines the factory's default values. This is useful for + * not nullable fields. You may use methods of the present factory here too. + * + * @return void + */ + protected function setDefaultTemplate(): void + { + $this->setDefaultData(function (Generator $faker) { + return [ + 'created' => $faker->date(), + 'modified' => $faker->date() + ]; + }); + } + +} diff --git a/plugins/bc-favorite/tests/Fixture/FavoritesFixture.php b/plugins/bc-favorite/tests/Fixture/FavoritesFixture.php deleted file mode 100644 index e7d216f407..0000000000 --- a/plugins/bc-favorite/tests/Fixture/FavoritesFixture.php +++ /dev/null @@ -1,85 +0,0 @@ - 'favorites']; - - /** - * Init method - * - * @return void - */ - public function init(): void - { - $this->records = [ - [ - 'id' => '1', - 'user_id' => '1', - 'name' => '固定ページ管理', - 'url' => '/admin/pages/index', - 'sort' => '1', - 'created' => '2015-01-27 12:57:59', - 'modified' => '2015-01-27 12:57:59' - ], - [ - 'id' => '2', - 'user_id' => '1', - 'name' => '新着情報管理', - 'url' => '/admin/blog/blog_posts/index/1', - 'sort' => '2', - 'created' => '2015-01-27 12:57:59', - 'modified' => '2015-01-27 12:57:59' - ], - [ - 'id' => '3', - 'user_id' => '1', - 'name' => 'お問い合わせ管理', - 'url' => '/admin/mail/mail_fields/index/1', - 'sort' => '3', - 'created' => '2015-01-27 12:57:59', - 'modified' => '2015-01-27 12:57:59' - ], - [ - 'id' => '4', - 'user_id' => '1', - 'name' => '受信メール一覧', - 'url' => '/admin/mail/mail_messages/index/1', - 'sort' => '4', - 'created' => '2015-01-27 12:57:59', - 'modified' => '2015-01-27 12:57:59' - ], - [ - 'id' => '5', - 'user_id' => '1', - 'name' => 'コメント一覧', - 'url' => '/admin/blog/blog_comments/index/1', - 'sort' => '5', - 'created' => '2015-01-27 12:57:59', - 'modified' => '2015-01-27 12:57:59' - ], - [ - 'id' => '6', - 'user_id' => '1', - 'name' => 'クレジット', - 'url' => 'javascript:credit();', - 'sort' => '6', - 'created' => '2015-01-27 12:57:59', - 'modified' => '2015-01-27 12:57:59' - ], - ]; - parent::init(); - } -} diff --git a/plugins/bc-favorite/tests/Scenario/FavoritesScenario.php b/plugins/bc-favorite/tests/Scenario/FavoritesScenario.php new file mode 100644 index 0000000000..851ab5794b --- /dev/null +++ b/plugins/bc-favorite/tests/Scenario/FavoritesScenario.php @@ -0,0 +1,71 @@ + + * Copyright (c) NPO baser foundation + * + * @copyright Copyright (c) NPO baser foundation + * @link https://basercms.net baserCMS Project + * @since 5.0.0 + * @license https://basercms.net/license/index.html MIT License + */ + +namespace BcFavorite\Test\Scenario; + +use BcFavorite\Test\Factory\FavoriteFactory; +use CakephpFixtureFactories\Scenario\FixtureScenarioInterface; + +/** + * FavoritesScenario + */ +class FavoritesScenario implements FixtureScenarioInterface +{ + + /** + * load + */ + public function load(...$args) + { + FavoriteFactory::make([ + 'id' => 1, + 'user_id' => '1', + 'name' => '固定ページ管理', + 'url' => '/admin/pages/index', + 'sort' => 1, + ])->persist(); + FavoriteFactory::make([ + 'id' => 2, + 'user_id' => '1', + 'name' => '新着情報管理', + 'url' => '/admin/blog/blog_posts/index/1', + 'sort' => 2, + ])->persist(); + FavoriteFactory::make([ + 'id' => 3, + 'user_id' => '1', + 'name' => 'お問い合わせ管理', + 'url' => '/admin/mail/mail_fields/index/1', + 'sort' => 3, + ])->persist(); + FavoriteFactory::make([ + 'id' => 4, + 'user_id' => '1', + 'name' => '受信メール一覧', + 'url' => '/admin/mail/mail_messages/index/1', + 'sort' => 4, + ])->persist(); + FavoriteFactory::make([ + 'id' => 5, + 'user_id' => '1', + 'name' => 'コメント一覧', + 'url' => '/admin/blog/blog_comments/index/1', + 'sort' => 5, + ])->persist(); + FavoriteFactory::make([ + 'id' => 6, + 'user_id' => '1', + 'name' => 'クレジット', + 'url' => 'javascript:credit();', + 'sort' => 6, + ])->persist(); + } +} diff --git a/plugins/bc-favorite/tests/TestCase/Controller/Api/Admin/FavoritesControllerTest.php b/plugins/bc-favorite/tests/TestCase/Controller/Api/Admin/FavoritesControllerTest.php index 9f21454538..c3c32e1e8b 100644 --- a/plugins/bc-favorite/tests/TestCase/Controller/Api/Admin/FavoritesControllerTest.php +++ b/plugins/bc-favorite/tests/TestCase/Controller/Api/Admin/FavoritesControllerTest.php @@ -11,31 +11,20 @@ namespace BcFavorite\Test\TestCase\Controller\Api\Admin; +use BaserCore\Test\Scenario\InitAppScenario; +use BcFavorite\Test\Scenario\FavoritesScenario; use Cake\TestSuite\IntegrationTestTrait; +use BaserCore\TestSuite\BcTestCase; +use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; -class FavoritesControllerTest extends \BaserCore\TestSuite\BcTestCase +class FavoritesControllerTest extends BcTestCase { /** * IntegrationTestTrait */ use IntegrationTestTrait; - - /** - * Fixtures - * - * @var array - */ - public $fixtures = [ - 'plugin.BaserCore.Plugins', - 'plugin.BaserCore.Users', - 'plugin.BaserCore.UsersUserGroups', - 'plugin.BaserCore.UserGroups', - 'plugin.BcFavorite.Favorites', - 'plugin.BaserCore.Sites', - 'plugin.BaserCore.Contents', - 'plugin.BaserCore.Permissions', - ]; + use ScenarioAwareTrait; /** * Access Token @@ -55,6 +44,7 @@ class FavoritesControllerTest extends \BaserCore\TestSuite\BcTestCase public function setUp(): void { parent::setUp(); + $this->loadFixtureScenario(InitAppScenario::class); $token = $this->apiLoginAdmin(1); $this->accessToken = $token['access_token']; $this->refreshToken = $token['refresh_token']; @@ -68,6 +58,7 @@ public function setUp(): void public function tearDown(): void { parent::tearDown(); + $this->truncateTable('favorites'); } /** @@ -75,6 +66,7 @@ public function tearDown(): void */ public function testView(): void { + $this->loadFixtureScenario(FavoritesScenario::class); $this->get('/baser/api/admin/bc-favorite/favorites/view/2.json?token=' . $this->accessToken); $this->assertResponseOk(); $result = json_decode((string)$this->_response->getBody()); @@ -88,6 +80,7 @@ public function testView(): void */ public function testIndex() { + $this->loadFixtureScenario(FavoritesScenario::class); $this->get('/baser/api/admin/bc-favorite/favorites/index.json?token=' . $this->accessToken); $this->assertResponseOk(); $result = json_decode((string)$this->_response->getBody()); @@ -142,6 +135,7 @@ public function testEdit() { $this->enableSecurityToken(); $this->enableCsrfToken(); + $this->loadFixtureScenario(FavoritesScenario::class); $data = [ 'name' => 'Test_test_Man' ]; @@ -161,10 +155,11 @@ public function testDelete() { $this->enableSecurityToken(); $this->enableCsrfToken(); - $this->post('/baser/api/admin/bc-favorite/favorites/delete/2.json?token=' . $this->accessToken); + $this->loadFixtureScenario(FavoritesScenario::class); + $this->post('/baser/api/admin/bc-favorite/favorites/delete/1.json?token=' . $this->accessToken); $this->assertResponseSuccess(); $favorites = $this->getTableLocator()->get('BcFavorite.Favorites'); - $query = $favorites->find()->where(['id' => 2]); + $query = $favorites->find()->where(['id' => 1]); $this->assertEquals(0, $query->count()); } @@ -221,6 +216,7 @@ public function testAdmin_ajax_delete() */ public function testAdmin_update_sort() { + $this->loadFixtureScenario(FavoritesScenario::class); $this->post('/baser/api/admin/bc-favorite/favorites/change_sort.json?token=' . $this->accessToken, [ 'id' => 1, 'offset' => 1 diff --git a/plugins/bc-favorite/tests/TestCase/Model/Table/FavoritesTableTest.php b/plugins/bc-favorite/tests/TestCase/Model/Table/FavoritesTableTest.php index 72131c7c7f..63f05cae73 100644 --- a/plugins/bc-favorite/tests/TestCase/Model/Table/FavoritesTableTest.php +++ b/plugins/bc-favorite/tests/TestCase/Model/Table/FavoritesTableTest.php @@ -11,9 +11,12 @@ namespace BcFavorite\Test\TestCase\Model\Table; +use BaserCore\Test\Scenario\InitAppScenario; use BaserCore\TestSuite\BcTestCase; -use BcFavorite\Model\Table\FavoritesTable; use BaserCore\Utility\BcUtil; +use BcFavorite\Test\Scenario\FavoritesScenario; +use Cake\TestSuite\IntegrationTestTrait; +use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; /** * Class FavoriteTableTest @@ -22,20 +25,10 @@ class FavoritesTableTest extends BcTestCase { /** - * Fixtures - * - * @var array + * IntegrationTestTrait */ - protected $fixtures = [ - 'plugin.BaserCore.Users', - 'plugin.BaserCore.UsersUserGroups', - 'plugin.BaserCore.UserGroups', - 'plugin.BaserCore.Permissions', - 'plugin.BaserCore.Plugins', - 'plugin.BaserCore.Sites', - 'plugin.BaserCore.Contents', - 'plugin.BcFavorite.Favorites', - ]; + use IntegrationTestTrait; + use ScenarioAwareTrait; /** * @var Favorites @@ -77,6 +70,7 @@ public function tearDown(): void */ public function testInitialize() { + $this->loadFixtureScenario(InitAppScenario::class); $this->loginAdmin($this->getRequest('/baser/admin')); $this->assertEquals('favorites', $this->Favorites->getTable()); $this->assertEquals('name', $this->Favorites->getDisplayField()); @@ -93,7 +87,8 @@ public function testInitialize() */ public function testValidationDefault($fields, $messages): void { - $this->loginAdmin($this->getRequest('/baser/admin'), 2); + $this->loadFixtureScenario(InitAppScenario::class); + $this->loginAdmin($this->getRequest('/baser/admin')); $favorite = $this->Favorites->newEntity($fields); $this->assertSame($messages, $favorite->getErrors()); } @@ -105,13 +100,6 @@ public function validationDefaultDataProvider() ['name' => ''], ['name' => ['_empty' => 'タイトルは必須です。']] ], - [ - ['url' => 1], - [ - 'name' => ['_required' => 'タイトルは必須です。'], - 'url' => ['isPermitted' => 'このURLの登録は許可されていません。'] - ] - ], [ ['name' => 'hoge', 'url' => '/baser/admin/favorites/add'], [] diff --git a/plugins/bc-favorite/tests/TestCase/Model/Validation/FavoriteValidationTest.php b/plugins/bc-favorite/tests/TestCase/Model/Validation/FavoriteValidationTest.php index 6640cde76a..93027dcca7 100644 --- a/plugins/bc-favorite/tests/TestCase/Model/Validation/FavoriteValidationTest.php +++ b/plugins/bc-favorite/tests/TestCase/Model/Validation/FavoriteValidationTest.php @@ -12,9 +12,12 @@ namespace BcFavorite\Test\TestCase\Model\Validation; use BaserCore\Service\PermissionServiceInterface; -use BaserCore\Utility\BcContainerTrait; +use BaserCore\Test\Scenario\InitAppScenario; use BcFavorite\Model\Validation\FavoriteValidation; use BaserCore\TestSuite\BcTestCase; +use BcFavorite\Test\Scenario\FavoritesScenario; +use Cake\TestSuite\IntegrationTestTrait; +use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; /** * Class FavoriteValidationTest @@ -24,22 +27,10 @@ class FavoriteValidationTest extends BcTestCase { /** - * Trait + * IntegrationTestTrait */ - use BcContainerTrait; - - /** - * Fixtures - * - * @var array - */ - protected $fixtures = [ - 'plugin.BaserCore.Users', - 'plugin.BaserCore.UsersUserGroups', - 'plugin.BaserCore.UserGroups', - 'plugin.BaserCore.Plugins', - 'plugin.BaserCore.Permissions', - ]; + use IntegrationTestTrait; + use ScenarioAwareTrait; /** * Test subject @@ -78,7 +69,8 @@ public function tearDown(): void */ public function testIsPermitted($isAdmin, $id, $url, $expected): void { - if($isAdmin) { + if ($isAdmin) { + $this->loadFixtureScenario(InitAppScenario::class); $this->loginAdmin($this->getRequest('/'), $id); } $this->assertEquals($expected, $this->FavoriteValidation->isPermitted($url)); @@ -88,8 +80,6 @@ public function isPermittedDataProvider() { return [ [true, 1, '/baser/admin/users/index', true], - [true, 2, '/baser/admin/users/index', false], - [true, 2, '/baser/admin/pages/index', true], [false, null, '/baser/admin/users/index', false], ]; } diff --git a/plugins/bc-favorite/tests/TestCase/Service/FavoritesServiceTest.php b/plugins/bc-favorite/tests/TestCase/Service/FavoritesServiceTest.php index 09a5b6faa1..891199ae43 100644 --- a/plugins/bc-favorite/tests/TestCase/Service/FavoritesServiceTest.php +++ b/plugins/bc-favorite/tests/TestCase/Service/FavoritesServiceTest.php @@ -11,9 +11,13 @@ namespace BcFavorite\Test\TestCase\Service; +use BaserCore\Test\Scenario\InitAppScenario; use BaserCore\Utility\BcUtil; use BaserCore\TestSuite\BcTestCase; use BcFavorite\Service\FavoritesService; +use BcFavorite\Test\Scenario\FavoritesScenario; +use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; +use Cake\TestSuite\IntegrationTestTrait; /** * Class FavoritesServiceTest @@ -23,16 +27,10 @@ class FavoritesServiceTest extends BcTestCase { /** - * Fixtures - * - * @var array + * IntegrationTestTrait */ - protected $fixtures = [ - 'plugin.BcFavorite.Favorites', - 'plugin.BaserCore.Users', - 'plugin.BaserCore.UsersUserGroups', - 'plugin.BaserCore.UserGroups', - ]; + use IntegrationTestTrait; + use ScenarioAwareTrait; /** * FavoritesService @@ -67,6 +65,7 @@ public function tearDown(): void { unset($this->FavoritesService); parent::tearDown(); + $this->truncateTable('favorites'); } /** @@ -76,6 +75,7 @@ public function tearDown(): void */ public function testGet(): void { + $this->loadFixtureScenario(FavoritesScenario::class); $result = $this->FavoritesService->get(1); $this->assertEquals("固定ページ管理", $result->name); @@ -90,6 +90,7 @@ public function testGet(): void */ public function testGetIndex(): void { + $this->loadFixtureScenario(FavoritesScenario::class); $result = $this->FavoritesService->getIndex(['num' => 2]); $this->assertEquals(2, $result->all()->count()); } @@ -112,6 +113,7 @@ public function testGetNew(): void */ public function testCreate(): void { + $this->loadFixtureScenario(InitAppScenario::class); $this->loginAdmin($this->getRequest()); $result = $this->FavoritesService->create([ 'user_id' => '1', @@ -127,6 +129,7 @@ public function testCreate(): void */ public function testUpdate(): void { + $this->loadFixtureScenario(FavoritesScenario::class); $favorite = $this->FavoritesService->get(1); $this->FavoritesService->update($favorite, [ 'name' => 'ucmitz', @@ -140,7 +143,8 @@ public function testUpdate(): void */ public function testDelete() { - $this->FavoritesService->delete(2); + $this->loadFixtureScenario(FavoritesScenario::class); + $this->FavoritesService->delete(1); $users = $this->FavoritesService->getIndex([]); $this->assertEquals(5, $users->all()->count()); } diff --git a/plugins/bc-theme-file/src/Controller/Admin/ThemeFilesController.php b/plugins/bc-theme-file/src/Controller/Admin/ThemeFilesController.php index 610295ee04..7c1ea78f79 100644 --- a/plugins/bc-theme-file/src/Controller/Admin/ThemeFilesController.php +++ b/plugins/bc-theme-file/src/Controller/Admin/ThemeFilesController.php @@ -203,7 +203,7 @@ public function edit(ThemeFilesAdminServiceInterface $service) $this->BcMessage->setInfo(sprintf(__d('baser_core', 'ファイル %s を更新しました。'), $themeFile->name)); $this->redirect(array_merge( [$args['theme'], $args['plugin'], $args['type']], - explode('/', dirname($args['path'])), + (str_contains($args['path'], '/'))? explode('/', dirname($args['path'])) : [], [$themeFile->name] )); } catch (BcFormFailedException $e) { @@ -242,7 +242,7 @@ public function delete(ThemeFilesAdminServiceInterface $service) $this->redirect(array_merge( ['action' => 'index', $args['theme'], $args['plugin'], $args['type']], - explode('/', dirname($args['path'])) + (str_contains($args['path'], '/'))? explode('/', dirname($args['path'])) : [] )); } @@ -270,7 +270,7 @@ public function delete_folder(ThemeFoldersAdminServiceInterface $service) $this->redirect(array_merge( ['action' => 'index', $args['theme'], $args['plugin'], $args['type']], - explode('/', dirname($args['path'])) + (str_contains($args['path'], '/'))? explode('/', dirname($args['path'])) : [] )); } @@ -316,7 +316,7 @@ public function copy(ThemeFilesAdminServiceInterface $service) $this->redirect(array_merge( ['action' => 'index', $args['theme'], $args['plugin'], $args['type']], - explode('/', dirname($args['path'])) + (str_contains($args['path'], '/'))? explode('/', dirname($args['path'])) : [] )); } @@ -343,7 +343,7 @@ public function copy_folder(ThemeFoldersAdminServiceInterface $service) $this->redirect(array_merge( ['action' => 'index', $args['theme'], $args['plugin'], $args['type']], - explode('/', dirname($args['path'])) + (str_contains($args['path'], '/'))? explode('/', dirname($args['path'])) : [] )); } diff --git a/plugins/bc-theme-file/tests/TestCase/Controller/Admin/ThemeFilesControllerTest.php b/plugins/bc-theme-file/tests/TestCase/Controller/Admin/ThemeFilesControllerTest.php index 94f2e6a109..3b0acc42ef 100644 --- a/plugins/bc-theme-file/tests/TestCase/Controller/Admin/ThemeFilesControllerTest.php +++ b/plugins/bc-theme-file/tests/TestCase/Controller/Admin/ThemeFilesControllerTest.php @@ -193,33 +193,29 @@ public function test_edit() { $this->enableSecurityToken(); $this->enableCsrfToken(); - $fullpath = BASER_PLUGINS . 'BcColumn' . '/layout/'; + $fullpath = BASER_PLUGINS . 'BcThemeSample/templates/layout/'; $file = new BcFile($fullpath . 'base_name_1.php'); $file->create(); //GETメソッドを検証場合 - $this->get('/baser/admin/bc-theme-file/theme_files/edit/BcColumn/layout/base_name_1.php'); + $this->get('/baser/admin/bc-theme-file/theme_files/edit/BcThemeSample/layout/base_name_1.php'); //取得データを確認 $pageTitle = $this->_controller->viewBuilder()->getVars()['pageTitle']; - $this->assertEquals('BcColumn|レイアウトテンプレート編集', $pageTitle); + $this->assertEquals('BcThemeSample|レイアウトテンプレート編集', $pageTitle); $postData = [ - 'fullpath' => '/var/www/html/plugins/BcColumn/layout/', - 'parent' => '/var/www/html/plugins/BcColumn/layout/', - 'theme' => 'BcColumn', - 'type' => 'layout', - 'path' => 'test.php', + 'fullpath' => $fullpath . 'base_name_1.php', + 'parent' => $fullpath, 'base_name' => 'base_name_2', - 'contents' => 'this is a content changed!', 'ext' => 'php', - 'plugin' => 'BaserCore' + 'contents' => "" ]; //Postメソッドを検証場合 - $this->post('/baser/admin/bc-theme-file/theme_files/edit/BcColumn/layout/base_name_1.php', $postData); + $this->post('/baser/admin/bc-theme-file/theme_files/edit/BcThemeSample/layout/base_name_1.php', $postData); //戻る値を確認 $this->assertResponseCode(302); $this->assertFlashMessage('ファイル base_name_2.php を更新しました。'); - $this->assertRedirect(['action' => 'edit/layout/base_name_2.php']); + $this->assertRedirect(['action' => 'edit/BcThemeSample/layout/base_name_2.php']); unlink($fullpath . 'base_name_2.php'); } @@ -239,7 +235,7 @@ public function test_delete() //戻る値を確認 $this->assertResponseCode(302); $this->assertFlashMessage('ファイル base_name_1.php を削除しました。'); - $this->assertRedirect('/baser/admin/bc-theme-file/theme_files/index/BcColumn/layout/'); + $this->assertRedirect('/baser/admin/bc-theme-file/theme_files/index/BcColumn/layout'); //実際にファイルが削除されいてるか確認すること $this->assertFalse(file_exists($fullpath . 'base_name_1.php')); } @@ -260,7 +256,7 @@ public function test_delete_folder() //戻る値を確認 $this->assertResponseCode(302); $this->assertFlashMessage('フォルダ delete_folder を削除しました。'); - $this->assertRedirect('/baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout/'); + $this->assertRedirect('/baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout'); //実際にフォルダが削除されいてるか確認すること $this->assertFalse(file_exists($fullpath . 'delete_folder')); } @@ -300,7 +296,7 @@ public function test_copy() //戻る値を確認 $this->assertResponseCode(302); $this->assertFlashMessage('ファイル default.php をコピーしました。'); - $this->assertRedirect('baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout/.'); + $this->assertRedirect('baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout'); unlink($fullpath . 'default_copy.php'); } @@ -321,7 +317,7 @@ public function test_copy_folder() //戻る値を確認 $this->assertResponseCode(302); $this->assertFlashMessage('フォルダ new_folder をコピーしました。'); - $this->assertRedirect('baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout/.'); + $this->assertRedirect('baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout'); //テスト後に不要なフォルダーを削除 $folder->delete(); @@ -364,7 +360,7 @@ public function test_upload() unlink($fullpath . 'uploadTestFile.html'); //エラーを発生した場合 - $this->assertRedirect('/baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout3'); + $this->post('/baser/admin/bc-theme-file/theme_files/index/BcThemeSample/layout3'); //ステータスを確認 $this->assertResponseCode(500); } diff --git a/plugins/bc-theme-file/tests/TestCase/Controller/Api/Admin/ThemeFoldersControllerTest.php b/plugins/bc-theme-file/tests/TestCase/Controller/Api/Admin/ThemeFoldersControllerTest.php index 2467784eff..8632e2a836 100644 --- a/plugins/bc-theme-file/tests/TestCase/Controller/Api/Admin/ThemeFoldersControllerTest.php +++ b/plugins/bc-theme-file/tests/TestCase/Controller/Api/Admin/ThemeFoldersControllerTest.php @@ -114,6 +114,7 @@ public function test_add() $fullpath = BASER_PLUGINS . 'BcThemeSample' . '/templates/layout/'; $data = [ 'theme' => 'BcThemeSample', + 'parent' => '/var/www/html/plugins/BcThemeSample/templates/layout/', 'plugin' => 'BaserCore', 'type' => 'layout', 'path' => '', @@ -146,6 +147,7 @@ public function test_edit() //Postデータを生成 $data = [ 'theme' => 'BcThemeSample', + 'parent' => '/var/www/html/plugins/BcThemeSample/templates/layout/', 'plugin' => 'BaserCore', 'type' => 'layout', 'path' => 'new_folder', @@ -180,6 +182,7 @@ public function test_delete() //Postデータを生成 $data = [ 'theme' => 'BcThemeSample', + 'parent' => '/var/www/html/plugins/BcThemeSample/templates/layout/', 'plugin' => 'BaserCore', 'type' => 'layout', 'path' => 'delete_folder', @@ -215,6 +218,7 @@ public function test_copy() //Postデータを生成 $data = [ 'theme' => 'BcThemeSample', + 'parent' => '/var/www/html/plugins/BcThemeSample/templates/layout/', 'plugin' => 'BaserCore', 'type' => 'layout', 'path' => 'new_folder', @@ -243,6 +247,7 @@ public function test_copy_to_theme() $fullpath = BASER_PLUGINS . '/BcPluginSample/templates/'; $data = [ 'theme' => 'BcFront', + 'parent' => '/var/www/html/plugins/BcThemeSample/templates/layout/', 'type' => 'Pages', 'path' => '', 'assets' => '', diff --git a/plugins/bc-theme-file/tests/TestCase/Service/ThemeFilesServiceTest.php b/plugins/bc-theme-file/tests/TestCase/Service/ThemeFilesServiceTest.php index cbbcd04084..2d459a3667 100644 --- a/plugins/bc-theme-file/tests/TestCase/Service/ThemeFilesServiceTest.php +++ b/plugins/bc-theme-file/tests/TestCase/Service/ThemeFilesServiceTest.php @@ -88,7 +88,6 @@ public function test_get() $this->assertEquals('php', $rs['ext']); $this->assertEquals('text', $rs['type']); $this->assertEquals(null, $rs['path']); - $this->assertTextContains('baserCMS : Based Website Development Project', $rs['contents']); } /** diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 6e7ad04708..ea7d2e57e7 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -95,7 +95,9 @@ (new Migrator())->runMany([ ['plugin' => 'BaserCore'], ['plugin' => 'BcBlog'], + ['plugin' => 'BcEditorTemplate'], ['plugin' => 'BcSearchIndex'], + ['plugin' => 'BcFavorite'], ['plugin' => 'BcContentLink'], ['plugin' => 'BcMail'], ['plugin' => 'BcWidgetArea'],