You are here

public function LayoutBuilderMigrationTest::testBuildBatch in Panelizer 8.5

File

tests/src/Kernel/LayoutBuilderMigrationTest.php, line 87

Class

LayoutBuilderMigrationTest
@coversDefaultClass \Drupal\panelizer\LayoutBuilderMigration

Namespace

Drupal\Tests\panelizer\Kernel

Code

public function testBuildBatch() {
  $display = $this
    ->prophesize(LayoutEntityDisplayInterface::class);
  $display
    ->id()
    ->willReturn('test');
  $display
    ->getTargetEntityTypeId()
    ->willReturn('node');
  $display
    ->getTargetBundle()
    ->willReturn('page');
  $entity_type = $this->container
    ->get('entity_type.manager')
    ->getDefinition('node');

  // Mock a query that will return particular results.
  $results = [
    1 => 1,
    2 => 1,
    3 => 2,
    4 => 2,
    5 => 2,
  ];
  $query = $this
    ->prophesize(QueryInterface::class);
  $the_query = $query
    ->reveal();
  $query
    ->exists('panelizer')
    ->willReturn($the_query);
  $query
    ->condition('panelizer.view_mode', 'full')
    ->willReturn($the_query);
  $query
    ->condition('type', 'page')
    ->shouldBeCalled();
  $query
    ->allRevisions()
    ->shouldBeCalled();
  $query
    ->execute()
    ->willReturn($results);
  $query_factory = $this
    ->prophesize()
    ->willExtend(QueryFactory::class);
  $query_factory
    ->get($entity_type, 'AND')
    ->willReturn($query
    ->reveal());
  $this->container
    ->set('entity.query.sql', $query_factory
    ->reveal());
  $batch = LayoutBuilderMigration::fromDisplay($display
    ->reveal())
    ->toArray();
  $operations = array_values(array_slice($batch['operations'], 1));
  $this
    ->assertCount(5, $operations);
  foreach (array_keys($results) as $i => $revision_id) {
    $arguments = $operations[$i][1];
    $this
      ->assertSame($revision_id, $arguments[1]);
  }
}