function ViewUIObjectTest::testSerialization

Same name in other branches
  1. 9 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()
  3. 11.x 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 164

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.