You are here

public function ViewUIObjectTest::testSerialization in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php \Drupal\Tests\views_ui\Unit\ViewUIObjectTest::testSerialization()
  2. 10 core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php \Drupal\Tests\views_ui\Unit\ViewUIObjectTest::testSerialization()

Tests serialization of the ViewUI object.

File

core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php, line 116

Class

ViewUIObjectTest
@coversDefaultClass \Drupal\views_ui\ViewUI @group views_ui

Namespace

Drupal\Tests\views_ui\Unit

Code

public function testSerialization() {

  // Set a container so the DependencySerializationTrait has it.
  $container = new ContainerBuilder();
  \Drupal::setContainer($container);
  $storage = new View([], 'view');
  $executable = $this
    ->getMockBuilder('Drupal\\views\\ViewExecutable')
    ->disableOriginalConstructor()
    ->setConstructorArgs([
    $storage,
  ])
    ->getMock();
  $storage
    ->set('executable', $executable);
  $view_ui = new ViewUI($storage);

  // Make sure the executable is returned before serializing.
  $this
    ->assertInstanceOf('Drupal\\views\\ViewExecutable', $view_ui
    ->getExecutable());
  $serialized = serialize($view_ui);

  // Make sure the ViewExecutable class is not found in the serialized string.
  $this
    ->assertStringNotContainsString('"Drupal\\views\\ViewExecutable"', $serialized);
  $unserialized = unserialize($serialized);
  $this
    ->assertInstanceOf('Drupal\\views_ui\\ViewUI', $unserialized);
}