-
Notifications
You must be signed in to change notification settings - Fork 131
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
BcCustomContentControllerEventListener::startup()&setAdminMenu() のユニットテスト #4026
Merged
HungDV2022
merged 2 commits into
baserproject:5.1.x
from
HungDV2022:unittest_BcCustomContentControllerEventListener_startup
Nov 22, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
...ins/bc-custom-content/tests/TestCase/Event/BcCustomContentControllerEventListenerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?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 BcCustomContent\Test\TestCase\Event; | ||
|
||
use BaserCore\Controller\Admin\UsersController; | ||
use BaserCore\Service\BcDatabaseServiceInterface; | ||
use BaserCore\Test\Scenario\InitAppScenario; | ||
use BaserCore\TestSuite\BcTestCase; | ||
use BcCustomContent\Event\BcCustomContentControllerEventListener; | ||
use BcCustomContent\Service\CustomTablesServiceInterface; | ||
use BcCustomContent\Test\Scenario\CustomContentsScenario; | ||
use BcCustomContent\Test\Scenario\CustomEntriesScenario; | ||
use Cake\Core\Configure; | ||
use Cake\Event\Event; | ||
use Cake\Event\EventManager; | ||
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; | ||
|
||
/** | ||
* Class BcCustomContentControllerEventListenerTest | ||
* | ||
* @property BcCustomContentControllerEventListener $BcCustomContentControllerEventListener | ||
*/ | ||
class BcCustomContentControllerEventListenerTest extends BcTestCase | ||
{ | ||
/** | ||
* Trait | ||
*/ | ||
use ScenarioAwareTrait; | ||
|
||
/** | ||
* @var UsersController | ||
*/ | ||
public $UsersController; | ||
|
||
/** | ||
* @var EventManager|null | ||
*/ | ||
public $eventManager; | ||
|
||
/** | ||
* setUp | ||
* | ||
* @return void | ||
*/ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->loadFixtureScenario(InitAppScenario::class); | ||
$this->eventManager = EventManager::instance(); | ||
|
||
$this->BcAuthenticationEventListener = new BcCustomContentControllerEventListener(); | ||
foreach ($this->BcAuthenticationEventListener->implementedEvents() as $key => $event) { | ||
$this->eventManager->off($key); | ||
} | ||
$this->UsersController = new UsersController($this->loginAdmin($this->getRequest('/baser/admin/baser-core/users/'))); | ||
} | ||
|
||
/** | ||
* tearDown | ||
* | ||
* @return void | ||
*/ | ||
public function tearDown(): void | ||
{ | ||
$this->BcAuthenticationEventListener = null; | ||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* test startup | ||
*/ | ||
public function testStartupAnSetAdminMenu() | ||
{ | ||
//データを生成 | ||
$dataBaseService = $this->getService(BcDatabaseServiceInterface::class); | ||
$customTable = $this->getService(CustomTablesServiceInterface::class); | ||
//カスタムテーブルとカスタムエントリテーブルを生成 | ||
$customTable->create([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @HungDV2022 このデータは使われてますか? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ryuring |
||
'id' => 1, | ||
'name' => 'recruit_categories', | ||
'title' => '求人情報', | ||
'type' => '1', | ||
'display_field' => 'title', | ||
'has_child' => 0 | ||
]); | ||
//フィクチャーからデーターを生成 | ||
$this->loadFixtureScenario(CustomContentsScenario::class); | ||
$this->loadFixtureScenario(CustomEntriesScenario::class); | ||
|
||
$listener = $this->getMockBuilder(BcCustomContentControllerEventListener::class) | ||
->onlyMethods(['implementedEvents']) | ||
->addMethods(['usersStartup']) | ||
->getMock(); | ||
|
||
$listener->method('implementedEvents') | ||
->willReturn(['Controller.BaserCore.Users.startup' => ['callable' => 'usersStartup']]); | ||
|
||
$this->eventManager | ||
->on($listener) | ||
->on($this->BcAuthenticationEventListener) | ||
->dispatch(new Event('Controller.startup', $this->UsersController, [])); | ||
|
||
//メーニューにカスタムタイトルがあるか確認 | ||
$menu = Configure::read('BcApp.adminNavigation.Contents'); | ||
$this->assertEquals('サービスタイトル', $menu['CustomContent1']['title']); | ||
//不要なテーブルを削除 | ||
$dataBaseService->dropTable('custom_entry_1_recruit_categories'); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HungDV2022 変数名がおかしくないですか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
すみません。修正しました。