You are here

public function SerializationTest::testPage in Page Manager 8.4

Same name and namespace in other branches
  1. 8 tests/src/Kernel/SerializationTest.php \Drupal\Tests\page_manager\Kernel\SerializationTest::testPage()

Test serialization of a page.

@covers \Drupal\page_manager\Entity\Page::__sleep

File

tests/src/Kernel/SerializationTest.php, line 88

Class

SerializationTest
Tests the serialization of the entities we provide.

Namespace

Drupal\Tests\page_manager\Kernel

Code

public function testPage() {
  $page = $this
    ->createPage();

  // Test that a very simple page successfully serializes.

  /* @var \Drupal\page_manager\Entity\Page $unserialized */
  $unserialized = $this
    ->assertSerialization($page);
  $this
    ->assertEquals($page
    ->id(), $unserialized
    ->id());
  $this
    ->assertEquals($page
    ->label(), $unserialized
    ->label());
  $this
    ->assertEquals($page
    ->getDescription(), $unserialized
    ->getDescription());
  $this
    ->assertEquals($page
    ->getPath(), $unserialized
    ->getPath());
  $this
    ->assertEquals($page
    ->usesAdminTheme(), $unserialized
    ->usesAdminTheme());

  // Test adding parameters.
  $page
    ->set('path', 'admin/foo/{id}');
  $page
    ->setParameter('id', 'integer', 'ID');
  $unserialized = $this
    ->assertSerialization($page);
  $this
    ->assertEquals($page
    ->getPath(), $unserialized
    ->getPath());
  $this
    ->assertEquals($page
    ->getParameters(), $unserialized
    ->getParameters());

  // Test adding access conditions.
  $condition = [
    'id' => 'request_path',
    'pages' => '/admin/foo/*',
    'negate' => FALSE,
    'context_mapping' => [],
  ];
  $page
    ->addAccessCondition($condition);
  $unserialized = $this
    ->assertSerialization($page);
  $this
    ->assertNull($unserialized
    ->get('accessConditionCollection'));
  $this
    ->assertEquals($page
    ->getAccessConditions()
    ->getConfiguration(), $unserialized
    ->getAccessConditions()
    ->getConfiguration());

  // Test adding context.
  $context = new Context(new ContextDefinition('integer', 'ID'), 1);
  $page
    ->addContext('id', $context);
  $unserialized = $this
    ->assertSerialization($page);
  $this
    ->assertEquals([], $unserialized
    ->get('contexts'));

  // Test adding a very basic variant.
  $page_variant = $this
    ->createPageVariant();
  $page
    ->addVariant($page_variant);
  $unserialized = $this
    ->assertSerialization($page);
  $this
    ->assertInstanceOf(PageVariant::class, $unserialized
    ->getVariant($page_variant
    ->id()));
  $this
    ->assertEquals($page_variant
    ->id(), $unserialized
    ->getVariant($page_variant
    ->id())
    ->id());
}