Skip to content

Commit

Permalink
Merge branch 'dev-5.1' of github.com:baserproject/basercms into dev-5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Jun 26, 2024
2 parents 25ecb7e + a2d9ec0 commit 22039bf
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 39 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
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
1 change: 1 addition & 0 deletions plugins/bc-mail/src/View/Helper/MaildataHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class MaildataHelper extends BcTextHelper
* @return string メール用データ
* @checked
* @noTodo
* @unitTest
*/
public function control($type, $value, $escape = true)
{
Expand Down
1 change: 1 addition & 0 deletions plugins/bc-mail/src/View/Helper/MailfieldHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function getAttributes($data)
* @return array コントロールソース
* @checked
* @noTodo
* @unitTest
*/
public function getOptions($data)
{
Expand Down
26 changes: 18 additions & 8 deletions plugins/bc-mail/tests/TestCase/View/Helper/MaildataHelperTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace BcMail\Test\TestCase\View\Helper;
use BaserCore\TestSuite\BcTestCase;
use BcMail\View\Helper\MaildataHelper;
use Cake\View\View;

class MaildataHelperTest extends BcTestCase
{
Expand All @@ -11,26 +13,34 @@ class MaildataHelperTest extends BcTestCase
public function setUp():void
{
parent::setUp();
// $this->View = new BcAppView(null);
// $this->View->request = $this->_getRequest('/');
// $this->Maildata = new MaildataHelper($this->View);
$this->MaildataHelper = new MaildataHelper(new View());
}

/**
* tear down
*/
public function tearDown():void
{
// unset($this->Maildata);
unset($this->MaildataHelper);
parent::tearDown();
}
/**
* メール表示用のデータを出力する
*
* public function testControl() {
* $this->markTestIncomplete('このメソッドは、同一クラス内のメソッドをラッピングしているメソッドのためスキップします。');
* }
* @dataProvider controlDataProvider
*/
public function testControl($type, $value, $escape, $expected)
{
$result = $this->MaildataHelper->control($type, $value, $escape);
$this->assertEquals($expected, $result);
}

public static function controlDataProvider()
{
return [
['text' , '<b>bold</b>', true, ' &lt;b&gt;bold&lt;/b&gt;'],
['text' , '<b>bold</b>', false, ' <b>bold</b>'],
];
}

/**
* メール表示用のデータを出力する
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace BcMail\Test\TestCase\View\Helper;

use BaserCore\TestSuite\BcTestCase;
use BcMail\Test\Factory\MailFieldsFactory;
use BcMail\View\Helper\MailfieldHelper;
use Cake\View\View;

Expand Down Expand Up @@ -59,6 +60,14 @@ public static function getAttributesProvider()
*/
public function testGetOptions()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
//with source data not empty
$mailField = MailFieldsFactory::make(['source' => '資料請求|問い合わせ|その他'])->getEntity();
$result = $this->mailfieldHelper->getOptions($mailField);
$this->assertEquals(['資料請求' => '資料請求', '問い合わせ' => '問い合わせ', 'その他' => 'その他'], $result);

//with source data empty
$mailField = MailFieldsFactory::make(['source' => ''])->getEntity();
$result = $this->mailfieldHelper->getOptions($mailField);
$this->assertEquals([], $result);
}
}

0 comments on commit 22039bf

Please sign in to comment.