Skip to content

Commit

Permalink
Merge branch '5.1.x' into unitTest_BcThemeConfigControllerEventListen…
Browse files Browse the repository at this point in the history
…er_baserCoreThemesAfterApply
  • Loading branch information
thangnn committed Oct 29, 2024
2 parents 4d03858 + a8a907d commit 543fe84
Show file tree
Hide file tree
Showing 19 changed files with 311 additions and 99 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ node_modules
# db
/db/*
!/db/.gitkeep
# profiler
/profiler/*
# etc
LOCAL_TODO.md
LOCAL_Q&A.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function offAlias(): void
* アソシエーション時に alias を含める
* @checked
* @noTodo
* @unitTest
*/
public function onAlias(): void
{
Expand Down
2 changes: 1 addition & 1 deletion plugins/baser-core/src/Model/Table/ContentsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ public function getRelatedSiteContents(int $id, array $options = []): array
['Sites.status' => true]
];
if ($options['excludeIds']) {
$conditions['Contents.site_id <>'] = $options['excludeIds'];
$conditions['Contents.site_id NOT IN'] = $options['excludeIds'];
}
$conditions = array_merge($conditions, $this->getConditionAllowPublish());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public function getViewVarsForAdd()
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public function isPluginsDirWritable()
{
Expand Down
4 changes: 4 additions & 0 deletions plugins/baser-core/src/View/Helper/BcContentsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ public function getCurrentRelatedSiteUrl($siteName)
* - `siteId` : サイトID
* @checked
* @noTodo
* @unitTest
*/
public function getTree(int $id = 1, ?int $level = null, array $options = []): ResultSetDecorator
{
Expand Down Expand Up @@ -402,6 +403,9 @@ public function getRelatedSiteContents(?int $id = null, array $options = []): ar
*
* @param int $id
* @return array
* @noTodo
* @checked
* @unitTest
*/
public function getRelatedSiteLinks($id = null, $options = [])
{
Expand Down
8 changes: 6 additions & 2 deletions plugins/baser-core/src/View/Helper/BcFreezeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function text(string $fieldName, array $options = []): string
$field = $fieldName;
}
if (isset($options)) {
$options = $options + ['type' => 'hidden'];
$options = array_merge($options, ['type' => 'hidden']);
} else {
$options = ['type' => 'hidden'];
}
Expand Down Expand Up @@ -349,7 +349,11 @@ public function textarea($fieldName, $options = []): string
} else {
$field = $fieldName;
}
$options = $options + ['type' => 'hidden'];
if (isset($options)) {
$options = array_merge($options, ['type' => 'hidden']);
} else {
$options = ['type' => 'hidden'];
}
if (isset($options["value"])) {
$value = $options["value"];
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function setUp(): void
$this->table->setPrimaryKey(['id']);
$this->table->addBehavior('BaserCore.BcContents');
$this->contentService = new ContentsService();
$this->BcContentsBehavior = new BcContentsBehavior($this->table);
}

/**
Expand Down Expand Up @@ -200,4 +201,17 @@ public function testAfterDelete()

}

/**
* test onAlias
*/
public function testOnAlias()
{
$this->BcContentsBehavior->onAlias();

$conditions = $this->BcContentsBehavior->Contents->getConditions();

$this->assertArrayHasKey('Contents.type', $conditions);
$this->assertEquals('ContentFolder', $conditions['Contents.type']);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,13 @@ public function test_getViewVarsForAdd()
$this->assertTrue(isset($vars['isPluginsDirWritable']));
}

/**
* test isPluginsDirWritable
*/
public function test_isPluginsDirWritable()
{
$result = $this->PluginsAdmin->isPluginsDirWritable();
$this->assertTrue($result);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -125,36 +125,54 @@ public function test_getExistsTitles()
* @param string $message テストが失敗した時に表示されるメッセージ
* @dataProvider getPageListDataProvider
*/
public function testGetTree($id, $level, $expectedCount, $expectedTitle, $message = null)
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$result = $this->BcContents->getTree($id, $level);
public function testGetTree($id, $level, $expectedCount, $expectedTitle)
{
$this->truncateTable('contents');
//データ生成
ContentFactory::make(['id' => 1, 'lft' => 1, 'rght' => 100, 'site_root' => true])->persist();
//'id' => 1の子
ContentFactory::make(['id' => 2, 'lft' => 2, 'rght' => 14, 'title' => 'トップページ', 'parent_id' => 1])->persist();
ContentFactory::make(['id' => 3, 'lft' => 15, 'rght' => 16, 'parent_id' => 1])->persist();
ContentFactory::make(['id' => 4, 'lft' => 17, 'rght' => 18, 'parent_id' => 1])->persist();
ContentFactory::make(['id' => 5, 'lft' => 19, 'rght' => 20, 'parent_id' => 1])->persist();

//'id' => 2の子
ContentFactory::make(['id' => 6, 'lft' => 3, 'rght' => 7, 'title' => 'サービス', 'parent_id' => 2])->persist();
ContentFactory::make(['id' => 7, 'lft' => 8, 'rght' => 9, 'parent_id' => 2])->persist();
ContentFactory::make(['id' => 8, 'lft' => 10, 'rght' => 11, 'parent_id' => 2])->persist();
ContentFactory::make(['id' => 9, 'lft' => 12, 'rght' => 13, 'parent_id' => 2])->persist();
//'id' => 6の子
ContentFactory::make(['id' => 10, 'lft' => 5, 'rght' => 6, 'title' => 'サブサービス1', 'parent_id' => 6])->persist();
//'id' => 3の子

$result = $this->BcContents->getTree($id, $level)->toArray();

$resultTitle = null;
$resultCount = null;
switch($level) {
switch ($level) {
case 1:
if (!empty($result[0]['Content']['title'])) {
$resultTitle = $result[0]['Content']['title'];
if (!empty($result[0]['title'])) {
$resultTitle = $result[0]['title'];
$resultCount = count($result);
}
break;
case 2:
if ($result) {
foreach($result as $data) {
foreach ($result as $data) {
if ($data['children']) {
$resultTitle = $data['children'][0]['Content']['title'];
$resultTitle = $data['children'][0]['title'];
$resultCount = count($data['children']);
}
}
}
break;
case 3:
if ($result) {
foreach($result as $data) {
foreach ($result as $data) {
if ($data['children']) {
foreach($data['children'] as $data2) {
foreach ($data['children'] as $data2) {
if ($data2['children']) {
$resultTitle = $data2['children'][0]['Content']['title'];
$resultTitle = $data2['children'][0]['title'];
$resultCount = count($data2['children']);
}
}
Expand All @@ -163,22 +181,19 @@ public function testGetTree($id, $level, $expectedCount, $expectedTitle, $messag
}
break;
}
$this->assertEquals($expectedCount, $resultCount, 'カウントエラー:' . $message);
$this->assertEquals($expectedTitle, $resultTitle, 'タイトルエラー:' . $message);
$this->assertEquals($expectedCount, $resultCount);
$this->assertEquals($expectedTitle, $resultTitle);
}

public static function getPageListDataProvider()
{
return [
// PC版
[1, 1, 7, 'トップページ', 'PC版1階層目のデータが正常に取得できません'],
[1, 2, 4, 'サービス', 'PC版2階層目のデータが正常に取得できません'],
[1, 3, 1, 'サブサービス1', 'PC版3階層目のデータが正常に取得できません'],
[1, 1, 4, 'トップページ'],
[1, 2, 4, 'サービス'],
[1, 3, 1, 'サブサービス1'],
// ケータイ
[2, 1, 3, 'トップページ', 'ケータイ版1階層目のデータが正常に取得できません'],
// スマホ
[3, 1, 7, 'トップページ', 'スマホ版1階層目のデータが正常に取得できません'],
[3, 2, 1, 'サービス1', 'スマホ版2階層目のデータが正常に取得できません']
[2, 1, 4, 'サービス']
];
}

Expand Down Expand Up @@ -377,28 +392,22 @@ public static function getRelatedSiteContentsDataProvider()
*/
public function testGetRelatedSiteLinks($id, $options, $expect)
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$this->BcContents->request = $this->_getRequest('/');
$_SERVER['HTTP_USER_AGENT'] = 'iPhone';
ContentFactory::make(['site_id' => 1, 'url' => '/'])->persist();
ContentFactory::make(['site_id' => 2, 'main_site_content_id' => 1, 'url' => '/en/'])->persist();
ContentFactory::make(['site_id' => 3, 'main_site_content_id' => 3, 'url' => '/en/about'])->persist();

$result = $this->BcContents->getRelatedSiteLinks($id, $options);
$this->assertEquals($expect, $result);
}

public static function getRelatedSiteLinksDataProvider()
{
return [
// IDが空 オプションも空
[null, [], [['prefix' => '', 'name' => 'パソコン', 'url' => '/index'], ['prefix' => 'mobile', 'name' => 'ケータイ', 'url' => '/m/index'], ['prefix' => 'smartphone', 'name' => 'スマートフォン', 'url' => '/s/index']]],
// IDが空 オプション excludeIds 0~2
['', ['excludeIds' => [0]], [0 => ['prefix' => 'mobile', 'name' => 'ケータイ', 'url' => '/m/index'], 1 => ['prefix' => 'smartphone', 'name' => 'スマートフォン', 'url' => '/s/index']]],
[false, ['excludeIds' => [1]], [['prefix' => '', 'name' => 'パソコン', 'url' => '/index'], ['prefix' => 'smartphone', 'name' => 'スマートフォン', 'url' => '/s/index']]],
[0, ['excludeIds' => [2]], [['prefix' => '', 'name' => 'パソコン', 'url' => '/index'], ['prefix' => 'mobile', 'name' => 'ケータイ', 'url' => '/m/index']]],
// IDが空 オプション excludeIds 3~
[0, ['excludeIds' => [3]], [['prefix' => '', 'name' => 'パソコン', 'url' => '/index'], ['prefix' => 'mobile', 'name' => 'ケータイ', 'url' => '/m/index'], ['prefix' => 'smartphone', 'name' => 'スマートフォン', 'url' => '/s/index']]],
[0, ['excludeIds' => [99]], [['prefix' => '', 'name' => 'パソコン', 'url' => '/index'], ['prefix' => 'mobile', 'name' => 'ケータイ', 'url' => '/m/index'], ['prefix' => 'smartphone', 'name' => 'スマートフォン', 'url' => '/s/index']]],
// IDに値が入っていれば、false
[1, ['excludeIds' => [0]], [['prefix' => 'mobile', 'name' => 'ケータイ', 'url' => '/m/'], ['prefix' => 'smartphone', 'name' => 'スマートフォン', 'url' => '/s/']]],
[99, [], []],
[null, [], [['prefix' => '', 'name' => 'メインサイト', 'url' => '/index']]],
[0, [], [['prefix' => '', 'name' => 'メインサイト', 'url' => '/index']]],
[1, [], [['prefix' => '', 'name' => 'メインサイト', 'url' => '/'], ['prefix' => 'en', 'name' => '英語サイト', 'url' => '/en/']]],
[1, ['excludeIds' => [1]], [['prefix' => 'en', 'name' => '英語サイト', 'url' => '/en/']]],
[3, [], [['prefix' => 'en', 'name' => '英語サイト', 'url' => '/en/about']]],
];
}

Expand Down Expand Up @@ -910,4 +919,5 @@ public function test_isFolder()
$rs = $this->BcContents->isFolder();
$this->assertTrue($rs);
}

}
3 changes: 3 additions & 0 deletions plugins/bc-blog/src/Service/BlogContentsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ public function getContentsTemplateRelativePath(array $options): string
*
* @param string $url
* @return EntityInterface|null
* @checked
* @noTodo
* @unitTest
*/
public function findByUrl(string $url): ?EntityInterface
{
Expand Down
19 changes: 19 additions & 0 deletions plugins/bc-blog/tests/TestCase/Service/BlogContentsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,23 @@ public function test_findByContentId()
$rs = $this->BlogContentsService->findByContentId(999);
$this->assertNull($rs);
}
/**
* test findByUrl
*/
public function test_findByUrl()
{
//generate data
BlogContentFactory::make(['id' => 1])->persist();
ContentFactory::make(['id' => 1, 'type' => 'BlogContent', 'entity_id' => 1, 'title' => 'url test', 'url' => '/test', 'site_id' => 1])->persist();
ContentFactory::make(['id' => 2, 'type' => 'BlogContent', 'entity_id' => 1,'title' => 'url demo', 'url' => '/demo', 'site_id' => 1])->persist();
SiteFactory::make(['id' => 1, 'theme' => 'BcBlog'])->persist();

$rs = $this->BlogContentsService->findByUrl('/test');
$this->assertEquals('url test', $rs->content->title);

//with empty url
$rs = $this->BlogContentsService->findByUrl('');
$this->assertNull($rs);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,11 @@ public function readDbSetting(ServerRequest $request, array $installationData =
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public function deleteAllTables(ServerRequest $request): bool
{
$dbConfig = $this->readDbSetting($request);
if (!$dbConfig) {
$dbConfig = ConnectionManager::getConfig('default');
}
return $this->BcDatabase->deleteTables('default', $dbConfig);
}

Expand Down Expand Up @@ -281,6 +279,7 @@ public function initAdmin(ServerRequest $request): void
* @param ServerRequest $request
* @checked
* @noTodo
* @unitTest
*/
public function initFiles(ServerRequest $request): void
{
Expand All @@ -301,6 +300,7 @@ public function initFiles(ServerRequest $request): void
* @return \Cake\Datasource\ConnectionInterface
* @checked
* @noTodo
* @unitTest
*/
public function connectDb(ServerRequest $request): \Cake\Datasource\ConnectionInterface
{
Expand All @@ -316,6 +316,7 @@ public function connectDb(ServerRequest $request): \Cake\Datasource\ConnectionIn
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function login(ServerRequest $request, Response $response): void
{
Expand All @@ -332,6 +333,7 @@ public function login(ServerRequest $request, Response $response): void
* @param ServerRequest $request
* @checked
* @noTodo
* @unitTest
*/
public function initDb(ServerRequest $request): void
{
Expand Down
1 change: 1 addition & 0 deletions plugins/bc-installer/src/Service/InstallationsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ public function setSiteName(string $name)
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public function executeDefaultUpdates(): bool
{
Expand Down
Loading

0 comments on commit 543fe84

Please sign in to comment.