Skip to content

Commit

Permalink
Merge pull request #3886 from HungDV2022/unittest_BcContentsHelper_ge…
Browse files Browse the repository at this point in the history
…tRelatedSiteLinks

BcContentsHelper::getRelatedSiteLinks() ユニットテスト調整
  • Loading branch information
HungDV2022 authored Oct 29, 2024
2 parents d28c946 + 82704ed commit 8db4fb9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
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
3 changes: 3 additions & 0 deletions plugins/baser-core/src/View/Helper/BcContentsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,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
Original file line number Diff line number Diff line change
Expand Up @@ -392,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

0 comments on commit 8db4fb9

Please sign in to comment.