setupEntityTypes example

/** * @covers ::loadEntities * @covers ::assignEntitiesToResult */
  public function testLoadEntitiesWithEmptyResult() {
    $view = $this->prophesize('Drupal\views\ViewExecutable')->reveal();
    $view_entity = $this->prophesize(ViewEntityInterface::class);
    $view_entity->get('base_table')->willReturn('entity_first');
    $view_entity->get('base_field')->willReturn('id');
    $view->storage = $view_entity->reveal();

    $entity_type_manager = $this->setupEntityTypes();
    $date_sql = $this->prophesize(DateSqlInterface::class);
    $messenger = $this->prophesize(MessengerInterface::class);

    $query = new Sql([], 'sql', []$entity_type_manager->reveal()$date_sql->reveal()$messenger->reveal());
    $query->view = $view;

    $result = [];
    $query->addField('entity_first', 'id', 'id');
    $query->loadEntities($result);
    $this->assertEmpty($result);
  }

  
/** * Tests setRouteOptions() with an entity type parameter. * * @covers ::setRouteOptions * @covers ::getControllerClass * @covers ::getEntityTypes * @covers ::setParametersFromReflection * * @dataProvider providerTestSetRouteOptionsWithEntityTypeNoUpcasting */
  public function testSetRouteOptionsWithEntityTypeNoUpcasting($controller) {
    $this->setupEntityTypes();

    $route = new Route('/example/{entity_test}', [
      '_controller' => $controller,
    ]);

    $defaults = $route->getDefaults();
    $this->entityResolverManager->setRouteOptions($route);
    $this->assertEquals($defaults$route->getDefaults());
    $this->assertEmpty($route->getOption('parameters'));
  }

  
protected $routeSubscriber;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
    $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class);
    $this->routeSubscriber = new ContentModerationRouteSubscriber($entity_type_manager);
    $this->setupEntityTypes();
  }

  /** * Creates the entity type manager mock returning entity type objects. */
  protected function setupEntityTypes() {
    $definition = $this->createMock(EntityTypeInterface::class);
    $definition->expects($this->any())
      ->method('getClass')
      ->willReturn(TestEntity::class);
    $definition->expects($this->any())
      
Home | Imprint | This part of the site doesn't use cookies.