/** * Checks if 'synonyms' feature is supported by configured search engine. If not supported displays a notice * * @return void */ protected function checkSearchEngineSupport() { // Display a notice if search engine configuration does not support synonyms $searchEngine = $this->engineResolver->getCurrentSearchEngine(); if (!$this->searchFeatureConfig->isFeatureSupported(\Magento\Framework\Search\SearchEngine\ConfigInterface::SEARCH_ENGINE_FEATURE_SYNONYMS, $searchEngine)) { $this->messageManager->addNoticeMessage(__('Search synonyms are not supported by the %1 search engine. ' . 'Any synonyms you enter won\'t be used.', $searchEngine)); } }
/** * Removes 'Search Synonyms' from the menu if 'synonyms' is not supported * * @param Builder $subject * @param Menu $menu * @return Menu * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterGetResult(Builder $subject, Menu $menu) { $searchEngine = $this->engineResolver->getCurrentSearchEngine(); if (!$this->searchFeatureConfig->isFeatureSupported(ConfigInterface::SEARCH_ENGINE_FEATURE_SYNONYMS, $searchEngine)) { // "Search Synonyms" feature is not supported by the current configured search engine. // Menu will be updated to remove it from the list $menu->remove(self::SEARCH_SYNONYMS_MENU_ITEM_ID); } return $menu; }
public function testAfterGetResult() { $this->engineResolver->expects($this->once())->method('getCurrentSearchEngine')->willReturn('mysql'); $this->searchFeatureConfig->expects($this->once())->method('isFeatureSupported')->with('synonyms', 'mysql')->willReturn(false); /** @var \Magento\Backend\Model\Menu $menu */ $menu = $this->getMock('\\Magento\\Backend\\Model\\Menu', [], [], '', false); $menu->expects($this->once())->method('remove')->willReturn(true); /** @var \Magento\Backend\Model\Menu\Builder $menuBuilder */ $menuBuilder = $this->getMock('\\Magento\\Backend\\Model\\Menu\\Builder', [], [], '', false); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); /** @var \Magento\Search\Model\SearchEngine\MenuBuilder $searchMenuBuilder */ $searchMenuBuilder = $objectManager->getObject('Magento\\Search\\Model\\SearchEngine\\MenuBuilder', ['searchFeatureConfig' => $this->searchFeatureConfig, 'engineResolver' => $this->engineResolver]); $this->assertInstanceOf('\\Magento\\Backend\\Model\\Menu', $searchMenuBuilder->afterGetResult($menuBuilder, $menu)); }
/** * Test getCurrentSearchEngine */ public function testGetCurrentSearchEngine() { $engine = 'mysql'; $this->scopeConfig->expects($this->any())->method('getValue')->willReturn($engine); $this->assertEquals($engine, $this->model->getCurrentSearchEngine()); }