Skip to content

Commit

Permalink
Merge branch '5.1.x' of github.com:baserproject/basercms into 5.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Sep 12, 2024
2 parents c32e26b + b470c8d commit bc42c5f
Show file tree
Hide file tree
Showing 22 changed files with 552 additions and 36 deletions.
1 change: 1 addition & 0 deletions plugins/baser-core/src/Event/BcEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public function implementedEvents(): array
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public function isAction($action, $isContainController = true)
{
Expand Down
3 changes: 3 additions & 0 deletions plugins/baser-core/src/Utility/BcAbstractDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function __construct($name, array $config)
* @return BcAbstractDetector|null
* @checked
* @noTodo
* @unitTest
*/
public static function find($name)
{
Expand All @@ -93,6 +94,7 @@ public static function find($name)
* @return BcAbstractDetector[]
* @checked
* @noTodo
* @unitTest
*/
public static function findAll()
{
Expand All @@ -116,6 +118,7 @@ public static function findAll()
* @return BcAbstractDetector|null
* @checked
* @noTodo
* @unitTest
*/
public static function findCurrent()
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/Utility/BcFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ public function read($sort = true, $exceptions = false, $fullPath = false)
* @return string
* @checked
* @noTodo
* @unitTest
*/
public function pwd(): string
{
Expand Down
4 changes: 4 additions & 0 deletions plugins/baser-core/src/Utility/BcLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class BcLang extends BcAbstractDetector
* @return void
* @checked
* @noTodo
* @unitTest
*/
protected function _setConfig(array $config)
{
Expand All @@ -55,6 +56,7 @@ protected function _setConfig(array $config)
* @return array
* @checked
* @noTodo
* @unitTest
*/
protected function _getDefaultConfig()
{
Expand All @@ -69,6 +71,7 @@ protected function _getDefaultConfig()
* @return string
* @checked
* @noTodo
* @unitTest
*/
public function getDetectorRegex()
{
Expand All @@ -82,6 +85,7 @@ public function getDetectorRegex()
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public function isMatchDecisionKey()
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/Utility/BcSiteConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class BcSiteConfig
* @return mixed
* @checked
* @noTodo
* @unitTest
*/
public static function get($key)
{
Expand Down
5 changes: 4 additions & 1 deletion plugins/baser-core/src/View/Helper/BcAdminHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ public function existsPublishLink()
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public function existsAddLink()
{
Expand Down Expand Up @@ -477,6 +478,7 @@ public function editLink(): void
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function addLink(): void
{
Expand Down Expand Up @@ -520,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');
}

Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/View/Helper/BcAuthHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ public function getCurrentLoginUser()
* @return boolean
* @checked
* @noTodo
* @unitTest
*/
public function isSuperUser(): bool
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/View/Helper/BcBaserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,7 @@ public function footer($data = [], $options = [])
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function pagination($name = 'default', $data = [], $options = [])
{
Expand Down
35 changes: 35 additions & 0 deletions plugins/baser-core/tests/TestCase/Event/BcEventListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
];
}
}
103 changes: 103 additions & 0 deletions plugins/baser-core/tests/TestCase/Utility/BcAbstractDetectorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?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\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()
{
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);
}

/**
* test findCurrent
* @param string $agent ユーザーエージェント名
* @param string $expect 期待値
*
* @dataProvider findCurrentDataProvider
*/
public function testFindCurrent($agent, $expect)
{
$_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],
];
}
}
25 changes: 22 additions & 3 deletions plugins/baser-core/tests/TestCase/Utility/BcFolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
['', ''],
];
}
}
Loading

0 comments on commit bc42c5f

Please sign in to comment.