You are here

public function SqlTest::testLoadEntitiesWithRevision in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php \Drupal\Tests\views\Unit\Plugin\query\SqlTest::testLoadEntitiesWithRevision()
  2. 9 core/modules/views/tests/src/Unit/Plugin/query/SqlTest.php \Drupal\Tests\views\Unit\Plugin\query\SqlTest::testLoadEntitiesWithRevision()

@covers ::loadEntities @covers ::assignEntitiesToResult

File

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

Class

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

Namespace

Drupal\Tests\views\Unit\Plugin\query

Code

public function testLoadEntitiesWithRevision() {

  // We don't use prophecy, because prophecy enforces methods.
  $view = $this
    ->getMockBuilder(ViewExecutable::class)
    ->disableOriginalConstructor()
    ->getMock();
  $view_entity = $this
    ->prophesize(ViewEntityInterface::class);
  $view_entity
    ->get('base_table')
    ->willReturn('entity_first__revision');
  $view_entity
    ->get('base_field')
    ->willReturn('vid');
  $view->storage = $view_entity
    ->reveal();
  $entity_revisions = [
    'first' => [
      1 => $this
        ->prophesize(EntityInterface::class)
        ->reveal(),
      3 => $this
        ->prophesize(EntityInterface::class)
        ->reveal(),
    ],
  ];
  $entity_type_manager = $this
    ->setupEntityTypes([], $entity_revisions);
  $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([
    'vid' => 1,
  ]);
  $result[] = new ResultRow([
    'vid' => 1,
  ]);
  $result[] = new ResultRow([
    'vid' => 3,
  ]);
  $query
    ->addField('entity_first__revision', 'vid', 'vid');
  $query
    ->loadEntities($result);
  $this
    ->assertSame($entity_revisions['first'][1], $result[0]->_entity);
  $this
    ->assertSame($entity_revisions['first'][1], $result[1]->_entity);
  $this
    ->assertSame($entity_revisions['first'][3], $result[2]->_entity);
}