You are here

public function PageTest::testGetVariants in Page Manager 8

Same name and namespace in other branches
  1. 8.4 tests/src/Unit/PageTest.php \Drupal\Tests\page_manager\Unit\PageTest::testGetVariants()

@covers ::getVariants

File

tests/src/Unit/PageTest.php, line 49
Contains \Drupal\Tests\page_manager\Unit\PageTest.

Class

PageTest
Tests the Page entity.

Namespace

Drupal\Tests\page_manager\Unit

Code

public function testGetVariants() {
  $variant1 = $this
    ->prophesize(PageVariantInterface::class);
  $variant1
    ->id()
    ->willReturn('variant1');
  $variant1
    ->getWeight()
    ->willReturn(0);
  $variant2 = $this
    ->prophesize(PageVariantInterface::class);
  $variant2
    ->id()
    ->willReturn('variant2');
  $variant2
    ->getWeight()
    ->willReturn(-10);
  $entity_storage = $this
    ->prophesize(EntityStorageInterface::class);
  $entity_storage
    ->loadByProperties([
    'page' => 'the_page',
  ])
    ->willReturn([
    'variant1' => $variant1
      ->reveal(),
    'variant2' => $variant2
      ->reveal(),
  ])
    ->shouldBeCalledTimes(1);
  $entity_type_manager = $this
    ->prophesize(EntityTypeManagerInterface::class);
  $entity_type_manager
    ->getStorage('page_variant')
    ->willReturn($entity_storage);
  $container = new ContainerBuilder();
  $container
    ->set('entity_type.manager', $entity_type_manager
    ->reveal());
  \Drupal::setContainer($container);
  $variants = $this->page
    ->getVariants();
  $this
    ->assertSame([
    'variant2' => $variant2
      ->reveal(),
    'variant1' => $variant1
      ->reveal(),
  ], $variants);
  $variants = $this->page
    ->getVariants();
  $this
    ->assertSame([
    'variant2' => $variant2
      ->reveal(),
    'variant1' => $variant1
      ->reveal(),
  ], $variants);
}