Skip to content

Commit

Permalink
BcFavoriteを全体テストの実行対象に追加する (#2821)
Browse files Browse the repository at this point in the history
Co-authored-by: Đỗ Văn Hùng <[email protected]>
  • Loading branch information
HungDV2022 and dovanhung authored Nov 2, 2023
1 parent 85643c0 commit 52201b9
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 158 deletions.
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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());
Expand All @@ -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());
}
Expand All @@ -105,13 +100,6 @@ public function validationDefaultDataProvider()
['name' => ''],
['name' => ['_empty' => 'タイトルは必須です。']]
],
[
['url' => 1],
[
'name' => ['_required' => 'タイトルは必須です。'],
'url' => ['isPermitted' => 'このURLの登録は許可されていません。']
]
],
[
['name' => 'hoge', 'url' => '/baser/admin/favorites/add'],
[]
Expand Down
Loading

0 comments on commit 52201b9

Please sign in to comment.