Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ public function getViewVarsForSearch(PaginatedInterface|ResultSetInterface $sear
'query' => $this->parseQuery($request->getQuery('q')),
'contentFolders' => $contentsService->getContentFolderList(
$currentSiteId,
['excludeId' => $contentsService->getSiteRoot($currentSiteId)['id']]
[
'excludeId' => $contentsService->getSiteRoot($currentSiteId)['id'],
'conditions' => $contentsService->getConditionAllowPublish()
]
),
'searchIndexesFront' => $frontForm
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use BcSearchIndex\Controller\SearchIndexesController;
use BcSearchIndex\Service\Front\SearchIndexesFrontServiceInterface;
use BcSearchIndex\Service\SearchIndexesServiceInterface;
use Cake\ORM\TableRegistry;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
Expand Down Expand Up @@ -76,4 +77,39 @@ public function test_getViewVarsForSearch(): void
$this->assertTrue(isset($vars['searchIndexesFront']));
}

/**
* Test getViewVarsForSearch
* contentFolders に公開中のフォルダだけが入る
*
* @return void
*/
public function test_getViewVarsForSearch_contentFoldersPublishedOnly(): void
{
$this->loadFixtureScenario(InitAppScenario::class);
ContentFactory::make()->treeNode(1, 1, null, 'root', '/', 1, true)->setField('type', 'ContentFolder')->persist();
// 公開
ContentFactory::make()->treeNode(2, 1, 1, 'public', '/public/', 2, false, 'public')->setField('type', 'ContentFolder')->persist();
// 非公開
ContentFactory::make()->treeNode(3, 1, 1, 'private', '/private/', 3, false, 'private')->setField('type', 'ContentFolder')
->setField('status', false)->persist();
// 公開期間(終了)
ContentFactory::make()->treeNode(4, 1, 1, 'ended', '/ended/', 4, false, 'ended')->setField('type', 'ContentFolder')
->setField('publish_end', '2000-01-01 00:00:00')->persist();
// 公開期間(開始前)
ContentFactory::make()->treeNode(5, 1, 1, 'future', '/future/', 5, false, 'future')->setField('type', 'ContentFolder')
->setField('publish_begin', '2100-01-01 00:00:00')->persist();
// 非公開のフォルダの下のフォルダ(親に合わせて status が false になる)
ContentFactory::make()->treeNode(6, 1, 3, 'child', '/private/child/', 6, false, 'child')->setField('type', 'ContentFolder')
->setField('status', false)->persist();
TableRegistry::getTableLocator()->get('BaserCore.Contents')->recover();

$controller = new SearchIndexesController($this->getRequest());
$service = $this->getService(SearchIndexesServiceInterface::class);
$frontService = $this->getService(SearchIndexesFrontServiceInterface::class);
$searchIndexes = $controller->paginate($service->getIndex());
$request = $this->getRequest()->withAttribute('currentSite', SiteFactory::get(1))->withQueryParams(['q' => 'test']);
$vars = $frontService->getViewVarsForSearch($searchIndexes, $request);
$this->assertEquals([2], array_keys($vars['contentFolders']));
}

}
Loading