Skip to content
Snippets Groups Projects
Verified Commit 8a760fb1 authored by Dave Long's avatar Dave Long
Browse files

Revert "Issue #3406024 by neclimdul, mondrake, Spokje, smustgrave:...

Revert "Issue #3406024 by neclimdul, mondrake, Spokje, smustgrave: DependencySerializationTrait depends on removed __PHPUNIT_BOOTSTRAP global"

This reverts commit 24f8f3c9.
parent 0b3326d3
No related branches found
No related tags found
No related merge requests found
...@@ -72,13 +72,29 @@ public function __sleep() { ...@@ -72,13 +72,29 @@ public function __sleep() {
*/ */
#[\ReturnTypeWillChange] #[\ReturnTypeWillChange]
public function __wakeup() { public function __wakeup() {
// Tests in isolation potentially unserialize in the parent process.
$phpunit_bootstrap = isset($GLOBALS['__PHPUNIT_BOOTSTRAP']);
if ($phpunit_bootstrap && !\Drupal::hasContainer()) {
return;
}
$container = \Drupal::getContainer(); $container = \Drupal::getContainer();
foreach ($this->_serviceIds as $key => $service_id) { foreach ($this->_serviceIds as $key => $service_id) {
// In rare cases, when test data is serialized in the parent process,
// there is a service container but it doesn't contain all expected
// services. To avoid fatal errors during the wrap-up of failing tests, we
// check for this case, too.
if ($phpunit_bootstrap && !$container->has($service_id)) {
continue;
}
$this->$key = $container->get($service_id); $this->$key = $container->get($service_id);
} }
$this->_serviceIds = []; $this->_serviceIds = [];
if ($this->_entityStorages) { // In rare cases, when test data is serialized in the parent process, there
// is a service container but it doesn't contain all expected services. To
// avoid fatal errors during the wrap-up of failing tests, we check for this
// case, too.
if ($this->_entityStorages && (!$phpunit_bootstrap || $container->has('entity_type.manager'))) {
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */ /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
$entity_type_manager = $container->get('entity_type.manager'); $entity_type_manager = $container->get('entity_type.manager');
foreach ($this->_entityStorages as $key => $entity_type_id) { foreach ($this->_entityStorages as $key => $entity_type_id) {
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\views_ui\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\views\Entity\View;
use Drupal\views\ViewExecutable;
use Drupal\views_ui\ViewUI;
/**
* @group views_ui
*/
class ViewsUiObjectTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = ['views', 'views_ui'];
/**
* Tests serialization of the ViewUI object.
*/
public function testSerialization(): void {
$storage = new View([], 'view');
$executable = $this->getMockBuilder(ViewExecutable::class)
->disableOriginalConstructor()
->setConstructorArgs([$storage])
->getMock();
$storage->set('executable', $executable);
$view_ui = new ViewUI($storage);
// Make sure the executable is returned before serializing.
$this->assertInstanceOf(ViewExecutable::class, $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(ViewUI::class, $unserialized);
// Ensure serialization magic repopulated the object with the executable.
$this->assertInstanceOf(ViewExecutable::class, $unserialized->getExecutable());
}
}
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\TempStore\Lock; use Drupal\Core\TempStore\Lock;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
use Drupal\views\Entity\View;
use Drupal\views_ui\ViewUI; use Drupal\views_ui\ViewUI;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
...@@ -19,7 +20,7 @@ class ViewUIObjectTest extends UnitTestCase { ...@@ -19,7 +20,7 @@ class ViewUIObjectTest extends UnitTestCase {
/** /**
* Tests entity method decoration. * Tests entity method decoration.
*/ */
public function testEntityDecoration(): void { public function testEntityDecoration() {
$method_args = []; $method_args = [];
$method_args['setOriginalId'] = [12]; $method_args['setOriginalId'] = [12];
$method_args['setStatus'] = [TRUE]; $method_args['setStatus'] = [TRUE];
...@@ -73,10 +74,8 @@ public function testEntityDecoration(): void { ...@@ -73,10 +74,8 @@ public function testEntityDecoration(): void {
/** /**
* Tests the isLocked method. * Tests the isLocked method.
*
* @runInSeparateProcess
*/ */
public function testIsLocked(): void { public function testIsLocked() {
$storage = $this->getMockBuilder('Drupal\views\Entity\View') $storage = $this->getMockBuilder('Drupal\views\Entity\View')
->setConstructorArgs([[], 'view']) ->setConstructorArgs([[], 'view'])
->getMock(); ->getMock();
...@@ -109,8 +108,33 @@ public function testIsLocked(): void { ...@@ -109,8 +108,33 @@ public function testIsLocked(): void {
$view_ui->setLock($lock); $view_ui->setLock($lock);
$this->assertFalse($view_ui->isLocked()); $this->assertFalse($view_ui->isLocked());
$view_ui->unsetLock(); $view_ui->unsetLock(NULL);
$this->assertFalse($view_ui->isLocked()); $this->assertFalse($view_ui->isLocked());
} }
/**
* Tests serialization of the ViewUI object.
*/
public function testSerialization() {
$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);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment