/** * Tests getHandler() without an override. */ public function testGetHandlerNoOverride() { $this->setupMockedFactory(); $item = []; $item['table'] = 'test_table'; $item['field'] = 'test_field'; $views_data = []; $views_data['test_field']['test']['id'] = 'test_id'; $this->viewsData->expects($this->once())->method('get')->with('test_table')->willReturn($views_data); $plugin = $this->getMock('Drupal\\views\\Plugin\\views\\ViewsHandlerInterface'); $this->factory->expects($this->once())->method('createInstance')->with('test_id')->willReturn($plugin); $result = $this->handlerManager->getHandler($item); $this->assertSame($plugin, $result); }
/** * @covers ::addHandler */ public function testAddHandlerWithEntityField() { /** @var \Drupal\views\ViewExecutable|\PHPUnit_Framework_MockObject_MockObject $view */ /** @var \Drupal\views\Plugin\views\display\DisplayPluginBase|\PHPUnit_Framework_MockObject_MockObject $display */ list($view, $display) = $this->setupBaseViewAndDisplay(); $views_data = []; $views_data['table']['entity type'] = 'test_entity_type'; $views_data['test_field'] = ['entity field' => 'test_field', 'field' => ['id' => 'standard'], 'filter' => ['id' => 'standard'], 'argument' => ['id' => 'standard'], 'sort' => ['id' => 'standard']]; $this->viewsData->expects($this->atLeastOnce())->method('get')->with('test_entity')->willReturn($views_data); foreach (['field', 'filter', 'argument', 'sort'] as $handler_type) { $display->expects($this->atLeastOnce())->method('setOption')->with($this->callback(function ($argument) { return $argument; }), ['test_field' => ['id' => 'test_field', 'table' => 'test_entity', 'field' => 'test_field', 'entity_type' => 'test_entity_type', 'entity_field' => 'test_field', 'plugin_id' => 'standard']]); } foreach (['field', 'filter', 'argument', 'sort'] as $handler_type) { $view->addHandler('default', $handler_type, 'test_entity', 'test_field'); } }