From 055abc946dcbd7104461d48c5a284af8800dd44b Mon Sep 17 00:00:00 2001 From: thangnnmd <150879641+thangnnmd@users.noreply.github.com> Date: Mon, 9 Sep 2024 05:30:35 +0700 Subject: [PATCH 01/21] Add unitTest_BcZip_escapePath (#3770) Co-authored-by: thangnn --- .../tests/TestCase/Utility/BcZipTest.php | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/plugins/baser-core/tests/TestCase/Utility/BcZipTest.php b/plugins/baser-core/tests/TestCase/Utility/BcZipTest.php index 3954ed4122..feeddd9f74 100644 --- a/plugins/baser-core/tests/TestCase/Utility/BcZipTest.php +++ b/plugins/baser-core/tests/TestCase/Utility/BcZipTest.php @@ -56,9 +56,30 @@ public function testExtractByPhpLib() } - public function test_escapePath() + /** + * test _escapePath + * @param $path + * @param $expected + * @dataProvider escapePathDataProvider + */ + public function test_escapePath($path, $expected) + { + $result = $this->execPrivateMethod($this->BcZip, '_escapePath', [$path]); + $this->assertEquals($expected, $result); + } + + public static function escapePathDataProvider() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + return [ + ['/var/www/html', "''/'var'/'www'/'html'"], + ['/path/to/some file.txt', "''/'path'/'to'/'some file.txt'"], + ['/', "''/''"], + ['', "''"], + [ + '/path/with/$pecial&chars', + "''/'path'/'with'/'\$pecial&chars'", + ], + ]; } /** From bf5954602c69a5252559098450dcba0ecdae90d9 Mon Sep 17 00:00:00 2001 From: thangnnmd <150879641+thangnnmd@users.noreply.github.com> Date: Mon, 9 Sep 2024 05:31:44 +0700 Subject: [PATCH 02/21] Add unitTest_BcZip_extractByPhpLib (#3771) Co-authored-by: thangnn --- .../tests/TestCase/Utility/BcZipTest.php | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/plugins/baser-core/tests/TestCase/Utility/BcZipTest.php b/plugins/baser-core/tests/TestCase/Utility/BcZipTest.php index feeddd9f74..b16256d332 100644 --- a/plugins/baser-core/tests/TestCase/Utility/BcZipTest.php +++ b/plugins/baser-core/tests/TestCase/Utility/BcZipTest.php @@ -52,9 +52,68 @@ public function testCreate() */ public function testExtractByPhpLib() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + // create zip file + $zipSrcPath = TMP . 'zip' . DS; + $sourceZip = $zipSrcPath . 'test.zip'; + $targetPath = TMP . 'extracted' . DS; + + if (!file_exists($zipSrcPath)) { + mkdir($zipSrcPath, 0777, true); + } + if (!file_exists($targetPath)) { + mkdir($targetPath, 0777, true); + } + + $zip = new \ZipArchive(); + $zip->open($sourceZip, \ZipArchive::CREATE); + $zip->addFromString('testfolder' . DS . 'testfile.txt', 'This is a test file.'); + $zip->close(); + + $result = $this->execPrivateMethod($this->BcZip, '_extractByPhpLib', [$sourceZip, $targetPath]); + + $this->assertTrue($result); + $this->assertEquals('testfolder', $this->BcZip->topArchiveName); + + // check extracted file + $extractedFile = $targetPath . 'testfolder' . DS . 'testfile.txt'; + $this->assertFileExists($extractedFile); + $this->assertEquals('This is a test file.', file_get_contents($extractedFile)); + + // clean up + $folder = new BcFolder($zipSrcPath); + $folder->delete(); + $folder = new BcFolder($targetPath); + $folder->delete(); } + /** + * test testExtractByPhpLibReturnsFalse + */ + public function testExtractByPhpLibReturnsFalse() + { + $zipSrcPath = TMP . 'zip' . DS; + $sourceZip = $zipSrcPath . 'invalid.zip'; + $targetPath = TMP . 'extracted' . DS; + + if (!file_exists($zipSrcPath)) { + mkdir($zipSrcPath, 0777, true); + } + if (!file_exists($targetPath)) { + mkdir($targetPath, 0777, true); + } + + $result = $this->execPrivateMethod($this->BcZip, '_extractByPhpLib', [$sourceZip, $targetPath]); + + $this->assertFalse($result); + //check target path is empty + $this->assertEmpty(glob($targetPath . '*')); + + // clean up + $folder = new BcFolder($zipSrcPath); + $folder->delete(); + $folder = new BcFolder($targetPath); + $folder->delete(); + } /** * test _escapePath From 1155b06364bb7ee27d99c70ab83b741599ddf9c3 Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Mon, 9 Sep 2024 07:33:23 +0900 Subject: [PATCH 03/21] =?UTF-8?q?BcAbstractDetector::find()=20=E3=83=A6?= =?UTF-8?q?=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88=20(#3780?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng --- .../src/Utility/BcAbstractDetector.php | 1 + .../Utility/BcAbstractDetectorTest.php | 74 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 plugins/baser-core/tests/TestCase/Utility/BcAbstractDetectorTest.php diff --git a/plugins/baser-core/src/Utility/BcAbstractDetector.php b/plugins/baser-core/src/Utility/BcAbstractDetector.php index e5ca109bcc..8a05753bd5 100644 --- a/plugins/baser-core/src/Utility/BcAbstractDetector.php +++ b/plugins/baser-core/src/Utility/BcAbstractDetector.php @@ -77,6 +77,7 @@ public function __construct($name, array $config) * @return BcAbstractDetector|null * @checked * @noTodo + * @unitTest */ public static function find($name) { diff --git a/plugins/baser-core/tests/TestCase/Utility/BcAbstractDetectorTest.php b/plugins/baser-core/tests/TestCase/Utility/BcAbstractDetectorTest.php new file mode 100644 index 0000000000..38fdc7ce85 --- /dev/null +++ b/plugins/baser-core/tests/TestCase/Utility/BcAbstractDetectorTest.php @@ -0,0 +1,74 @@ + + * Copyright (c) NPO baser foundation + * + * @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\Utility; + +use BaserCore\TestSuite\BcTestCase; +use BaserCore\Utility\BcAgent; +use Cake\Core\Configure; + +/** + * Class BcAbstractDetector + * + */ +class BcAbstractDetectorTest extends BcTestCase +{ + + /** + * set up + */ + public function setUp(): void + { + parent::setUp(); + } + + /** + * tearDown + * + * @return void + */ + public function tearDown(): void + { + parent::tearDown(); + } + + /** + * test find + */ + public function testFind() + { + Configure::write("BcApp.smartphone", true); + + //Configureにnameがある場合、 + $rs = BcAgent::find('smartphone'); + $this->assertEquals('smartphone', $rs->name); + $this->assertEquals('device', $rs->type); + + //Configureにnameがない場合、 + $this->assertNull(BcAgent::find('test')); + } + + /** + * test findAll + */ + public function testFindAll() + { + $this->markTestIncomplete('このテストは、まだ実装されていません。'); + } + + /** + * test findCurrent + */ + public function testFindCurrent() + { + $this->markTestIncomplete('このテストは、まだ実装されていません。'); + } +} From 63a89050b646d0e498670b0d19e9e3c51899a8d7 Mon Sep 17 00:00:00 2001 From: seto1 <30764014+seto1@users.noreply.github.com> Date: Mon, 9 Sep 2024 18:28:18 +0900 Subject: [PATCH 04/21] =?UTF-8?q?=E3=83=86=E3=83=BC=E3=83=9E=E4=B8=80?= =?UTF-8?q?=E8=A6=A7=20=E3=83=86=E3=83=BC=E3=83=9E=E3=81=AEdescription?= =?UTF-8?q?=E3=81=8C=E8=A8=AD=E5=AE=9A=E3=81=95=E3=82=8C=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=81=A8=E3=82=A8=E3=83=A9=E3=83=BC=20(#3791?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/Admin/element/Themes/index_row.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/bc-admin-third/templates/Admin/element/Themes/index_row.php b/plugins/bc-admin-third/templates/Admin/element/Themes/index_row.php index 5363353f48..b6a0a94ebc 100755 --- a/plugins/bc-admin-third/templates/Admin/element/Themes/index_row.php +++ b/plugins/bc-admin-third/templates/Admin/element/Themes/index_row.php @@ -96,7 +96,9 @@ author) ?> -
BcText->autoLinkUrls($theme->description)) ?>
+ description)): ?> +
BcText->autoLinkUrls($theme->description)) ?>
+ From 1e0a456a93190487fa25060cabf7f27f4de03270 Mon Sep 17 00:00:00 2001 From: thangnnmd <150879641+thangnnmd@users.noreply.github.com> Date: Mon, 9 Sep 2024 16:35:02 +0700 Subject: [PATCH 05/21] Add unitTest_BcFolder_pwd (#3775) Co-authored-by: thangnn --- plugins/baser-core/src/Utility/BcFolder.php | 1 + .../tests/TestCase/Utility/BcFolderTest.php | 25 ++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/plugins/baser-core/src/Utility/BcFolder.php b/plugins/baser-core/src/Utility/BcFolder.php index 95fdfb2c67..6768c54b29 100644 --- a/plugins/baser-core/src/Utility/BcFolder.php +++ b/plugins/baser-core/src/Utility/BcFolder.php @@ -429,6 +429,7 @@ public function read($sort = true, $exceptions = false, $fullPath = false) * @return string * @checked * @noTodo + * @unitTest */ public function pwd(): string { diff --git a/plugins/baser-core/tests/TestCase/Utility/BcFolderTest.php b/plugins/baser-core/tests/TestCase/Utility/BcFolderTest.php index 73289aaae5..9176a8b821 100644 --- a/plugins/baser-core/tests/TestCase/Utility/BcFolderTest.php +++ b/plugins/baser-core/tests/TestCase/Utility/BcFolderTest.php @@ -165,10 +165,29 @@ public function test_move() $this->assertFileDoesNotExist($path. DS. 'test.txt'); $this->assertFileExists($des. DS. 'test.txt'); $folder2->delete(); - } + /** + * test pwd + * @param string $path + * @param string $expected + * @dataProvider pwdDataProvider + */ + public function test_pwd($path, $expected) + { + $bcFolder = new BcFolder($path); + $result = $bcFolder->pwd(); + $this->assertEquals($expected, $result); + } - - + public static function pwdDataProvider() + { + return [ + ['/', '/'], + ['/var/www/html', '/var/www/html'], + ['plugins/baser-core', 'plugins/baser-core'], + ['/path/with spaces/folder', '/path/with spaces/folder'], + ['', ''], + ]; + } } From 03acb0fa878407a6cf88e0af8f8d28155a6e6b51 Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Mon, 9 Sep 2024 18:44:01 +0900 Subject: [PATCH 06/21] =?UTF-8?q?BcAbstractDetector::findCurrent()=20?= =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=20(#3782)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng --- .../src/Utility/BcAbstractDetector.php | 1 + .../Utility/BcAbstractDetectorTest.php | 24 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/plugins/baser-core/src/Utility/BcAbstractDetector.php b/plugins/baser-core/src/Utility/BcAbstractDetector.php index 8a05753bd5..d10251f44a 100644 --- a/plugins/baser-core/src/Utility/BcAbstractDetector.php +++ b/plugins/baser-core/src/Utility/BcAbstractDetector.php @@ -117,6 +117,7 @@ public static function findAll() * @return BcAbstractDetector|null * @checked * @noTodo + * @unitTest */ public static function findCurrent() { diff --git a/plugins/baser-core/tests/TestCase/Utility/BcAbstractDetectorTest.php b/plugins/baser-core/tests/TestCase/Utility/BcAbstractDetectorTest.php index 38fdc7ce85..05cf7ae69f 100644 --- a/plugins/baser-core/tests/TestCase/Utility/BcAbstractDetectorTest.php +++ b/plugins/baser-core/tests/TestCase/Utility/BcAbstractDetectorTest.php @@ -66,9 +66,29 @@ public function testFindAll() /** * test findCurrent + * @param string $agent ユーザーエージェント名 + * @param string $expect 期待値 + * + * @dataProvider findCurrentDataProvider */ - public function testFindCurrent() + public function testFindCurrent($agent, $expect) { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $_SERVER["HTTP_USER_AGENT"] = $agent; + $result = BcAgent::findCurrent(); + if (is_null($expect)) { + $this->assertNull($result); + } else { + $this->assertEquals($expect, $result->name); + } + } + + public static function findCurrentDataProvider(): array + { + return [ + ['Googlebot-Mobile', 'mobile'], + ['DoCoMo', 'mobile'], + ['iPhone', 'smartphone'], + ['hoge', null], + ]; } } From 8b6669e3c4e914ce538a60c5dcab152e43837cd8 Mon Sep 17 00:00:00 2001 From: thangnnmd <150879641+thangnnmd@users.noreply.github.com> Date: Mon, 9 Sep 2024 16:44:46 +0700 Subject: [PATCH 07/21] unitTest_BcEventListener_isAction (#3783) Co-authored-by: thangnn --- .../baser-core/src/Event/BcEventListener.php | 1 + .../TestCase/Event/BcEventListenerTest.php | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/plugins/baser-core/src/Event/BcEventListener.php b/plugins/baser-core/src/Event/BcEventListener.php index 60f28ad370..355b454a40 100644 --- a/plugins/baser-core/src/Event/BcEventListener.php +++ b/plugins/baser-core/src/Event/BcEventListener.php @@ -122,6 +122,7 @@ public function implementedEvents(): array * @return bool * @checked * @noTodo + * @unitTest */ public function isAction($action, $isContainController = true) { diff --git a/plugins/baser-core/tests/TestCase/Event/BcEventListenerTest.php b/plugins/baser-core/tests/TestCase/Event/BcEventListenerTest.php index bb1b75ae56..3fdebf0398 100644 --- a/plugins/baser-core/tests/TestCase/Event/BcEventListenerTest.php +++ b/plugins/baser-core/tests/TestCase/Event/BcEventListenerTest.php @@ -45,4 +45,39 @@ public function testGetAction() $result = $this->BcEventListener->getAction(false); $this->assertEquals('Index', $result); } + + /** + * Test isAction + * @param $currentAction + * @param $actionToCheck + * @param $isContainController + * @param $expected + * @dataProvider isActionDataProvider + */ + public function testIsAction($currentAction, $actionToCheck, $isContainController, $expected) + { + $this->BcEventListener = $this->getMockBuilder(BcEventListener::class) + ->onlyMethods(['getAction']) + ->getMock(); + + $this->BcEventListener->method('getAction') + ->with($isContainController) + ->willReturn($currentAction); + + $result = $this->BcEventListener->isAction($actionToCheck, $isContainController); + $this->assertEquals($expected, $result); + } + + public static function isActionDataProvider() + { + return [ + ['Users.Index', 'Users.Index', true, true], + ['Users.Index', 'Users.View', true, false], + ['Users.Index', ['Users.View', 'Users.Index'], true, true], + ['Users.Index', ['Users.View', 'Users.Edit'], true, false], + ['Index', 'Index', false, true], + ['Index', 'View', false, false], + ['Users.Index', 'Users.Index', true, true], + ]; + } } From e973a7d68c4f2b5b77739dd03e6e07b03ece576e Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Mon, 9 Sep 2024 18:46:51 +0900 Subject: [PATCH 08/21] =?UTF-8?q?BcLang::=5FsetConfig()=20=E3=83=A6?= =?UTF-8?q?=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88=20(#3787?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng --- plugins/baser-core/src/Utility/BcLang.php | 1 + plugins/baser-core/tests/TestCase/Utility/BcLangTest.php | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/baser-core/src/Utility/BcLang.php b/plugins/baser-core/src/Utility/BcLang.php index 12ee0fd491..b4e4272330 100644 --- a/plugins/baser-core/src/Utility/BcLang.php +++ b/plugins/baser-core/src/Utility/BcLang.php @@ -43,6 +43,7 @@ class BcLang extends BcAbstractDetector * @return void * @checked * @noTodo + * @unitTest */ protected function _setConfig(array $config) { diff --git a/plugins/baser-core/tests/TestCase/Utility/BcLangTest.php b/plugins/baser-core/tests/TestCase/Utility/BcLangTest.php index d09e64aaf4..6904be1839 100644 --- a/plugins/baser-core/tests/TestCase/Utility/BcLangTest.php +++ b/plugins/baser-core/tests/TestCase/Utility/BcLangTest.php @@ -17,9 +17,16 @@ public function tearDown(): void parent::tearDown(); } + /** + * test _setConfig + */ public function testSetConfig() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $bcLang = new BcLang('BcLang', ['langs' => 'ja-JP']); + //対象メソッドをコール + $this->execPrivateMethod($bcLang, '_setConfig', [['langs' => 'ja-JP']]); + //decisionKeysがlangsを設定できるか確認すること + $this->assertEquals('ja-JP', $bcLang->decisionKeys); } public function testGetDefaultConfig() From 397ff245844fbe6649b69ecb9708eee85d8d27da Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Mon, 9 Sep 2024 18:47:23 +0900 Subject: [PATCH 09/21] =?UTF-8?q?BcLang::=5FgetDefaultConfig()=20=E3=83=A6?= =?UTF-8?q?=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88=20(#3788?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng --- plugins/baser-core/src/Utility/BcLang.php | 1 + plugins/baser-core/tests/TestCase/Utility/BcLangTest.php | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/baser-core/src/Utility/BcLang.php b/plugins/baser-core/src/Utility/BcLang.php index b4e4272330..00f94e2233 100644 --- a/plugins/baser-core/src/Utility/BcLang.php +++ b/plugins/baser-core/src/Utility/BcLang.php @@ -56,6 +56,7 @@ protected function _setConfig(array $config) * @return array * @checked * @noTodo + * @unitTest */ protected function _getDefaultConfig() { diff --git a/plugins/baser-core/tests/TestCase/Utility/BcLangTest.php b/plugins/baser-core/tests/TestCase/Utility/BcLangTest.php index 6904be1839..dcadc6824b 100644 --- a/plugins/baser-core/tests/TestCase/Utility/BcLangTest.php +++ b/plugins/baser-core/tests/TestCase/Utility/BcLangTest.php @@ -29,9 +29,14 @@ public function testSetConfig() $this->assertEquals('ja-JP', $bcLang->decisionKeys); } + /** + * test _getDefaultConfig + */ public function testGetDefaultConfig() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $bcLang = new BcLang('BcLang', ['langs' => 'ja-JP']); + $rs = $this->execPrivateMethod($bcLang, '_getDefaultConfig', []); + $this->assertEquals($rs['langs'], []); } public function testGetPattern() From c39593b2e96b89f0b6e47618285d61f06a9d5d35 Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Mon, 9 Sep 2024 18:48:49 +0900 Subject: [PATCH 10/21] =?UTF-8?q?BcAdminHelper::existsAddLink()=20?= =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=20(#3789)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng --- .../src/View/Helper/BcAdminHelper.php | 1 + .../View/Helper/BcAdminHelperTest.php | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/plugins/baser-core/src/View/Helper/BcAdminHelper.php b/plugins/baser-core/src/View/Helper/BcAdminHelper.php index 4b8117629b..2f85df60b7 100755 --- a/plugins/baser-core/src/View/Helper/BcAdminHelper.php +++ b/plugins/baser-core/src/View/Helper/BcAdminHelper.php @@ -425,6 +425,7 @@ public function existsPublishLink() * @return bool * @checked * @noTodo + * @unitTest */ public function existsAddLink() { diff --git a/plugins/baser-core/tests/TestCase/View/Helper/BcAdminHelperTest.php b/plugins/baser-core/tests/TestCase/View/Helper/BcAdminHelperTest.php index 46686d307d..8ea1cc8a98 100644 --- a/plugins/baser-core/tests/TestCase/View/Helper/BcAdminHelperTest.php +++ b/plugins/baser-core/tests/TestCase/View/Helper/BcAdminHelperTest.php @@ -13,6 +13,7 @@ use BaserCore\Middleware\BcAdminMiddleware; use BaserCore\Service\Admin\BcAdminAppServiceInterface; +use BaserCore\Test\Factory\ContentFactory; use BaserCore\Test\Factory\SiteFactory; use BaserCore\Test\Factory\UserFactory; use BaserCore\Test\Scenario\InitAppScenario; @@ -395,6 +396,38 @@ public function testExistsPublishLink() $this->assertEquals(true, $this->BcAdmin->existsPublishLink()); } + /** + * test existsAddLink + */ + public function testExistsAddLink() + { + //データを生成 + $this->loadFixtureScenario(InitAppScenario::class); + ContentFactory::make(['type' => 'ContentFolder', 'url' => '/service'])->persist(); + ContentFactory::make(['type' => 'ContentLink', 'url' => '/service-1'])->persist(); + + //isAdminSystem = true, return false + $request = $this->loginAdmin($this->getRequest('/baser/admin/baser-core/pages/edit/2')); + $this->BcAdmin->getView()->setRequest($request); + $this->assertFalse($this->BcAdmin->existsAddLink()); + + //isAdminSystem = false, return false + $this->BcAdmin->getView()->setRequest($this->getRequest('/')); + $this->assertFalse($this->BcAdmin->existsAddLink()); + + //isAdminSystem = true && type !== ContentFolder, return false + $request = $this->loginAdmin($this->getRequest('/service-1')); + $request->getSession()->write('AuthAdmin', UserFactory::get(1)); + $this->BcAdmin->getView()->setRequest($request); + $this->assertFalse($this->BcAdmin->existsAddLink()); + + //isAdminSystem = true && type == ContentFolder, return true + $request = $this->loginAdmin($this->getRequest('/service')); + $request->getSession()->write('AuthAdmin', UserFactory::get(1)); + $this->BcAdmin->getView()->setRequest($request); + $this->assertTrue($this->BcAdmin->existsAddLink()); + } + /** * 編集画面へのリンクを出力する * From 04cafd274466fbb718e00267a6e0d4fe32f07981 Mon Sep 17 00:00:00 2001 From: ryoma_kawase <137789417+RyoK513@users.noreply.github.com> Date: Tue, 10 Sep 2024 13:34:40 +0900 Subject: [PATCH 11/21] =?UTF-8?q?=E3=83=86=E3=83=BC=E3=83=9E=E3=83=86?= =?UTF-8?q?=E3=83=B3=E3=83=97=E3=83=AC=E3=83=BC=E3=83=88=E3=81=AE=E7=B7=A8?= =?UTF-8?q?=E9=9B=86=E8=A8=AD=E5=AE=9A=E3=81=AE=E5=90=8D=E7=A7=B0=E3=81=AB?= =?UTF-8?q?=E3=83=96=E3=83=AC=E3=81=8C=E3=81=82=E3=82=8B=E3=81=AE=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20(#3795)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bc-theme-file/src/Controller/Admin/ThemeFilesController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/bc-theme-file/src/Controller/Admin/ThemeFilesController.php b/plugins/bc-theme-file/src/Controller/Admin/ThemeFilesController.php index 9c91dc05f9..1170a918e7 100644 --- a/plugins/bc-theme-file/src/Controller/Admin/ThemeFilesController.php +++ b/plugins/bc-theme-file/src/Controller/Admin/ThemeFilesController.php @@ -76,7 +76,7 @@ public function __construct( ]; // テーマ編集機能が制限されている場合はアクセス禁止 - if (Configure::read('BcThemeEdit.allowedThemeEdit') === false) { + if (Configure::read('BcThemeFile.allowedThemeEdit') === false) { $denyList = [ 'index', 'add', From 720fbe70878942973cb1cd0b34b4cd9f1f72dd0f Mon Sep 17 00:00:00 2001 From: GUSSAN Date: Tue, 10 Sep 2024 17:36:50 +0900 Subject: [PATCH 12/21] =?UTF-8?q?fix=20#3764=20postContent()=E3=80=81getPo?= =?UTF-8?q?stContent()=E3=81=AB=E3=81=A4=E3=81=84=E3=81=A6=E3=80=81?= =?UTF-8?q?=E3=83=91=E3=83=A9=E3=83=A1=E3=83=BC=E3=82=BF=E3=81=AE=E5=AE=A3?= =?UTF-8?q?=E8=A8=80=E5=9E=8B=E3=82=92=E8=A8=82=E6=AD=A3=E3=80=82=20(#3798?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit postContent()、getPostContent()について、パラメータの宣言型を訂正。 --- plugins/bc-blog/src/View/Helper/BlogHelper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/bc-blog/src/View/Helper/BlogHelper.php b/plugins/bc-blog/src/View/Helper/BlogHelper.php index ba30e0e509..f81a896a1c 100755 --- a/plugins/bc-blog/src/View/Helper/BlogHelper.php +++ b/plugins/bc-blog/src/View/Helper/BlogHelper.php @@ -454,9 +454,9 @@ public function postLink($post, $title, $options = []) public function postContent( BlogPost $post, bool $moreText = true, - bool $moreLink = false, + mixed $moreLink = false, mixed $cut = false, - bool $lastText = false + mixed $lastText = false ) { echo $this->getPostContent($post, $moreText, $moreLink, $cut, $lastText); @@ -482,7 +482,7 @@ public function getPostContent( bool $moreText = true, mixed $moreLink = false, mixed $cut = false, - bool $lastText = false + mixed $lastText = false ) { if ($cut) { From 35ad76ac55b7fe42a6c261b9017c6c5e11db3ca0 Mon Sep 17 00:00:00 2001 From: thangnnmd <150879641+thangnnmd@users.noreply.github.com> Date: Tue, 10 Sep 2024 15:48:13 +0700 Subject: [PATCH 13/21] Add unitTest_BcLang_isMatchDecisionKey (#3792) Co-authored-by: thangnn --- plugins/baser-core/src/Utility/BcLang.php | 1 + .../tests/TestCase/Utility/BcLangTest.php | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/plugins/baser-core/src/Utility/BcLang.php b/plugins/baser-core/src/Utility/BcLang.php index 00f94e2233..d76685af2a 100644 --- a/plugins/baser-core/src/Utility/BcLang.php +++ b/plugins/baser-core/src/Utility/BcLang.php @@ -84,6 +84,7 @@ public function getDetectorRegex() * @return bool * @checked * @noTodo + * @unitTest */ public function isMatchDecisionKey() { diff --git a/plugins/baser-core/tests/TestCase/Utility/BcLangTest.php b/plugins/baser-core/tests/TestCase/Utility/BcLangTest.php index dcadc6824b..4a4b97aec5 100644 --- a/plugins/baser-core/tests/TestCase/Utility/BcLangTest.php +++ b/plugins/baser-core/tests/TestCase/Utility/BcLangTest.php @@ -67,4 +67,47 @@ public static function parseLangDataProvider() ['123,456', '123'], ]; } + + /** + * Test isMatchDecisionKey + * @param string $acceptLanguage + * @param string $detectorRegex + * @param bool $expected + * @dataProvider isMatchDecisionKeyDataProvider + */ + public function testIsMatchDecisionKey($acceptLanguage, $detectorRegex, $expected) + { + $request = $this->getMockBuilder('Cake\Http\ServerRequest')->getMock(); + $config = []; + + $BcLang = $this->getMockBuilder(BcLang::class) + ->setConstructorArgs([$request, $config]) + ->onlyMethods(['getDetectorRegex']) + ->getMock(); + + $BcLang->method('getDetectorRegex') + ->willReturn($detectorRegex); + + // Set $_SERVER['HTTP_ACCEPT_LANGUAGE'] + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $acceptLanguage; + + $result = $BcLang->isMatchDecisionKey(); + $this->assertEquals($expected, $result); + + // Clean up + unset($_SERVER['HTTP_ACCEPT_LANGUAGE']); + } + + public static function isMatchDecisionKeyDataProvider() + { + return [ + ['en-US,en;q=0.9', '/en/i', true], + ['ja,en-US;q=0.9,en;q=0.8', '/ja|en/i', true], + ['fr-FR,fr;q=0.9', '/de|es/i', false], + ['', '/en|ja/i', true], + [null, '/en|ja/i', true], + ['', '/ja/i', true], + ['', '/en/i', false], + ]; + } } From 3dccdcca55f8276c75fcc6384e1f26c609a9c788 Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Tue, 10 Sep 2024 17:51:08 +0900 Subject: [PATCH 14/21] =?UTF-8?q?BcAdminHelper::addLink()=20=E3=81=AE?= =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=20(#3796)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng --- .../src/View/Helper/BcAdminHelper.php | 1 + .../View/Helper/BcAdminHelperTest.php | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/plugins/baser-core/src/View/Helper/BcAdminHelper.php b/plugins/baser-core/src/View/Helper/BcAdminHelper.php index 2f85df60b7..50afe8fb3a 100755 --- a/plugins/baser-core/src/View/Helper/BcAdminHelper.php +++ b/plugins/baser-core/src/View/Helper/BcAdminHelper.php @@ -478,6 +478,7 @@ public function editLink(): void * @return void * @checked * @noTodo + * @unitTest */ public function addLink(): void { diff --git a/plugins/baser-core/tests/TestCase/View/Helper/BcAdminHelperTest.php b/plugins/baser-core/tests/TestCase/View/Helper/BcAdminHelperTest.php index 8ea1cc8a98..f6542da133 100644 --- a/plugins/baser-core/tests/TestCase/View/Helper/BcAdminHelperTest.php +++ b/plugins/baser-core/tests/TestCase/View/Helper/BcAdminHelperTest.php @@ -428,6 +428,37 @@ public function testExistsAddLink() $this->assertTrue($this->BcAdmin->existsAddLink()); } + /** + * test addLink + */ + public function testAddLink() + { + //データを生成 + $this->loadFixtureScenario(InitAppScenario::class); + ContentFactory::make(['type' => 'ContentFolder', 'url' => '/service'])->persist(); + + //isAdminSystem = true, return '' + $this->BcAdmin->getView()->setRequest($this->loginAdmin($this->getRequest('/baser/admin/baser-core/pages/edit/2'))); + ob_start(); + $this->BcAdmin->addLink(); + $actualEmpty = ob_get_clean(); + $this->assertEmpty($actualEmpty); + + //$content == null, return '' + $this->BcAdmin->getView()->setRequest($this->getRequest('/service-1')); + ob_start(); + $this->BcAdmin->addLink(); + $actualEmpty = ob_get_clean(); + $this->assertEmpty($actualEmpty); + + //$content != null, 固定ページ新規追加画面へのリンクを出力する + $this->BcAdmin->getView()->setRequest($this->getRequest('/service')); + ob_start(); + $this->BcAdmin->addLink(); + $actualEmpty = ob_get_clean(); + $this->assertTextContains('新規ページ追加', $actualEmpty); + } + /** * 編集画面へのリンクを出力する * From 229457f0670b7706f72fa5d65b87376407ac737e Mon Sep 17 00:00:00 2001 From: thangnnmd <150879641+thangnnmd@users.noreply.github.com> Date: Thu, 12 Sep 2024 07:42:43 +0700 Subject: [PATCH 15/21] BcSiteConfig::get (#3774) Co-authored-by: thangnn --- .../baser-core/src/Utility/BcSiteConfig.php | 1 + .../TestCase/Utility/BcSiteConfigTest.php | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 plugins/baser-core/tests/TestCase/Utility/BcSiteConfigTest.php diff --git a/plugins/baser-core/src/Utility/BcSiteConfig.php b/plugins/baser-core/src/Utility/BcSiteConfig.php index e01cd0f7a2..fa4b873dec 100644 --- a/plugins/baser-core/src/Utility/BcSiteConfig.php +++ b/plugins/baser-core/src/Utility/BcSiteConfig.php @@ -29,6 +29,7 @@ class BcSiteConfig * @return mixed * @checked * @noTodo + * @unitTest */ public static function get($key) { diff --git a/plugins/baser-core/tests/TestCase/Utility/BcSiteConfigTest.php b/plugins/baser-core/tests/TestCase/Utility/BcSiteConfigTest.php new file mode 100644 index 0000000000..e307d77264 --- /dev/null +++ b/plugins/baser-core/tests/TestCase/Utility/BcSiteConfigTest.php @@ -0,0 +1,29 @@ + 'version', 'value' => '2.0.0'])->persist(); + $this->assertEquals('2.0.0', BcSiteConfig::get('version')); + + //field not exist + $this->assertEquals(null, BcSiteConfig::get('not_exist')); + } +} From c684118093fea6479d4ef979547030e3fd60df38 Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Thu, 12 Sep 2024 09:43:04 +0900 Subject: [PATCH 16/21] =?UTF-8?q?BcAbstractDetector::findAll()=20=E3=83=A6?= =?UTF-8?q?=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88=20(#3781?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng --- plugins/baser-core/src/Utility/BcAbstractDetector.php | 1 + .../tests/TestCase/Utility/BcAbstractDetectorTest.php | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/plugins/baser-core/src/Utility/BcAbstractDetector.php b/plugins/baser-core/src/Utility/BcAbstractDetector.php index d10251f44a..fb831f875b 100644 --- a/plugins/baser-core/src/Utility/BcAbstractDetector.php +++ b/plugins/baser-core/src/Utility/BcAbstractDetector.php @@ -94,6 +94,7 @@ public static function find($name) * @return BcAbstractDetector[] * @checked * @noTodo + * @unitTest */ public static function findAll() { diff --git a/plugins/baser-core/tests/TestCase/Utility/BcAbstractDetectorTest.php b/plugins/baser-core/tests/TestCase/Utility/BcAbstractDetectorTest.php index 05cf7ae69f..f5ab3fac85 100644 --- a/plugins/baser-core/tests/TestCase/Utility/BcAbstractDetectorTest.php +++ b/plugins/baser-core/tests/TestCase/Utility/BcAbstractDetectorTest.php @@ -61,7 +61,16 @@ public function testFind() */ public function testFindAll() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + Configure::write("BcEnv.isInstalled", false); + + //isInstalled=false + $agents = BcAgent::findAll(); + $this->assertCount(0, $agents); + + //isInstalled=true + Configure::write("BcEnv.isInstalled", true); + $agents = BcAgent::findAll(); + $this->assertCount(2, $agents); } /** From 1b63d0a2a790b669f50bd9976a260a0fc507365e Mon Sep 17 00:00:00 2001 From: thangnnmd <150879641+thangnnmd@users.noreply.github.com> Date: Thu, 12 Sep 2024 07:44:20 +0700 Subject: [PATCH 17/21] MailMessagesTable::createTableName (#3784) Co-authored-by: thangnn --- .../src/Model/Table/MailMessagesTable.php | 13 +++---- .../Model/Table/MailMessagesTableTest.php | 37 +++++++++++++++++++ 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/plugins/bc-mail/src/Model/Table/MailMessagesTable.php b/plugins/bc-mail/src/Model/Table/MailMessagesTable.php index 219dd6aaa7..09f9943b0b 100755 --- a/plugins/bc-mail/src/Model/Table/MailMessagesTable.php +++ b/plugins/bc-mail/src/Model/Table/MailMessagesTable.php @@ -144,18 +144,15 @@ public function setUseTable($mailContentId) /** * テーブル名を生成する * int型でなかったら強制終了 - * @param $mailContentId - * @return string + * @param int $mailContentId + * @return string The table name * @checked * @noTodo + * @unitTest */ - public function createTableName($mailContentId) + public function createTableName(int $mailContentId): string { - $mailContentId = (int)$mailContentId; - if (!is_int($mailContentId)) { - throw new BcException(__d('baser_core', 'MailMessageService::createTableName() の引数 $mailContentId は int 型しか受けつけていません。')); - } - return $this->addPrefix('mail_message_' . $mailContentId); + return $this->addPrefix("mail_message_{$mailContentId}"); } /** diff --git a/plugins/bc-mail/tests/TestCase/Model/Table/MailMessagesTableTest.php b/plugins/bc-mail/tests/TestCase/Model/Table/MailMessagesTableTest.php index be4399d592..102361e146 100644 --- a/plugins/bc-mail/tests/TestCase/Model/Table/MailMessagesTableTest.php +++ b/plugins/bc-mail/tests/TestCase/Model/Table/MailMessagesTableTest.php @@ -19,9 +19,11 @@ use BcMail\Test\Scenario\MailFieldsScenario; use BcMail\Test\TestCase\Model\Array; use BcMail\Test\TestCase\Model\ClassRegistry; +use Cake\Core\Exception\CakeException; use Cake\ORM\Entity; use Cake\TestSuite\IntegrationTestTrait; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; +use TypeError; /** * Class MailMessageTest @@ -509,4 +511,39 @@ public function test_createFullTableName() $expected = 'prefix_mail_message_5'; $this->assertEquals($expected, $result); } + + /** + * test createTableName + * @param $mailContentId + * @param $expected + * @param bool $expectException + * @dataProvider createTableNameDataProvider + */ + public function test_createTableName($mailContentId, $expected, $expectException = false) + { + if ($expectException) { + $this->expectException(TypeError::class); + } + + $result = $this->MailMessage->createTableName($mailContentId); + + if (!$expectException) { + $this->assertEquals($expected, $result); + } + } + + public static function createTableNameDataProvider() + { + return [ + [1, 'mail_message_1'], + [0, 'mail_message_0'], + [-1, 'mail_message_-1'], + ['2', 'mail_message_2'], + ['abc', null, true], + ['', null, true], + [null, null, true], + [true, 'mail_message_1'], + [false, 'mail_message_0'], + ]; + } } From 4ba4ccf906efa93e939385bedd1ff4d18e26f73c Mon Sep 17 00:00:00 2001 From: thangnnmd <150879641+thangnnmd@users.noreply.github.com> Date: Thu, 12 Sep 2024 07:44:36 +0700 Subject: [PATCH 18/21] Add unitTest_BcLang_getDetectorRegex (#3793) Co-authored-by: thangnn --- plugins/baser-core/src/Utility/BcLang.php | 1 + .../tests/TestCase/Utility/BcLangTest.php | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/plugins/baser-core/src/Utility/BcLang.php b/plugins/baser-core/src/Utility/BcLang.php index d76685af2a..dbb5ac0db8 100644 --- a/plugins/baser-core/src/Utility/BcLang.php +++ b/plugins/baser-core/src/Utility/BcLang.php @@ -71,6 +71,7 @@ protected function _getDefaultConfig() * @return string * @checked * @noTodo + * @unitTest */ public function getDetectorRegex() { diff --git a/plugins/baser-core/tests/TestCase/Utility/BcLangTest.php b/plugins/baser-core/tests/TestCase/Utility/BcLangTest.php index 4a4b97aec5..efc549e300 100644 --- a/plugins/baser-core/tests/TestCase/Utility/BcLangTest.php +++ b/plugins/baser-core/tests/TestCase/Utility/BcLangTest.php @@ -110,4 +110,27 @@ public static function isMatchDecisionKeyDataProvider() ['', '/en/i', false], ]; } + + /** + * Test getDetectorRegex + * @param array $decisionKeys + * @param string $expected + * @dataProvider getDetectorRegexDataProvider + */ + public function testGetDetectorRegex($decisionKeys, $expected) + { + $lang = new BcLang('lang', ['langs' => $decisionKeys]); + $result = $lang->getDetectorRegex(); + $this->assertEquals($expected, $result); + } + + public static function getDetectorRegexDataProvider() + { + return [ + [['en'], '/en/i'], + [['en', 'ja', 'fr'], '/en|ja|fr/i'], + [['en-US', 'zh-CN', 'pt-BR'], '/en\-US|zh\-CN|pt\-BR/i'], + [[], '//i'], + ]; + } } From 9bd82d257028198fbde9f7d64ec5b9a41b9a70ba Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Thu, 12 Sep 2024 09:45:21 +0900 Subject: [PATCH 19/21] =?UTF-8?q?BcAdminHelper::firstAccess()=20=E3=81=AE?= =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=20(#3797)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng --- .../src/View/Helper/BcAdminHelper.php | 3 ++- .../View/Helper/BcAdminHelperTest.php | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/plugins/baser-core/src/View/Helper/BcAdminHelper.php b/plugins/baser-core/src/View/Helper/BcAdminHelper.php index 50afe8fb3a..ff3987a587 100755 --- a/plugins/baser-core/src/View/Helper/BcAdminHelper.php +++ b/plugins/baser-core/src/View/Helper/BcAdminHelper.php @@ -522,10 +522,11 @@ public function publishLink(): void * @return void * @checked * @noTodo + * @unitTest */ public function firstAccess() { - if($this->getView()->getRequest()->getParam('controller') === 'installations') return; + if ($this->getView()->getRequest()->getParam('controller') === 'installations') return; $this->BcBaser->element('first_access'); } diff --git a/plugins/baser-core/tests/TestCase/View/Helper/BcAdminHelperTest.php b/plugins/baser-core/tests/TestCase/View/Helper/BcAdminHelperTest.php index f6542da133..cb6e987d1d 100644 --- a/plugins/baser-core/tests/TestCase/View/Helper/BcAdminHelperTest.php +++ b/plugins/baser-core/tests/TestCase/View/Helper/BcAdminHelperTest.php @@ -510,6 +510,27 @@ public function testPublishLink() $this->assertEquals('サイト確認', $result); } + /** + * test firstAccess + */ + public function testFirstAccess() + { + //controller == installations, return '' + $request = $this->getRequest('/')->withParam('controller', 'installations'); + $this->BcAdmin->getView()->setRequest($request); + ob_start(); + $this->BcAdmin->firstAccess(); + $actualEmpty = ob_get_clean(); + $this->assertEmpty($actualEmpty); + + //controller != installations, 初回アクセス時のメッセージ表示 + $this->BcAdmin->getView()->setRequest($this->getRequest('/baser/admin/baser-core/pages/edit/2'))->set('firstAccess', true); + ob_start(); + $this->BcAdmin->firstAccess(); + $actualEmpty = ob_get_clean(); + $this->assertTextContains('baserCMSへようこそ', $actualEmpty); + } + /** * test getTitle * @return void From 58d9e9b243d207cc678853859753fabe82d08ff0 Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Thu, 12 Sep 2024 09:45:54 +0900 Subject: [PATCH 20/21] =?UTF-8?q?BcAuthHelper::isSuperUser()=20=E3=81=AE?= =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=20(#3800)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng --- .../src/View/Helper/BcAuthHelper.php | 1 + .../TestCase/View/Helper/BcAuthHelperTest.php | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/plugins/baser-core/src/View/Helper/BcAuthHelper.php b/plugins/baser-core/src/View/Helper/BcAuthHelper.php index f2e77999e5..b2fa90b82f 100644 --- a/plugins/baser-core/src/View/Helper/BcAuthHelper.php +++ b/plugins/baser-core/src/View/Helper/BcAuthHelper.php @@ -249,6 +249,7 @@ public function getCurrentLoginUser() * @return boolean * @checked * @noTodo + * @unitTest */ public function isSuperUser(): bool { diff --git a/plugins/baser-core/tests/TestCase/View/Helper/BcAuthHelperTest.php b/plugins/baser-core/tests/TestCase/View/Helper/BcAuthHelperTest.php index 701c41ac45..5d5a369f71 100644 --- a/plugins/baser-core/tests/TestCase/View/Helper/BcAuthHelperTest.php +++ b/plugins/baser-core/tests/TestCase/View/Helper/BcAuthHelperTest.php @@ -293,6 +293,44 @@ public static function isAdminUserDataProvider() ]; } + /** + * Test isSuperUser + * @dataProvider isSupperUserDataProvider + * @param $id + * @param $expected + * @return void + */ + public function testIsSuperUser($id, $expected) + { + //データー生成 + $this->loadFixtureScenario(InitAppScenario::class); + UserFactory::make(['id' => 2])->persist(); + UserFactory::make(['id' => 3])->persist(); + //特権ユーザを設定 + Configure::write('BcApp.superUserId', 2); + + if ($id) { + $this->loginAdmin($this->getRequest('/baser/admin'), $id); + } + + $result = $this->BcAuth->isSuperUser(); + $this->assertEquals($result, $expected); + } + + public static function isSupperUserDataProvider() + { + return [ + // ログインしない場合 + [null, false], + // システム管理者の場合 + [1, false], + // 特権ユーザでのログインの場合 + [2, true], + // サイト運営者などそれ以外の場合 + [3, false], + ]; + } + /** * Test isAgentUser * @return void From b470c8dfb960578c4ff6690d71b5d1a2995ae9a0 Mon Sep 17 00:00:00 2001 From: HungDV2022 <110375578+HungDV2022@users.noreply.github.com> Date: Thu, 12 Sep 2024 09:46:33 +0900 Subject: [PATCH 21/21] =?UTF-8?q?BcBaserHelper::pagination()=20=E3=81=AE?= =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=20(#3801)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Đỗ Văn Hùng --- .../src/View/Helper/BcBaserHelper.php | 1 + .../View/Helper/BcBaserHelperTest.php | 26 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/plugins/baser-core/src/View/Helper/BcBaserHelper.php b/plugins/baser-core/src/View/Helper/BcBaserHelper.php index 89739dd33e..a46c7ef543 100755 --- a/plugins/baser-core/src/View/Helper/BcBaserHelper.php +++ b/plugins/baser-core/src/View/Helper/BcBaserHelper.php @@ -1255,6 +1255,7 @@ public function footer($data = [], $options = []) * @return void * @checked * @noTodo + * @unitTest */ public function pagination($name = 'default', $data = [], $options = []) { diff --git a/plugins/baser-core/tests/TestCase/View/Helper/BcBaserHelperTest.php b/plugins/baser-core/tests/TestCase/View/Helper/BcBaserHelperTest.php index 041ffa87af..488484c6d7 100644 --- a/plugins/baser-core/tests/TestCase/View/Helper/BcBaserHelperTest.php +++ b/plugins/baser-core/tests/TestCase/View/Helper/BcBaserHelperTest.php @@ -21,7 +21,9 @@ use BaserCore\Test\Scenario\InitAppScenario; use BaserCore\Utility\BcUtil; use BaserCore\View\Helper\BcContentsHelper; +use Cake\Datasource\Paging\PaginatedResultSet; use Cake\Http\Exception\NotFoundException; +use Cake\ORM\ResultSet; use Cake\View\View; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; use BaserCore\Utility\BcFile; @@ -1087,21 +1089,17 @@ public function testFooter() */ public function testPagination() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); - - $this->expectOutputRegex('/