Skip to content

Commit

Permalink
fix #2032 Admin/BlogPostsController::beforeFilter のユニットテスト実装 (#2072)
Browse files Browse the repository at this point in the history
Co-authored-by: Đỗ Văn Hùng <HungDV2022>
  • Loading branch information
HungDV2022 committed Apr 27, 2023
1 parent 3fd330b commit 9132f03
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function initialize(): void
* @param EventInterface $event
* @checked
* @noTodo
* @unitTest
*/
public function beforeFilter(EventInterface $event)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
use BaserCore\Utility\BcUtil;
use BcBlog\Controller\Admin\BlogPostsController;
use BcBlog\Service\BlogPostsServiceInterface;
use BcBlog\Test\Factory\BlogPostFactory;
use BcBlog\Test\Scenario\BlogContentScenario;
use Cake\Core\Plugin;
use Cake\Event\Event;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;
use Cake\TestSuite\IntegrationTestTrait;

Expand Down Expand Up @@ -94,7 +93,39 @@ public function testInitialize(): void
*/
public function testBeforeFilter()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->loadFixtureScenario(BlogContentScenario::class, 1, 1, null, 'test', '/');
SiteConfigFactory::make(['name' => 'editor', 'value' => 'BaserCore.BcCkeditor'])->persist();

$request = $this->getRequest('/baser/admin/bc-blog/blog_posts/index/1');
$request = $this->loginAdmin($request);
$blogPosts = new BlogPostsController($request);

$event = new Event('filter');
$blogPosts->beforeFilter($event);
$helpers = $blogPosts->viewBuilder()->getHelpers();

$this->assertEquals($helpers[0], 'BaserCore.BcCkeditor');

//$blogContentIdを指定しない場合。
$this->expectExceptionMessage('不正なURLです。');
$this->expectException('BaserCore\Error\BcException');
$event = new Event('Controller.beforeFilter', $this->BlogPostsController);
$this->BlogPostsController->beforeFilter($event);
}
/**
* test beforeFilter
*/
public function testBeforeFilter_content_is_null()
{
//コンテンツデータが存在しない場合。
$this->expectExceptionMessage('コンテンツデータが見つかりません。');
$this->expectException('BaserCore\Error\BcException');
$request = $this->getRequest('/baser/admin/bc-blog/blog_posts/index/1111');
$request = $this->loginAdmin($request);
$blogPosts = new BlogPostsController($request);

$event = new Event('filter');
$blogPosts->beforeFilter($event);
}

/**
Expand Down

0 comments on commit 9132f03

Please sign in to comment.