You are here

public function ViewExecutableTest::testSerialization in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/views/src/Tests/ViewExecutableTest.php \Drupal\views\Tests\ViewExecutableTest::testSerialization()

Tests serialization of the ViewExecutable object.

File

core/modules/views/src/Tests/ViewExecutableTest.php, line 464
Contains \Drupal\views\Tests\ViewExecutableTest.

Class

ViewExecutableTest
Tests the ViewExecutable class.

Namespace

Drupal\views\Tests

Code

public function testSerialization() {
  $view = Views::getView('test_executable_displays');
  $view
    ->setDisplay('page_1');
  $view
    ->setArguments([
    'test',
  ]);
  $view
    ->setCurrentPage(2);
  $serialized = serialize($view);

  // Test the view storage object is not present in the actual serialized
  // string.
  $this
    ->assertIdentical(strpos($serialized, '"Drupal\\views\\Entity\\View"'), FALSE, 'The Drupal\\views\\Entity\\View class was not found in the serialized string.');

  /** @var \Drupal\views\ViewExecutable $unserialized */
  $unserialized = unserialize($serialized);
  $this
    ->assertTrue($unserialized instanceof ViewExecutable);
  $this
    ->assertIdentical($view->storage
    ->id(), $unserialized->storage
    ->id(), 'The expected storage entity was loaded on the unserialized view.');
  $this
    ->assertIdentical($unserialized->current_display, 'page_1', 'The expected display was set on the unserialized view.');
  $this
    ->assertIdentical($unserialized->args, [
    'test',
  ], 'The expected argument was set on the unserialized view.');
  $this
    ->assertIdentical($unserialized
    ->getCurrentPage(), 2, 'The expected current page was set on the unserialized view.');
}