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

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

Merged
merged 11 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 @@ -24,9 +24,9 @@
<!-- <testsuite name="BcEditorTemplate">-->
<!-- <directory>plugins/bc-editor-template/tests/TestCase</directory>-->
<!-- </testsuite>-->
<!-- <testsuite name="BcFavorite">-->
<!-- <directory>plugins/bc-favorite/tests/TestCase</directory>-->
<!-- </testsuite>-->
<testsuite name="BcFavorite">
<directory>plugins/bc-favorite/tests/TestCase</directory>
</testsuite>
<testsuite name="BcInstaller">
<directory>plugins/bc-installer/tests/TestCase</directory>
</testsuite>
Expand Down
13 changes: 12 additions & 1 deletion plugins/baser-core/config/Seeds/PluginsSeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,18 @@ public function run(): void
'priority' => '2',
'created' => NULL,
'modified' => NULL,
]
],
ryuring marked this conversation as resolved.
Show resolved Hide resolved
[
'id' => '6',
'name' => 'BcFavorite',
'title' => 'お気に入り',
'version' => '2.0.0',
'status' => '1',
'db_init' => '1',
'priority' => '2',
'created' => NULL,
'modified' => NULL,
],
];

$table = $this->table('plugins');
Expand Down
51 changes: 51 additions & 0 deletions plugins/bc-favorite/tests/Factory/FavoriteFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);

/**
* baserCMS : Based Website Development Project <https://basercms.net>
* Copyright (c) NPO baser foundation <https://baserfoundation.org/>
*
* @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()
];
});
}

}
85 changes: 0 additions & 85 deletions plugins/bc-favorite/tests/Fixture/FavoritesFixture.php

This file was deleted.

71 changes: 71 additions & 0 deletions plugins/bc-favorite/tests/Scenario/FavoritesScenario.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* baserCMS : Based Website Development Project <https://basercms.net>
* Copyright (c) NPO baser foundation <https://baserfoundation.org/>
*
* @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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'];
Expand All @@ -68,13 +58,15 @@ public function setUp(): void
public function tearDown(): void
{
parent::tearDown();
$this->truncateTable('favorites');
}

/**
* test View
*/
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());
Expand All @@ -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());
Expand Down Expand Up @@ -142,6 +135,7 @@ public function testEdit()
{
$this->enableSecurityToken();
$this->enableCsrfToken();
$this->loadFixtureScenario(FavoritesScenario::class);
$data = [
'name' => 'Test_test_Man'
];
Expand All @@ -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());
}

Expand Down Expand Up @@ -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
Expand Down
Loading