setViewsData example

/** * @covers ::access */
  public function testAccess() {
    $definition = [
      'entity_type' => 'test_entity',
      'field_name' => 'title',
    ];
    $handler = new EntityField([], 'field', $definition$this->entityTypeManager, $this->formatterPluginManager, $this->fieldTypePluginManager, $this->languageManager, $this->renderer, $this->entityRepository, $this->entityFieldManager);
    $handler->view = $this->executable;
    $handler->setViewsData($this->viewsData);

    $this->view->expects($this->atLeastOnce())
      ->method('get')
      ->with('base_table')
      ->willReturn('test_entity_table');

    $this->viewsData->expects($this->atLeastOnce())
      ->method('get')
      ->with('test_entity_table')
      ->willReturn([
        'table' => ['entity type' => 'test_entity'],
      ]);
// Finally, use the 'broken' handler.     return $this->createInstance('broken', ['original_configuration' => $item]);
  }

  /** * {@inheritdoc} */
  public function createInstance($plugin_id, array $configuration = []) {
    $instance = parent::createInstance($plugin_id$configuration);
    if ($instance instanceof HandlerBase) {
      $instance->setModuleHandler($this->moduleHandler);
      $instance->setViewsData($this->viewsData);
    }
    return $instance;
  }

  /** * {@inheritdoc} */
  public function getFallbackPluginId($plugin_id, array $configuration = []) {
    return 'broken';
  }

}
$this->view->expects($this->any())
      ->method('get')
      ->with('base_table')
      ->willReturn('test_entity_type_table');
    $this->viewsData->expects($this->any())
      ->method('get')
      ->with('test_entity_type_table')
      ->willReturn([
        'table' => ['entity type' => 'test_entity_type'],
      ]);
    $handler->setViewsData($this->viewsData);

    $this->assertEquals('test_entity_type', $handler->getEntityType());
  }

  /** * @covers ::getEntityType */
  public function testGetEntityTypeForFieldWithRelationship() {
    $handler = new TestHandler([], 'test_handler', []);

    $options = ['relationship' => 'test_relationship'];
    
Home | Imprint | This part of the site doesn't use cookies.