class UpdateRegistryTest
Same name in other branches
- 8.9.x core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php \Drupal\Tests\Core\Update\UpdateRegistryTest
- 10 core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php \Drupal\Tests\Core\Update\UpdateRegistryTest
- 11.x core/tests/Drupal/Tests/Core/Update/UpdateRegistryTest.php \Drupal\Tests\Core\Update\UpdateRegistryTest
@coversDefaultClass \Drupal\Core\Update\UpdateRegistry @group Update
Note we load code, so isolate the tests.
@runTestsInSeparateProcesses @preserveGlobalState disabled
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait
- class \Drupal\Tests\Core\Update\UpdateRegistryTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of UpdateRegistryTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Update/ UpdateRegistryTest.php, line 21
Namespace
Drupal\Tests\Core\UpdateView source
class UpdateRegistryTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$settings = [];
$settings['extension_discovery_scan_tests'] = TRUE;
new Settings($settings);
}
/**
* Sets up some extensions with some update functions.
*/
protected function setupBasicExtensions() {
$info_a = <<<'EOS'
type: module
name: Module A
core_version_requirement: '*'
EOS;
$info_b = <<<'EOS'
type: module
name: Module B
core_version_requirement: '*'
EOS;
$info_c = <<<'EOS'
type: module
name: Module C
core_version_requirement: '*'
EOS;
$info_d = <<<'EOS'
type: theme
name: Theme D
EOS;
$module_a = <<<'EOS'
<?php
/**
* Module A update B.
*/
function module_a_post_update_b() {
}
/**
* Module A update A.
*/
function module_a_post_update_a() {
}
EOS;
$module_b = <<<'EOS'
<?php
/**
* Module B update A.
*/
function module_b_post_update_a() {
}
/**
* Implements hook_removed_post_updates().
*/
function module_b_removed_post_updates() {
return [
'module_b_post_update_b' => '8.9.0',
'module_b_post_update_c' => '8.9.0',
];
}
EOS;
$module_c = <<<'EOS'
<?php
/**
* Module C update A.
*/
function module_c_post_update_a() {
}
/**
* Module C update B.
*/
function module_c_post_update_b() {
}
/**
* Implements hook_removed_post_updates().
*/
function module_c_removed_post_updates() {
return [
'module_c_post_update_b' => '8.9.0',
'module_c_post_update_c' => '8.9.0',
];
}
EOS;
$theme_d = <<<'EOS'
<?php
/**
* Theme D update B.
*/
function theme_d_post_update_b() {
}
/**
* Theme D update C.
*/
function theme_d_post_update_c() {
}
/**
* Implements hook_removed_post_updates().
*/
function theme_d_removed_post_updates() {
return [
'theme_d_post_update_a' => '8.9.0',
];
}
EOS;
vfsStream::setup('drupal');
vfsStream::create([
'sites' => [
'default' => [
'modules' => [
'module_a' => [
'module_a.post_update.php' => $module_a,
'module_a.info.yml' => $info_a,
],
'module_b' => [
'module_b.post_update.php' => $module_b,
'module_b.info.yml' => $info_b,
],
'module_c' => [
'module_c.post_update.php' => $module_c,
'module_c.info.yml' => $info_c,
],
],
'themes' => [
'theme_d' => [
'theme_d.post_update.php' => $theme_d,
'theme_d.info.yml' => $info_c,
],
],
],
],
]);
}
/**
* @covers ::getPendingUpdateFunctions
*/
public function testGetPendingUpdateFunctionsNoExistingUpdates() {
$this->setupBasicExtensions();
$key_value = $this->prophesize(KeyValueStoreInterface::class);
$key_value->get('existing_updates', [])
->willReturn([]);
$key_value = $key_value->reveal();
$update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [
'module_a',
'module_b',
'theme_d',
], $key_value, FALSE);
$this->assertEquals([
'module_a_post_update_a',
'module_a_post_update_b',
'module_b_post_update_a',
'theme_d_post_update_b',
'theme_d_post_update_c',
], $update_registry->getPendingUpdateFunctions());
}
/**
* @covers ::getPendingUpdateFunctions
*/
public function testGetPendingUpdateFunctionsWithLoadedModulesButNotEnabled() {
$this->setupBasicExtensions();
$key_value = $this->prophesize(KeyValueStoreInterface::class);
$key_value->get('existing_updates', [])
->willReturn([]);
$key_value = $key_value->reveal();
// Preload modules to ensure that ::getAvailableUpdateFunctions filters out
// not enabled modules.
include_once 'vfs://drupal/sites/default/modules/module_a/module_a.post_update.php';
include_once 'vfs://drupal/sites/default/modules/module_b/module_b.post_update.php';
$update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [
'module_a',
], $key_value, FALSE);
$this->assertEquals([
'module_a_post_update_a',
'module_a_post_update_b',
], $update_registry->getPendingUpdateFunctions());
}
/**
* @covers ::getPendingUpdateFunctions
*/
public function testGetPendingUpdateFunctionsExistingUpdates() {
$this->setupBasicExtensions();
$key_value = $this->prophesize(KeyValueStoreInterface::class);
$key_value->get('existing_updates', [])
->willReturn([
'module_a_post_update_a',
'theme_d_post_update_a',
'theme_d_post_update_b',
]);
$key_value = $key_value->reveal();
$update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [
'module_a',
'module_b',
'theme_d',
], $key_value, FALSE);
$this->assertEquals(array_values([
'module_a_post_update_b',
'module_b_post_update_a',
'theme_d_post_update_c',
]), array_values($update_registry->getPendingUpdateFunctions()));
}
/**
* @covers ::getPendingUpdateInformation
*/
public function testGetPendingUpdateInformation() {
$this->setupBasicExtensions();
$key_value = $this->prophesize(KeyValueStoreInterface::class);
$key_value->get('existing_updates', [])
->willReturn([]);
$key_value = $key_value->reveal();
$update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [
'module_a',
'module_b',
'theme_d',
], $key_value, FALSE);
$expected = [];
$expected['module_a']['pending']['a'] = 'Module A update A.';
$expected['module_a']['pending']['b'] = 'Module A update B.';
$expected['module_a']['start'] = 'a';
$expected['module_b']['pending']['a'] = 'Module B update A.';
$expected['module_b']['start'] = 'a';
$expected['theme_d']['pending']['b'] = 'Theme D update B.';
$expected['theme_d']['pending']['c'] = 'Theme D update C.';
$expected['theme_d']['start'] = 'b';
$this->assertEquals($expected, $update_registry->getPendingUpdateInformation());
}
/**
* @covers ::getPendingUpdateInformation
*/
public function testGetPendingUpdateInformationWithExistingUpdates() {
$this->setupBasicExtensions();
$key_value = $this->prophesize(KeyValueStoreInterface::class);
$key_value->get('existing_updates', [])
->willReturn([
'module_a_post_update_a',
'theme_d_post_update_a',
'theme_d_post_update_b',
]);
$key_value = $key_value->reveal();
$update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [
'module_a',
'module_b',
'theme_d',
], $key_value, FALSE);
$expected = [];
$expected['module_a']['pending']['b'] = 'Module A update B.';
$expected['module_a']['start'] = 'b';
$expected['module_b']['pending']['a'] = 'Module B update A.';
$expected['module_b']['start'] = 'a';
$expected['theme_d']['pending']['c'] = 'Theme D update C.';
$expected['theme_d']['start'] = 'c';
$this->assertEquals($expected, $update_registry->getPendingUpdateInformation());
}
/**
* @covers ::getPendingUpdateInformation
*/
public function testGetPendingUpdateInformationWithRemovedUpdates() {
$this->setupBasicExtensions();
$key_value = $this->prophesize(KeyValueStoreInterface::class);
$key_value->get('existing_updates', [])
->willReturn([
'module_a_post_update_a',
]);
$key_value = $key_value->reveal();
$update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [
'module_c',
], $key_value, FALSE);
$this->expectException(RemovedPostUpdateNameException::class);
$update_registry->getPendingUpdateInformation();
}
/**
* @covers ::getUpdateFunctions
*/
public function testGetUpdateFunctions() {
$this->setupBasicExtensions();
$key_value = $this->prophesize(KeyValueStoreInterface::class)
->reveal();
$update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [
'module_a',
'module_b',
'theme_d',
], $key_value, FALSE);
$this->assertEquals([
'module_a_post_update_a',
'module_a_post_update_b',
], array_values($update_registry->getUpdateFunctions('module_a')));
$this->assertEquals([
'module_b_post_update_a',
], array_values($update_registry->getUpdateFunctions('module_b')));
$this->assertEquals([
'theme_d_post_update_b',
'theme_d_post_update_c',
], array_values($update_registry->getUpdateFunctions('theme_d')));
}
/**
* @covers ::getModuleUpdateFunctions
* @group legacy
*/
public function testGetModuleUpdateFunctions() {
$this->expectDeprecation('Drupal\\Core\\Update\\UpdateRegistry\\getModuleUpdateFunctions() is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Use \\Drupal\\Core\\Update\\UpdateRegistry::getUpdateFunctions() instead. See https://www.drupal.org/node/3260162');
$this->setupBasicExtensions();
$key_value = $this->prophesize(KeyValueStoreInterface::class)
->reveal();
$update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [
'module_a',
'module_b',
], $key_value, FALSE);
$this->assertEquals([
'module_a_post_update_a',
'module_a_post_update_b',
], array_values($update_registry->getModuleUpdateFunctions('module_a')));
$this->assertEquals([
'module_b_post_update_a',
], array_values($update_registry->getModuleUpdateFunctions('module_b')));
}
/**
* @covers ::registerInvokedUpdates
*/
public function testRegisterInvokedUpdatesWithoutExistingUpdates() {
$this->setupBasicExtensions();
$key_value = $this->prophesize(KeyValueStoreInterface::class);
$key_value->get('existing_updates', [])
->willReturn([])
->shouldBeCalledTimes(1);
$key_value->set('existing_updates', [
'module_a_post_update_a',
])
->willReturn(NULL)
->shouldBeCalledTimes(1);
$key_value = $key_value->reveal();
$update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [
'module_a',
'module_b',
'theme_d',
], $key_value, FALSE);
$update_registry->registerInvokedUpdates([
'module_a_post_update_a',
]);
}
/**
* @covers ::registerInvokedUpdates
*/
public function testRegisterInvokedUpdatesWithMultiple() {
$this->setupBasicExtensions();
$key_value = $this->prophesize(KeyValueStoreInterface::class);
$key_value->get('existing_updates', [])
->willReturn([])
->shouldBeCalledTimes(1);
$key_value->set('existing_updates', [
'module_a_post_update_a',
'module_a_post_update_b',
'theme_d_post_update_c',
])
->willReturn(NULL)
->shouldBeCalledTimes(1);
$key_value = $key_value->reveal();
$update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [
'module_a',
'module_b',
'theme_d',
], $key_value, FALSE);
$update_registry->registerInvokedUpdates([
'module_a_post_update_a',
'module_a_post_update_b',
'theme_d_post_update_c',
]);
}
/**
* @covers ::registerInvokedUpdates
*/
public function testRegisterInvokedUpdatesWithExistingUpdates() {
$this->setupBasicExtensions();
$key_value = $this->prophesize(KeyValueStoreInterface::class);
$key_value->get('existing_updates', [])
->willReturn([
'module_a_post_update_b',
])
->shouldBeCalledTimes(1);
$key_value->set('existing_updates', [
'module_a_post_update_b',
'module_a_post_update_a',
])
->willReturn(NULL)
->shouldBeCalledTimes(1);
$key_value = $key_value->reveal();
$update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [
'module_a',
'module_b',
], $key_value, FALSE);
$update_registry->registerInvokedUpdates([
'module_a_post_update_a',
]);
}
/**
* @covers ::filterOutInvokedUpdatesByExtension
*/
public function testFilterOutInvokedUpdatesByExtension() {
$this->setupBasicExtensions();
$key_value = $this->prophesize(KeyValueStoreInterface::class);
$key_value->get('existing_updates', [])
->willReturn([
'module_a_post_update_b',
'module_a_post_update_a',
'module_b_post_update_a',
'theme_d_post_update_c',
])
->shouldBeCalledTimes(1);
$key_value->set('existing_updates', [
'module_b_post_update_a',
'theme_d_post_update_c',
])
->willReturn(NULL)
->shouldBeCalledTimes(1);
$key_value = $key_value->reveal();
$update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [
'module_a',
'module_b',
'theme_d',
], $key_value, FALSE);
$update_registry->filterOutInvokedUpdatesByExtension('module_a');
}
/**
* @covers ::filterOutInvokedUpdatesByModule
* @group legacy
*/
public function testFilterOutInvokedUpdatesByModule() {
$this->expectDeprecation('Drupal\\Core\\Update\\UpdateRegistry\\filterOutInvokedUpdatesByModule() is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Use \\Drupal\\Core\\Update\\UpdateRegistry::filterOutInvokedUpdatesByExtension() instead. See https://www.drupal.org/node/3260162');
$this->setupBasicExtensions();
$key_value = $this->prophesize(KeyValueStoreInterface::class);
$key_value->get('existing_updates', [])
->willReturn([
'module_a_post_update_b',
'module_a_post_update_a',
'module_b_post_update_a',
])
->shouldBeCalledTimes(1);
$key_value->set('existing_updates', [
'module_b_post_update_a',
])
->willReturn(NULL)
->shouldBeCalledTimes(1);
$key_value = $key_value->reveal();
$update_registry = new UpdateRegistry('vfs://drupal', 'sites/default', [
'module_a',
'module_b',
], $key_value, FALSE);
$update_registry->filterOutInvokedUpdatesByModule('module_a');
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|---|
PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |||
PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |||
UnitTestCase::$randomGenerator | protected | property | The random generator. | |||
UnitTestCase::$root | protected | property | The app root. | 1 | ||
UnitTestCase::assertArrayEquals | Deprecated | protected | function | Asserts if two arrays are equal by sorting them first. | ||
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |||
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |||
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |||
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |||
UnitTestCase::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |||
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |||
UnitTestCase::randomMachineName | public | function | Generates a unique random string containing letters and numbers. | |||
UnitTestCase::setUpBeforeClass | public static | function | ||||
UpdateRegistryTest::setUp | protected | function | Overrides UnitTestCase::setUp | |||
UpdateRegistryTest::setupBasicExtensions | protected | function | Sets up some extensions with some update functions. | |||
UpdateRegistryTest::testFilterOutInvokedUpdatesByExtension | public | function | @covers ::filterOutInvokedUpdatesByExtension | |||
UpdateRegistryTest::testFilterOutInvokedUpdatesByModule | public | function | @covers ::filterOutInvokedUpdatesByModule @group legacy |
|||
UpdateRegistryTest::testGetModuleUpdateFunctions | public | function | @covers ::getModuleUpdateFunctions @group legacy |
|||
UpdateRegistryTest::testGetPendingUpdateFunctionsExistingUpdates | public | function | @covers ::getPendingUpdateFunctions | |||
UpdateRegistryTest::testGetPendingUpdateFunctionsNoExistingUpdates | public | function | @covers ::getPendingUpdateFunctions | |||
UpdateRegistryTest::testGetPendingUpdateFunctionsWithLoadedModulesButNotEnabled | public | function | @covers ::getPendingUpdateFunctions | |||
UpdateRegistryTest::testGetPendingUpdateInformation | public | function | @covers ::getPendingUpdateInformation | |||
UpdateRegistryTest::testGetPendingUpdateInformationWithExistingUpdates | public | function | @covers ::getPendingUpdateInformation | |||
UpdateRegistryTest::testGetPendingUpdateInformationWithRemovedUpdates | public | function | @covers ::getPendingUpdateInformation | |||
UpdateRegistryTest::testGetUpdateFunctions | public | function | @covers ::getUpdateFunctions | |||
UpdateRegistryTest::testRegisterInvokedUpdatesWithExistingUpdates | public | function | @covers ::registerInvokedUpdates | |||
UpdateRegistryTest::testRegisterInvokedUpdatesWithMultiple | public | function | @covers ::registerInvokedUpdates | |||
UpdateRegistryTest::testRegisterInvokedUpdatesWithoutExistingUpdates | public | function | @covers ::registerInvokedUpdates |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.