/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); // TODO: Change the autogenerated stub $condition_plugin_manager = $this->getMock('Drupal\\Core\\Executable\\ExecutableManagerInterface'); $condition_plugin_manager->expects($this->any())->method('getDefinitions')->will($this->returnValue(array())); $container = new ContainerBuilder(); $container->set('plugin.manager.condition', $condition_plugin_manager); \Drupal::setContainer($container); $this->executable = $this->getMockBuilder('Drupal\\views\\ViewExecutable')->disableOriginalConstructor()->setMethods(['buildRenderable', 'setDisplay', 'setItemsPerPage'])->getMock(); $this->executable->expects($this->any())->method('setDisplay')->with('block_1')->will($this->returnValue(TRUE)); $this->executable->expects($this->any())->method('getShowAdminLinks')->willReturn(FALSE); $this->executable->display_handler = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\Block')->disableOriginalConstructor()->setMethods(NULL)->getMock(); $this->view = $this->getMockBuilder('Drupal\\views\\Entity\\View')->disableOriginalConstructor()->getMock(); $this->view->expects($this->any())->method('id')->willReturn('test_view'); $this->executable->storage = $this->view; $this->executableFactory = $this->getMockBuilder('Drupal\\views\\ViewExecutableFactory')->disableOriginalConstructor()->getMock(); $this->executableFactory->expects($this->any())->method('get')->with($this->view)->will($this->returnValue($this->executable)); $this->displayHandler = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\Block')->disableOriginalConstructor()->getMock(); $this->displayHandler->expects($this->any())->method('blockSettings')->willReturn([]); $this->displayHandler->expects($this->any())->method('getPluginId')->willReturn('block'); $this->executable->display_handler = $this->displayHandler; $this->storage = $this->getMockBuilder('Drupal\\Core\\Config\\Entity\\ConfigEntityStorage')->disableOriginalConstructor()->getMock(); $this->storage->expects($this->any())->method('load')->with('test_view')->will($this->returnValue($this->view)); $this->account = $this->getMock('Drupal\\Core\\Session\\AccountInterface'); }
/** * Tests the build method with overriding items per page. */ public function testBuildOverride() { $this->executable->expects($this->once())->method('setItemsPerPage')->with(5); $this->blockPlugin->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('items_per_page' => 5))); $this->blockDisplay->preBlockBuild($this->blockPlugin); }
/** * Exposed widgets typically only work with ajax in Drupal core, however * #2605218 totally breaks the rest of the functionality in this display and * in Core's Block display as well, so we allow non-ajax block views to use * exposed filters and manually set the #action to the current request uri. */ public function elementPreRender(array $element) { /** @var \Drupal\views\ViewExecutable $view */ $view = $element['#view']; if (!empty($view->exposed_widgets['#action']) && !$view->ajaxEnabled()) { $view->exposed_widgets['#action'] = \Drupal::request()->getRequestUri(); } return parent::elementPreRender($element); }
/** * {@inheritdoc} */ public function query() { parent::query(); $query = $this->view->query; if (!$query instanceof SearchApiQuery) { return; } $facet_field = $this->getOption('facet_field'); if (!$facet_field) { return; } $base_path = $this->getOption('linked_path'); if (!$base_path) { $base_path = $_GET['q']; } $limit = empty($query->pager->options['items_per_page']) ? 10 : $query->pager->options['items_per_page']; $query_options =& $query->getOptions(); if (!$this->getOption('hide_block')) { // If we hide the block, we don't need this extra facet. $query_options['search_api_facets']['search_api_views_facets_block'] = array('field' => $facet_field, 'limit' => $limit, 'missing' => FALSE, 'min_count' => 1); } $query_options['search_api_base_path'] = $base_path; $query->range(0, 0); }