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

BcUtil::addSessionId() ユニットテスト #3831

Open
wants to merge 1 commit into
base: 5.1.x
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions plugins/baser-core/src/Utility/BcUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,7 @@ public static function isWindows()
* @return mixed
* @checked
* @noTodo
* @unitTest
*/
public static function addSessionId($url, $force = false)
{
Expand Down
37 changes: 37 additions & 0 deletions plugins/baser-core/tests/TestCase/Utility/BcUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use BaserCore\Event\BcEventListener;
use BaserCore\Test\Factory\SiteConfigFactory;
use BaserCore\Test\Factory\SiteFactory;
use BaserCore\Test\Factory\UserFactory;
use BaserCore\Test\Factory\UserGroupFactory;
use BaserCore\Test\Factory\UsersUserGroupFactory;
Expand Down Expand Up @@ -1593,4 +1594,40 @@ public function testPairToAssoc()
$result = BcUtil::pairToAssoc('');
$this->assertEquals([], $result);
}

/**
* test addSessionId
*/
public function testAddSessionId()
{
// 初期化
$this->truncateTable('sites');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryuring この書き方は悪いだと思いますが、BcUnitに関してPRをマージしてからsetUp()のところにloadFixtureScenarioを削除してリファクタリングします。
スクリーンショット 2024-09-20 11 41 19

SiteFactory::make(['id' => 1, 'device' => 'mobile'])->persist();
$_SERVER['REQUEST_URI'] = '/m/';

$this->assertEquals('/?BASERCMS=cli', BcUtil::addSessionId('/', true));
$this->assertEquals('/?id=1&BASERCMS=cli', BcUtil::addSessionId('/?id=1', true));
$this->assertEquals('/?id=1&BASERCMS=cli', BcUtil::addSessionId('/?id=1&BASERCMS=1', true));

// urlが配列の場合
$url = [
0 => '/',
'?' => [
'id' => 1,
'BASERCMS' => 1
]
];
$expect = [
0 => '/',
'?' => [
'id' => 1,
'BASERCMS' => 'cli'
]
];
$this->assertEquals($expect, BcUtil::addSessionId($url, true));

//adminでログインしいる場合、
$this->loginAdmin($this->getRequest('/baser/admin'));
$this->assertEquals('/', BcUtil::addSessionId('/'));
}
}
Loading