Skip to content

Commit

Permalink
Merge branch 'dev-5.1' into 5.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Jun 26, 2024
2 parents cff505f + 22039bf commit e469e77
Show file tree
Hide file tree
Showing 22 changed files with 160 additions and 47 deletions.
1 change: 1 addition & 0 deletions plugins/baser-core/src/Model/Entity/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function isTheme()
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public function isAdminTheme(): bool
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/Model/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public function isDeletableUser(EntityInterface $targetUser): bool
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public function isEditableUser(EntityInterface $targetUser): bool
{
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/Model/Validation/BcValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ public static function checkSelectList($value): bool
* @param int $min 値の最短値
* @param int $max 値の最長値
* @param boolean
* @unitTest
*/
public static function between($value, $min, $max)
{
Expand Down
2 changes: 1 addition & 1 deletion plugins/baser-core/src/Service/UtilitiesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected function _verify(Table $table)
$errors = [];

for($i = $min; $i <= $edge; $i++) {
$count = $table->find()->where([
$count = $table->find()->applyOptions(['withDeleted'])->where([
$scope,
'OR' => [$left => $i, $right => $i]
])->count();
Expand Down
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 @@ -1979,6 +1979,7 @@ public static function getExistsWebrootDir(string $theme, string $plugin, string
* @return array Associative array
* @checked
* @noTodo
* @unitTest
*/
public static function pairToAssoc()
{
Expand Down
2 changes: 2 additions & 0 deletions plugins/baser-core/src/View/Helper/BcArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class BcArrayHelper extends Helper
* @return boolean
* @checked
* @noTodo
* @unitTest
*/
public function first($array, int $key)
{
Expand All @@ -65,6 +66,7 @@ public function first($array, int $key)
* @return boolean
* @checked
* @noTodo
* @unitTest
*/
public function last($array, $key)
{
Expand Down
3 changes: 3 additions & 0 deletions plugins/baser-core/src/View/Helper/BcBaserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,7 @@ public function isSSL()
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function charset($charset = null)
{
Expand Down Expand Up @@ -2170,6 +2171,7 @@ public function getBaseUrl()
* @return void
* @checked
* @noTodo
* @UnitTest ラッパーメソッドに付きテスト不要
*/
public function baseUrl()
{
Expand Down Expand Up @@ -2662,6 +2664,7 @@ public function webClipIcon($fileName = 'apple-touch-icon-precomposed.png', $use
* @return string
* @checked
* @noTodo
* @unitTest
*/
public function getContentsUrl($url = null, $full = false, $useSubDomain = null, $base = true)
{
Expand Down
12 changes: 12 additions & 0 deletions plugins/baser-core/tests/TestCase/Model/Entity/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,16 @@ public static function hasTypeDataProvider()
}



public function testIsAdminTheme()
{
//with type = 'AdminTheme'
$this->Plugin->type = 'AdminTheme';
$this->assertTrue($this->Plugin->isAdminTheme());

//with type = 'Plugin'
$this->Plugin->type = 'Plugin';
$this->assertFalse($this->Plugin->isAdminTheme());
}

}
24 changes: 24 additions & 0 deletions plugins/baser-core/tests/TestCase/Model/Entity/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use BaserCore\Model\Entity\User;
use BaserCore\Test\Factory\UserFactory;
use BaserCore\Test\Factory\UsersUserGroupFactory;
use BaserCore\Test\Scenario\InitAppScenario;
use BaserCore\TestSuite\BcTestCase;
use Cake\Core\Configure;
Expand Down Expand Up @@ -65,6 +66,29 @@ public function testSetPassword()
$this->assertNotEquals('testtest', $this->User->password);
}

/**
* test isEditableUser
*/
public function testIsEditableUser()
{
//$isSuper = true, return true
$this->assertTrue($this->User->isEditableUser(UserFactory::make(['id' => 2])->getEntity()));

//$this->id === $targetUser->id、return true
$this->assertTrue($this->User->isEditableUser(UserFactory::make(['id' => 1])->getEntity()));

//isAdminではない場合、return true
$this->assertTrue($this->User->isEditableUser(UserFactory::make(['id' => 3])->getEntity()));

//他のAdminアカウトを編集する場合、return false
Configure::write('BcApp.superUserId', 2);
UserFactory::make(['id' => 4])->persist();
UsersUserGroupFactory::make(['user_id' => 4, 'user_group_id' => 1])->persist();
$user = $this->getTableLocator()->get('BaserCore.Users')->get(4, contain: 'UserGroups');

$this->assertFalse($this->User->isEditableUser($user));
}

/**
* Test isAdmin
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,7 @@ public function test_checkSelectList()
*/
public function testBetween($check, $min, $max, $expect)
{
$this->markTestIncomplete('このテストはまだ実装されていません。');
$result = $this->BcApp->between($check, $min, $max);
$result = $this->BcValidation->between($check, $min, $max);
$this->assertEquals($expect, $result);
}

Expand All @@ -621,7 +620,7 @@ public static function betweenDataProvider()
["あいう", 2, 4, true],
["あいう", 3, 3, true],
["あいう", 4, 3, false],
[["あいう", "あいうえお"], 2, 4, true],
["あいうえお", 2, 4, false],
];
}

Expand Down
15 changes: 15 additions & 0 deletions plugins/baser-core/tests/TestCase/Utility/BcUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1565,4 +1565,19 @@ public function test_isDebug()
Configure::write('debug', false);
$this->assertFalse(BcUtil::isDebug());
}

/**
* test PairToAssoc
*/
public function testPairToAssoc()
{
$result = BcUtil::pairToAssoc('key1', 'value1', 'key2', 'value2', 'key3');
$this->assertEquals(['key1' => 'value1', 'key2' => 'value2', 'key3' => null], $result);

$result = BcUtil::pairToAssoc('key1|value1|key2|value2|key3');
$this->assertEquals(['key1' => 'value1', 'key2' => 'value2', 'key3' => null], $result);

$result = BcUtil::pairToAssoc('');
$this->assertEquals([], $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use BaserCore\TestSuite\BcTestCase;
use BaserCore\View\Helper\BcAdminHelper;
use BaserCore\View\Helper\BcArrayHelper;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Query;
use Cake\View\View;

/**
Expand Down Expand Up @@ -48,22 +50,54 @@ public function tearDown(): void
* 配列の最初のキーを判定する
*
* */
public function testFirst()
public function testFirstWithArray()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->assertTrue($this->Helper->first($this->data, 'b'));
$this->assertFalse($this->Helper->first($this->data, 'c'));
$data = [1 => 'カンジ', 2 => 'リュウジ', 3 => 'スナオ', 4 => 'ゴンチャン'];

$this->assertTrue($this->Helper->first($data, 1));
$this->assertFalse($this->Helper->first($data, 2));

$data = [];
$this->assertFalse($this->Helper->first($data, 1));
}

public function testFirstWithQuery()
{
$mockResultSet = $this->createMock(ResultSetInterface::class);
$mockResultSet->method('first')->willReturn([1 => 'a', 2 => 'b', 3 => 'c']);
$mockResultSet->method('key')->willReturn(1);

$mockQuery = $this->createMock(Query::class);
$mockQuery->method('getIterator')->willReturn($mockResultSet);

$this->assertTrue($this->Helper->first($mockQuery, 1));
$this->assertFalse($this->Helper->first($mockQuery, 2));
}

/**
* 配列の最後のキーを判定する
*
* */
public function testLast()
public function testLastWithArray()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->assertTrue($this->Helper->last($this->data, 'c'));
$this->assertFalse($this->Helper->last($this->data, 'd'));

$this->data = [];
$this->assertFalse($this->Helper->last($this->data, 'c'));
}

public function testLastWithQuery()
{
$mockResultSet = $this->createMock(ResultSetInterface::class);
$mockResultSet->method('count')->willReturn(3);

$mockQuery = $this->createMock(Query::class);
$mockQuery->method('count')->willReturn(3);
$mockQuery->method('getIterator')->willReturn($mockResultSet);

$this->assertTrue($this->Helper->last($mockQuery, 2));
$this->assertFalse($this->Helper->last($mockQuery, 1));
}

/**
Expand Down
40 changes: 19 additions & 21 deletions plugins/baser-core/tests/TestCase/View/Helper/BcBaserHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1283,24 +1283,21 @@ public function testIsSSL()
* @return void
* @dataProvider charsetDataProvider
*/
public function testCharset($expected, $encoding, $url = null)
public function testCharset($expected, $charset , $device)
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');

$this->BcBaser->request = $this->_getRequest($url);
$this->expectOutputString($expected);
if ($encoding !== null) {
$this->BcBaser->charset($encoding);
} else {
$this->BcBaser->charset();
}
$site = SiteFactory::make(['device' => $device])->getEntity();
$this->BcBaser->getView()->setRequest($this->getRequest()->withAttribute('currentSite', $site));
ob_start();
$this->BcBaser->charset($charset);
$result = ob_get_clean();
$this->assertEquals($expected, $result);
}

public static function charsetDataProvider()
{
return [
['<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />', 'UTF-8', '/'],
['<meta http-equiv="Content-Type" content="text/html; charset=Shift-JIS" />', null, '/m/']
['<meta charset="utf-8">','utf-8', 'desktop'],
['<meta charset="Shift-JIS">', null, 'mobile'],
];
}

Expand Down Expand Up @@ -1906,25 +1903,26 @@ public function testGetPluginBaser()
*/
public function testGetContentsUrl()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
SiteFactory::make(['id' => 1, 'domain_type' => 2, 'alias' => 'another.com'])->persist();
ContentFactory::make(['url' => '/news/', 'site_id' => 1])->persist();
// URLが設定されていない場合
$this->BcBaser->request = $this->_getRequest('/news/');
$this->BcBaser = new BcBaserHelper(new View($this->getRequest('/news/')));
$this->assertEquals('/news/', $this->BcBaser->getContentsUrl());
// URLの指定がある場合
$this->BcBaser->request = $this->_getRequest('/');
$this->BcBaser = new BcBaserHelper(new View($this->getRequest('/')));
$this->assertEquals('/news/', $this->BcBaser->getContentsUrl('/news/'));
// サブドメインの指定がない場合
Configure::write('BcEnv.host', 'another.com');
$this->BcBaser->request = $this->_getRequest('/news/');
$siteUrl = Configure::read('BcEnv.siteUrl');
Configure::write('BcEnv.siteUrl', 'http://another.com/');
$this->BcBaser = new BcBaserHelper(new View($this->getRequest('/news/')));
$this->assertEquals('http://another.com/news/', $this->BcBaser->getContentsUrl(null, true));
// サブドメインの指定がある場合
Configure::write('BcEnv.host', 'localhost');
$this->BcBaser->request = $this->_getRequest('/');
$this->assertEquals('http://another.com/news/', $this->BcBaser->getContentsUrl('/another.com/news/', true, true));
$this->BcBaser = new BcBaserHelper(new View($this->getRequest('/')));
$this->assertEquals('http://another.com/news/', $this->BcBaser->getContentsUrl('another.com/news/', true, true));
// サブドメインの指定がないのに指定ありとした場合
$siteUrl = Configure::read('BcEnv.siteUrl');
Configure::write('BcEnv.siteUrl', 'http://main.com');
$this->assertEquals('http://main.com/news/', $this->BcBaser->getContentsUrl('/news/', true, true));
$this->assertEquals('http://main.com/news/', $this->BcBaser->getContentsUrl('/news/', true, false));
Configure::write('BcEnv.siteUrl', $siteUrl);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export default {
*/
formSubmitted: function () {
this.refresh();
this.currentFavorite = null;
this.$refs.modalFavoriteForm.closeModal();
},

Expand All @@ -245,6 +246,7 @@ export default {
case 'FavoriteDelete':
if (!confirm(bcI18n.commonConfirmDeleteMessage)) return false;
var id = this.currentFavorite.id;
let t = this;
$.bcToken.check(function () {
$("#Waiting").show();
axios.post($.bcUtil.apiAdminBaseUrl + "bc-favorite/favorites/delete/" + id + ".json", {}, {
Expand All @@ -253,9 +255,8 @@ export default {
}
}).then(function (response) {
if (response.status === 200) {
$('#FavoriteRow' + id).fadeOut(300, function () {
$(this).remove();
});
t.refresh();
t.currentFavorite = null;
} else {
alert(bcI18n.alertServerError);
}
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit e469e77

Please sign in to comment.