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

BcRedirectMainSiteMiddleware::process() ユニットテスト #4047

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class BcRedirectMainSiteMiddleware implements MiddlewareInterface
* @return ResponseInterface
* @checked
* @noTodo
* @unitTest
*/
public function process(
ServerRequestInterface $request,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?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 BaserCore\Test\TestCase\Middleware;

use BaserCore\Middleware\BcRedirectMainSiteMiddleware;
use BaserCore\Test\Factory\ContentFactory;
use BaserCore\Test\Factory\PageFactory;
use BaserCore\Test\Factory\SiteFactory;
use BaserCore\TestSuite\BcTestCase;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
* Class BcRedirectMainSiteMiddlewareTest
* @property BcRedirectMainSiteMiddleware $BcRedirectMainSiteMiddleware
*/
class BcRedirectMainSiteMiddlewareTest extends BcTestCase
{
/**
* Trait
*/
use ScenarioAwareTrait;

/**
* Set Up
*
* @return void
*/
public function setUp(): void
{
parent::setUp();
$this->BcRedirectMainSiteMiddleware = new BcRedirectMainSiteMiddleware();
}

/**
* Tear Down
*
* @return void
*/
public function tearDown(): void
{
unset($this->BcRedirectMainSiteMiddleware);
parent::tearDown();
}

/**
* test Process
* リダイレクトを確認
*/
public function test_process(): void
{
SiteFactory::make(['id' => 1, 'status' => true])->persist();
SiteFactory::make(['id' => 2, 'alias' => 's', 'auto_redirect' => true])->persist();
PageFactory::make(['id' => 1])->persist();
ContentFactory::make([
'url' => '/about',
'name' => 'about',
'plugin' => 'BaserCore',
'type' => 'Page',
'site_id' => 1,
'parent_id' => null,
'lft' => 1,
'rght' => 2,
'entity_id' => 1,
'site_root' => 2,
'status' => true
])->persist();

$request = $this->getRequest('/s/about')->withParam('plugin', 'BaserCore')->withParam('controller', 'Pages')->withParam('action', 'view');
$this->_response = $this->BcRedirectMainSiteMiddleware->process($request, $this->Application);
$this->assertResponseCode(302);

$request = $this->getRequest('/about')->withParam('plugin', 'BaserCore')->withParam('controller', 'Pages')->withParam('action', 'view');
$this->_response = $this->BcRedirectMainSiteMiddleware->process($request, $this->Application);
$this->assertResponseCode(200);
}
}