You are here

public function ViewsTest::testSerialization in Multiversion 8.2

Same name and namespace in other branches
  1. 8 tests/src/Kernel/ViewsTest.php \Drupal\Tests\multiversion\Kernel\ViewsTest::testSerialization()

Test that ViewExecutable can be correctly (un-)serialized.

Throws

\Exception

File

tests/src/Kernel/ViewsTest.php, line 36

Class

ViewsTest
Test for views integration.

Namespace

Drupal\Tests\multiversion\Kernel

Code

public function testSerialization() {

  // Rebuild the container because the "module_handler" service assign
  // "router.route_provider" to "router.route_provider.old" and then
  // assign "router.route_provider.old" back to "router.route_provider".

  /* @see \Drupal\Core\Extension\ModuleInstaller::install() */
  $this->container
    ->get('kernel')
    ->rebuildContainer();

  // The "_serviceId" property is set only to public services.

  /* @see \Drupal\Core\DependencyInjection\Compiler\DependencySerializationTraitPass::process() */

  // The "router.route_provider" is decorated by "multiversion" and used
  // by the "ViewExecutable". The decorated service must not be private in
  // order to be able to serialize/deserialize "ViewExecutable" properly.

  /* @see \Drupal\views\ViewExecutable::__sleep() */
  static::assertTrue(isset($this->container
    ->get('router.route_provider')->_serviceId));

  // The (un-)serialization must go smoothly without the errors.
  unserialize(serialize($this->container
    ->get('views.executable')
    ->get(View::load('test_executable_displays'))));
}