diff --git a/plugins/bc-search-index/src/Service/Front/SearchIndexesFrontService.php b/plugins/bc-search-index/src/Service/Front/SearchIndexesFrontService.php index aac076ef19..067b2447fd 100644 --- a/plugins/bc-search-index/src/Service/Front/SearchIndexesFrontService.php +++ b/plugins/bc-search-index/src/Service/Front/SearchIndexesFrontService.php @@ -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 ]; diff --git a/plugins/bc-search-index/tests/TestCase/Service/Front/SearchIndexesFrontServiceTest.php b/plugins/bc-search-index/tests/TestCase/Service/Front/SearchIndexesFrontServiceTest.php index a11f5cbf4e..a90ec093ba 100644 --- a/plugins/bc-search-index/tests/TestCase/Service/Front/SearchIndexesFrontServiceTest.php +++ b/plugins/bc-search-index/tests/TestCase/Service/Front/SearchIndexesFrontServiceTest.php @@ -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; /** @@ -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'])); + } + }