function SqlTest::testLoadEntitiesWithNoRelationshipAndNoRevision

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php \Drupal\Tests\views\Unit\Plugin\query\SqlTest::testLoadEntitiesWithNoRelationshipAndNoRevision()
  2. 10 core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php \Drupal\Tests\views\Unit\Plugin\query\SqlTest::testLoadEntitiesWithNoRelationshipAndNoRevision()
  3. 11.x core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php \Drupal\Tests\views\Unit\Plugin\query\SqlTest::testLoadEntitiesWithNoRelationshipAndNoRevision()

@covers ::loadEntities @covers ::assignEntitiesToResult

File

core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php, line 273

Class

SqlTest
@coversDefaultClass \Drupal\views\Plugin\views\query\Sql

Namespace

Drupal\Tests\views\Unit\Plugin\query

Code

public function testLoadEntitiesWithNoRelationshipAndNoRevision() {
    $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();
    $entities = [
        'first' => [
            1 => $this->prophesize(EntityInterface::class)
                ->reveal(),
            2 => $this->prophesize(EntityInterface::class)
                ->reveal(),
        ],
    ];
    $entity_type_manager = $this->setupEntityTypes($entities);
    $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 = [];
    $result[] = new ResultRow([
        'id' => 1,
    ]);
    // Note: Let the same entity be returned multiple times, for example to
    // support the translation usecase.
    $result[] = new ResultRow([
        'id' => 2,
    ]);
    $result[] = new ResultRow([
        'id' => 2,
    ]);
    $query->addField('entity_first', 'id', 'id');
    $query->loadEntities($result);
    $this->assertSame($entities['first'][1], $result[0]->_entity);
    $this->assertSame($entities['first'][2], $result[1]->_entity);
    $this->assertSame($entities['first'][2], $result[2]->_entity);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.