diff --git a/core/modules/system/src/Controller/AdminController.php b/core/modules/system/src/Controller/AdminController.php index 767a8ce226..2a88b11025 100644 --- a/core/modules/system/src/Controller/AdminController.php +++ b/core/modules/system/src/Controller/AdminController.php @@ -21,15 +21,10 @@ class AdminController extends ControllerBase { /** * AdminController constructor. * - * @param \Drupal\Core\Extension\ModuleExtensionList|null $extension_list_module - * The module extension list. This is left optional for BC reasons, but the - * optional usage is deprecated and will become required in Drupal 9.0.0. + * @param \Drupal\Core\Extension\ModuleExtensionList $extension_list_module + * The module extension list. */ - public function __construct(ModuleExtensionList $extension_list_module = NULL) { - if ($extension_list_module === NULL) { - @trigger_error('Calling AdminController::__construct() with the $module_extension_list argument is supported in drupal:8.8.0 and will be required before drupal:9.0.0. See https://www.drupal.org/node/2709919.', E_USER_DEPRECATED); - $extension_list_module = \Drupal::service('extension.list.module'); - } + public function __construct(ModuleExtensionList $extension_list_module) { $this->moduleExtensionList = $extension_list_module; } diff --git a/core/modules/system/src/FileDownloadController.php b/core/modules/system/src/FileDownloadController.php index 9bf889084a..086618518f 100644 --- a/core/modules/system/src/FileDownloadController.php +++ b/core/modules/system/src/FileDownloadController.php @@ -28,11 +28,7 @@ class FileDownloadController extends ControllerBase { * @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $streamWrapperManager * The stream wrapper manager. */ - public function __construct(StreamWrapperManagerInterface $streamWrapperManager = NULL) { - if (!$streamWrapperManager) { - @trigger_error('Calling FileDownloadController::__construct() without the $streamWrapperManager argument is deprecated in drupal:8.8.0. The $streamWrapperManager argument will be required in drupal:9.0.0. See https://www.drupal.org/node/3035273', E_USER_DEPRECATED); - $streamWrapperManager = \Drupal::service('stream_wrapper_manager'); - } + public function __construct(StreamWrapperManagerInterface $streamWrapperManager) { $this->streamWrapperManager = $streamWrapperManager; } diff --git a/core/modules/system/src/Form/FileSystemForm.php b/core/modules/system/src/Form/FileSystemForm.php index d81488b44e..9bc5b92ef3 100644 --- a/core/modules/system/src/Form/FileSystemForm.php +++ b/core/modules/system/src/Form/FileSystemForm.php @@ -53,14 +53,10 @@ class FileSystemForm extends ConfigFormBase { * @param \Drupal\Core\File\FileSystemInterface $file_system * The file system. */ - public function __construct(ConfigFactoryInterface $config_factory, DateFormatterInterface $date_formatter, StreamWrapperManagerInterface $stream_wrapper_manager, FileSystemInterface $file_system = NULL) { + public function __construct(ConfigFactoryInterface $config_factory, DateFormatterInterface $date_formatter, StreamWrapperManagerInterface $stream_wrapper_manager, FileSystemInterface $file_system) { parent::__construct($config_factory); $this->dateFormatter = $date_formatter; $this->streamWrapperManager = $stream_wrapper_manager; - if (!$file_system) { - @trigger_error('Calling FileSystemForm::__construct() without the $file_system argument is deprecated in drupal:8.8.0. The $file_system argument will be required in drupal:9.0.0. See https://www.drupal.org/node/3039255', E_USER_DEPRECATED); - $file_system = \Drupal::service('file_system'); - } $this->fileSystem = $file_system; } diff --git a/core/modules/system/src/Form/ThemeSettingsForm.php b/core/modules/system/src/Form/ThemeSettingsForm.php index 2a65c6b52d..e25563d049 100644 --- a/core/modules/system/src/Form/ThemeSettingsForm.php +++ b/core/modules/system/src/Form/ThemeSettingsForm.php @@ -82,17 +82,13 @@ class ThemeSettingsForm extends ConfigFormBase { * @param \Drupal\Core\File\FileSystemInterface $file_system * The file system. */ - public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, MimeTypeGuesserInterface $mime_type_guesser, ThemeManagerInterface $theme_manager, FileSystemInterface $file_system = NULL) { + public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, MimeTypeGuesserInterface $mime_type_guesser, ThemeManagerInterface $theme_manager, FileSystemInterface $file_system) { parent::__construct($config_factory); $this->moduleHandler = $module_handler; $this->themeHandler = $theme_handler; $this->mimeTypeGuesser = $mime_type_guesser; $this->themeManager = $theme_manager; - if (!$file_system) { - @trigger_error('The file_system service must be passed to ThemeSettingsForm::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/3006851.', E_USER_DEPRECATED); - $file_system = \Drupal::service('file_system'); - } $this->fileSystem = $file_system; } diff --git a/core/modules/system/src/Plugin/Block/SystemMenuBlock.php b/core/modules/system/src/Plugin/Block/SystemMenuBlock.php index 84f34b4b25..55c2af6202 100644 --- a/core/modules/system/src/Plugin/Block/SystemMenuBlock.php +++ b/core/modules/system/src/Plugin/Block/SystemMenuBlock.php @@ -54,13 +54,9 @@ class SystemMenuBlock extends BlockBase implements ContainerFactoryPluginInterfa * @param \Drupal\Core\Menu\MenuActiveTrailInterface $menu_active_trail * The active menu trail service. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MenuLinkTreeInterface $menu_tree, MenuActiveTrailInterface $menu_active_trail = NULL) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, MenuLinkTreeInterface $menu_tree, MenuActiveTrailInterface $menu_active_trail) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->menuTree = $menu_tree; - if ($menu_active_trail === NULL) { - @trigger_error('The menu.active_trail service must be passed to SystemMenuBlock::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2669550.', E_USER_DEPRECATED); - $menu_active_trail = \Drupal::service('menu.active_trail'); - } $this->menuActiveTrail = $menu_active_trail; } diff --git a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php index c07c9cf3c5..2d5e1678ac 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php @@ -88,13 +88,9 @@ class GDToolkit extends ImageToolkitBase { * @param \Drupal\Core\File\FileSystemInterface $file_system * The file system. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, ImageToolkitOperationManagerInterface $operation_manager, LoggerInterface $logger, ConfigFactoryInterface $config_factory, StreamWrapperManagerInterface $stream_wrapper_manager, FileSystemInterface $file_system = NULL) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, ImageToolkitOperationManagerInterface $operation_manager, LoggerInterface $logger, ConfigFactoryInterface $config_factory, StreamWrapperManagerInterface $stream_wrapper_manager, FileSystemInterface $file_system) { parent::__construct($configuration, $plugin_id, $plugin_definition, $operation_manager, $logger, $config_factory); $this->streamWrapperManager = $stream_wrapper_manager; - if (!$file_system) { - @trigger_error('The file_system service must be passed to GDToolkit::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/3006851.', E_USER_DEPRECATED); - $file_system = \Drupal::service('file_system'); - } $this->fileSystem = $file_system; } diff --git a/core/modules/system/src/Plugin/views/field/BulkForm.php b/core/modules/system/src/Plugin/views/field/BulkForm.php deleted file mode 100644 index 5eb13b405a..0000000000 --- a/core/modules/system/src/Plugin/views/field/BulkForm.php +++ /dev/null @@ -1,31 +0,0 @@ -=') && version_compare($phpversion, '5.6.0', '<')) - || version_compare($phpversion, '5.6.5', '>='); - } - -} diff --git a/core/modules/system/src/Tests/Cache/CacheTestBase.php b/core/modules/system/src/Tests/Cache/CacheTestBase.php deleted file mode 100644 index dc2f601c5f..0000000000 --- a/core/modules/system/src/Tests/Cache/CacheTestBase.php +++ /dev/null @@ -1,93 +0,0 @@ -defaultBin; - } - - $cached = \Drupal::cache($bin)->get($cid); - - return isset($cached->data) && $cached->data == $var; - } - - /** - * Asserts that a cache entry exists. - * - * @param $message - * Message to display. - * @param $var - * The variable the cache should contain. - * @param $cid - * The cache id. - * @param $bin - * The bin the cache item was stored in. - */ - protected function assertCacheExists($message, $var = NULL, $cid = NULL, $bin = NULL) { - if ($bin == NULL) { - $bin = $this->defaultBin; - } - if ($cid == NULL) { - $cid = $this->defaultCid; - } - if ($var == NULL) { - $var = $this->defaultValue; - } - - $this->assertTrue($this->checkCacheExists($cid, $var, $bin), $message); - } - - /** - * Asserts that a cache entry has been removed. - * - * @param $message - * Message to display. - * @param $cid - * The cache id. - * @param $bin - * The bin the cache item was stored in. - */ - public function assertCacheRemoved($message, $cid = NULL, $bin = NULL) { - if ($bin == NULL) { - $bin = $this->defaultBin; - } - if ($cid == NULL) { - $cid = $this->defaultCid; - } - - $cached = \Drupal::cache($bin)->get($cid); - $this->assertFalse($cached, $message); - } - -} diff --git a/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php b/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php deleted file mode 100644 index 4abca9e576..0000000000 --- a/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php +++ /dev/null @@ -1,630 +0,0 @@ -testBin)) { - $this->testBin = 'page'; - } - return $this->testBin; - } - - /** - * Creates a cache backend to test. - * - * Override this method to test a CacheBackend. - * - * @param string $bin - * Bin name to use for this backend instance. - * - * @return \Drupal\Core\Cache\CacheBackendInterface - * Cache backend to test. - */ - abstract protected function createCacheBackend($bin); - - /** - * Allows specific implementation to change the environment before a test run. - */ - public function setUpCacheBackend() { - } - - /** - * Allows alteration of environment after a test run but before tear down. - * - * Used before the real tear down because the tear down will change things - * such as the database prefix. - */ - public function tearDownCacheBackend() { - } - - /** - * Gets a backend to test; this will get a shared instance set in the object. - * - * @return \Drupal\Core\Cache\CacheBackendInterface - * Cache backend to test. - */ - protected function getCacheBackend($bin = NULL) { - if (!isset($bin)) { - $bin = $this->getTestBin(); - } - if (!isset($this->cachebackends[$bin])) { - $this->cachebackends[$bin] = $this->createCacheBackend($bin); - // Ensure the backend is empty. - $this->cachebackends[$bin]->deleteAll(); - } - return $this->cachebackends[$bin]; - } - - protected function setUp() { - $this->cachebackends = []; - $this->defaultValue = $this->randomMachineName(10); - - parent::setUp(); - - $this->setUpCacheBackend(); - } - - protected function tearDown() { - // Destruct the registered backend, each test will get a fresh instance, - // properly emptying it here ensure that on persistent data backends they - // will come up empty the next test. - foreach ($this->cachebackends as $bin => $cachebackend) { - $this->cachebackends[$bin]->deleteAll(); - } - unset($this->cachebackends); - - $this->tearDownCacheBackend(); - - parent::tearDown(); - } - - /** - * Tests the get and set methods of Drupal\Core\Cache\CacheBackendInterface. - */ - public function testSetGet() { - $backend = $this->getCacheBackend(); - - $this->assertIdentical(FALSE, $backend->get('test1'), "Backend does not contain data for cache id test1."); - $with_backslash = ['foo' => '\Drupal\foo\Bar']; - $backend->set('test1', $with_backslash); - $cached = $backend->get('test1'); - $this->assert(is_object($cached), "Backend returned an object for cache id test1."); - $this->assertIdentical($with_backslash, $cached->data); - $this->assertTrue($cached->valid, 'Item is marked as valid.'); - // We need to round because microtime may be rounded up in the backend. - $this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.'); - $this->assertEqual($cached->expire, Cache::PERMANENT, 'Expire time is correct.'); - - $this->assertIdentical(FALSE, $backend->get('test2'), "Backend does not contain data for cache id test2."); - $backend->set('test2', ['value' => 3], REQUEST_TIME + 3); - $cached = $backend->get('test2'); - $this->assert(is_object($cached), "Backend returned an object for cache id test2."); - $this->assertIdentical(['value' => 3], $cached->data); - $this->assertTrue($cached->valid, 'Item is marked as valid.'); - $this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.'); - $this->assertEqual($cached->expire, REQUEST_TIME + 3, 'Expire time is correct.'); - - $backend->set('test3', 'foobar', REQUEST_TIME - 3); - $this->assertFalse($backend->get('test3'), 'Invalid item not returned.'); - $cached = $backend->get('test3', TRUE); - $this->assert(is_object($cached), 'Backend returned an object for cache id test3.'); - $this->assertFalse($cached->valid, 'Item is marked as valid.'); - $this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.'); - $this->assertEqual($cached->expire, REQUEST_TIME - 3, 'Expire time is correct.'); - - $this->assertIdentical(FALSE, $backend->get('test4'), "Backend does not contain data for cache id test4."); - $with_eof = ['foo' => "\nEOF\ndata"]; - $backend->set('test4', $with_eof); - $cached = $backend->get('test4'); - $this->assert(is_object($cached), "Backend returned an object for cache id test4."); - $this->assertIdentical($with_eof, $cached->data); - $this->assertTrue($cached->valid, 'Item is marked as valid.'); - $this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.'); - $this->assertEqual($cached->expire, Cache::PERMANENT, 'Expire time is correct.'); - - $this->assertIdentical(FALSE, $backend->get('test5'), "Backend does not contain data for cache id test5."); - $with_eof_and_semicolon = ['foo' => "\nEOF;\ndata"]; - $backend->set('test5', $with_eof_and_semicolon); - $cached = $backend->get('test5'); - $this->assert(is_object($cached), "Backend returned an object for cache id test5."); - $this->assertIdentical($with_eof_and_semicolon, $cached->data); - $this->assertTrue($cached->valid, 'Item is marked as valid.'); - $this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.'); - $this->assertEqual($cached->expire, Cache::PERMANENT, 'Expire time is correct.'); - - $with_variable = ['foo' => '$bar']; - $backend->set('test6', $with_variable); - $cached = $backend->get('test6'); - $this->assert(is_object($cached), "Backend returned an object for cache id test6."); - $this->assertIdentical($with_variable, $cached->data); - - // Make sure that a cached object is not affected by changing the original. - $data = new \stdClass(); - $data->value = 1; - $data->obj = new \stdClass(); - $data->obj->value = 2; - $backend->set('test7', $data); - $expected_data = clone $data; - // Add a property to the original. It should not appear in the cached data. - $data->this_should_not_be_in_the_cache = TRUE; - $cached = $backend->get('test7'); - $this->assert(is_object($cached), "Backend returned an object for cache id test7."); - $this->assertEqual($expected_data, $cached->data); - $this->assertFalse(isset($cached->data->this_should_not_be_in_the_cache)); - // Add a property to the cache data. It should not appear when we fetch - // the data from cache again. - $cached->data->this_should_not_be_in_the_cache = TRUE; - $fresh_cached = $backend->get('test7'); - $this->assertFalse(isset($fresh_cached->data->this_should_not_be_in_the_cache)); - - // Check with a long key. - $cid = str_repeat('a', 300); - $backend->set($cid, 'test'); - $this->assertEqual('test', $backend->get($cid)->data); - - // Check that the cache key is case sensitive. - $backend->set('TEST8', 'value'); - $this->assertEqual('value', $backend->get('TEST8')->data); - $this->assertFalse($backend->get('test8')); - - // Calling ::set() with invalid cache tags. This should fail an assertion. - try { - $backend->set('assertion_test', 'value', Cache::PERMANENT, ['node' => [3, 5, 7]]); - $this->fail('::set() was called with invalid cache tags, runtime assertion did not fail.'); - } - catch (\AssertionError $e) { - $this->pass('::set() was called with invalid cache tags, runtime assertion failed.'); - } - } - - /** - * Tests Drupal\Core\Cache\CacheBackendInterface::delete(). - */ - public function testDelete() { - $backend = $this->getCacheBackend(); - - $this->assertIdentical(FALSE, $backend->get('test1'), "Backend does not contain data for cache id test1."); - $backend->set('test1', 7); - $this->assert(is_object($backend->get('test1')), "Backend returned an object for cache id test1."); - - $this->assertIdentical(FALSE, $backend->get('test2'), "Backend does not contain data for cache id test2."); - $backend->set('test2', 3); - $this->assert(is_object($backend->get('test2')), "Backend returned an object for cache id %cid."); - - $backend->delete('test1'); - $this->assertIdentical(FALSE, $backend->get('test1'), "Backend does not contain data for cache id test1 after deletion."); - - $this->assert(is_object($backend->get('test2')), "Backend still has an object for cache id test2."); - - $backend->delete('test2'); - $this->assertIdentical(FALSE, $backend->get('test2'), "Backend does not contain data for cache id test2 after deletion."); - - $long_cid = str_repeat('a', 300); - $backend->set($long_cid, 'test'); - $backend->delete($long_cid); - $this->assertIdentical(FALSE, $backend->get($long_cid), "Backend does not contain data for long cache id after deletion."); - } - - /** - * Tests data type preservation. - */ - public function testValueTypeIsKept() { - $backend = $this->getCacheBackend(); - - $variables = [ - 'test1' => 1, - 'test2' => '0', - 'test3' => '', - 'test4' => 12.64, - 'test5' => FALSE, - 'test6' => [1, 2, 3], - ]; - - // Create cache entries. - foreach ($variables as $cid => $data) { - $backend->set($cid, $data); - } - - // Retrieve and test cache objects. - foreach ($variables as $cid => $value) { - $object = $backend->get($cid); - $this->assert(is_object($object), sprintf("Backend returned an object for cache id %s.", $cid)); - $this->assertIdentical($value, $object->data, sprintf("Data of cached id %s kept is identical in type and value", $cid)); - } - } - - /** - * Tests Drupal\Core\Cache\CacheBackendInterface::getMultiple(). - */ - public function testGetMultiple() { - $backend = $this->getCacheBackend(); - - // Set numerous testing keys. - $long_cid = str_repeat('a', 300); - $backend->set('test1', 1); - $backend->set('test2', 3); - $backend->set('test3', 5); - $backend->set('test4', 7); - $backend->set('test5', 11); - $backend->set('test6', 13); - $backend->set('test7', 17); - $backend->set($long_cid, 300); - - // Mismatch order for harder testing. - $reference = [ - 'test3', - 'test7', - // Cid does not exist. - 'test21', - 'test6', - // Cid does not exist until added before second getMultiple(). - 'test19', - 'test2', - ]; - - $cids = $reference; - $ret = $backend->getMultiple($cids); - // Test return - ensure it contains existing cache ids. - $this->assert(isset($ret['test2']), "Existing cache id test2 is set."); - $this->assert(isset($ret['test3']), "Existing cache id test3 is set."); - $this->assert(isset($ret['test6']), "Existing cache id test6 is set."); - $this->assert(isset($ret['test7']), "Existing cache id test7 is set."); - // Test return - ensure that objects has expected properties. - $this->assertTrue($ret['test2']->valid, 'Item is marked as valid.'); - $this->assertTrue($ret['test2']->created >= REQUEST_TIME && $ret['test2']->created <= round(microtime(TRUE), 3), 'Created time is correct.'); - $this->assertEqual($ret['test2']->expire, Cache::PERMANENT, 'Expire time is correct.'); - // Test return - ensure it does not contain nonexistent cache ids. - $this->assertFalse(isset($ret['test19']), "Nonexistent cache id test19 is not set."); - $this->assertFalse(isset($ret['test21']), "Nonexistent cache id test21 is not set."); - // Test values. - $this->assertIdentical($ret['test2']->data, 3, "Existing cache id test2 has the correct value."); - $this->assertIdentical($ret['test3']->data, 5, "Existing cache id test3 has the correct value."); - $this->assertIdentical($ret['test6']->data, 13, "Existing cache id test6 has the correct value."); - $this->assertIdentical($ret['test7']->data, 17, "Existing cache id test7 has the correct value."); - // Test $cids array - ensure it contains cache id's that do not exist. - $this->assert(in_array('test19', $cids), "Nonexistent cache id test19 is in cids array."); - $this->assert(in_array('test21', $cids), "Nonexistent cache id test21 is in cids array."); - // Test $cids array - ensure it does not contain cache id's that exist. - $this->assertFalse(in_array('test2', $cids), "Existing cache id test2 is not in cids array."); - $this->assertFalse(in_array('test3', $cids), "Existing cache id test3 is not in cids array."); - $this->assertFalse(in_array('test6', $cids), "Existing cache id test6 is not in cids array."); - $this->assertFalse(in_array('test7', $cids), "Existing cache id test7 is not in cids array."); - - // Test a second time after deleting and setting new keys which ensures that - // if the backend uses statics it does not cause unexpected results. - $backend->delete('test3'); - $backend->delete('test6'); - $backend->set('test19', 57); - - $cids = $reference; - $ret = $backend->getMultiple($cids); - // Test return - ensure it contains existing cache ids. - $this->assert(isset($ret['test2']), "Existing cache id test2 is set"); - $this->assert(isset($ret['test7']), "Existing cache id test7 is set"); - $this->assert(isset($ret['test19']), "Added cache id test19 is set"); - // Test return - ensure it does not contain nonexistent cache ids. - $this->assertFalse(isset($ret['test3']), "Deleted cache id test3 is not set"); - $this->assertFalse(isset($ret['test6']), "Deleted cache id test6 is not set"); - $this->assertFalse(isset($ret['test21']), "Nonexistent cache id test21 is not set"); - // Test values. - $this->assertIdentical($ret['test2']->data, 3, "Existing cache id test2 has the correct value."); - $this->assertIdentical($ret['test7']->data, 17, "Existing cache id test7 has the correct value."); - $this->assertIdentical($ret['test19']->data, 57, "Added cache id test19 has the correct value."); - // Test $cids array - ensure it contains cache id's that do not exist. - $this->assert(in_array('test3', $cids), "Deleted cache id test3 is in cids array."); - $this->assert(in_array('test6', $cids), "Deleted cache id test6 is in cids array."); - $this->assert(in_array('test21', $cids), "Nonexistent cache id test21 is in cids array."); - // Test $cids array - ensure it does not contain cache id's that exist. - $this->assertFalse(in_array('test2', $cids), "Existing cache id test2 is not in cids array."); - $this->assertFalse(in_array('test7', $cids), "Existing cache id test7 is not in cids array."); - $this->assertFalse(in_array('test19', $cids), "Added cache id test19 is not in cids array."); - - // Test with a long $cid and non-numeric array key. - $cids = ['key:key' => $long_cid]; - $return = $backend->getMultiple($cids); - $this->assertEqual(300, $return[$long_cid]->data); - $this->assertTrue(empty($cids)); - } - - /** - * Tests \Drupal\Core\Cache\CacheBackendInterface::setMultiple(). - */ - public function testSetMultiple() { - $backend = $this->getCacheBackend(); - - $future_expiration = REQUEST_TIME + 100; - - // Set multiple testing keys. - $backend->set('cid_1', 'Some other value'); - $items = [ - 'cid_1' => ['data' => 1], - 'cid_2' => ['data' => 2], - 'cid_3' => ['data' => [1, 2]], - 'cid_4' => ['data' => 1, 'expire' => $future_expiration], - 'cid_5' => ['data' => 1, 'tags' => ['test:a', 'test:b']], - ]; - $backend->setMultiple($items); - $cids = array_keys($items); - $cached = $backend->getMultiple($cids); - - $this->assertEqual($cached['cid_1']->data, $items['cid_1']['data'], 'Over-written cache item set correctly.'); - $this->assertTrue($cached['cid_1']->valid, 'Item is marked as valid.'); - $this->assertTrue($cached['cid_1']->created >= REQUEST_TIME && $cached['cid_1']->created <= round(microtime(TRUE), 3), 'Created time is correct.'); - $this->assertEqual($cached['cid_1']->expire, CacheBackendInterface::CACHE_PERMANENT, 'Cache expiration defaults to permanent.'); - - $this->assertEqual($cached['cid_2']->data, $items['cid_2']['data'], 'New cache item set correctly.'); - $this->assertEqual($cached['cid_2']->expire, CacheBackendInterface::CACHE_PERMANENT, 'Cache expiration defaults to permanent.'); - - $this->assertEqual($cached['cid_3']->data, $items['cid_3']['data'], 'New cache item with serialized data set correctly.'); - $this->assertEqual($cached['cid_3']->expire, CacheBackendInterface::CACHE_PERMANENT, 'Cache expiration defaults to permanent.'); - - $this->assertEqual($cached['cid_4']->data, $items['cid_4']['data'], 'New cache item set correctly.'); - $this->assertEqual($cached['cid_4']->expire, $future_expiration, 'Cache expiration has been correctly set.'); - - $this->assertEqual($cached['cid_5']->data, $items['cid_5']['data'], 'New cache item set correctly.'); - - // Calling ::setMultiple() with invalid cache tags. This should fail an - // assertion. - try { - $items = [ - 'exception_test_1' => ['data' => 1, 'tags' => []], - 'exception_test_2' => ['data' => 2, 'tags' => ['valid']], - 'exception_test_3' => ['data' => 3, 'tags' => ['node' => [3, 5, 7]]], - ]; - $backend->setMultiple($items); - $this->fail('::setMultiple() was called with invalid cache tags, runtime assertion did not fail.'); - } - catch (\AssertionError $e) { - $this->pass('::setMultiple() was called with invalid cache tags, runtime assertion failed.'); - } - } - - /** - * Test Drupal\Core\Cache\CacheBackendInterface::delete() and - * Drupal\Core\Cache\CacheBackendInterface::deleteMultiple(). - */ - public function testDeleteMultiple() { - $backend = $this->getCacheBackend(); - - // Set numerous testing keys. - $backend->set('test1', 1); - $backend->set('test2', 3); - $backend->set('test3', 5); - $backend->set('test4', 7); - $backend->set('test5', 11); - $backend->set('test6', 13); - $backend->set('test7', 17); - - $backend->delete('test1'); - // Nonexistent key should not cause an error. - $backend->delete('test23'); - $backend->deleteMultiple([ - 'test3', - 'test5', - 'test7', - // Nonexistent key should not cause an error. - 'test19', - // Nonexistent key should not cause an error. - 'test21', - ]); - - // Test if expected keys have been deleted. - $this->assertIdentical(FALSE, $backend->get('test1'), "Cache id test1 deleted."); - $this->assertIdentical(FALSE, $backend->get('test3'), "Cache id test3 deleted."); - $this->assertIdentical(FALSE, $backend->get('test5'), "Cache id test5 deleted."); - $this->assertIdentical(FALSE, $backend->get('test7'), "Cache id test7 deleted."); - - // Test if expected keys exist. - $this->assertNotIdentical(FALSE, $backend->get('test2'), "Cache id test2 exists."); - $this->assertNotIdentical(FALSE, $backend->get('test4'), "Cache id test4 exists."); - $this->assertNotIdentical(FALSE, $backend->get('test6'), "Cache id test6 exists."); - - // Test if that expected keys do not exist. - $this->assertIdentical(FALSE, $backend->get('test19'), "Cache id test19 does not exist."); - $this->assertIdentical(FALSE, $backend->get('test21'), "Cache id test21 does not exist."); - - // Calling deleteMultiple() with an empty array should not cause an error. - $this->assertFalse($backend->deleteMultiple([])); - } - - /** - * Test Drupal\Core\Cache\CacheBackendInterface::deleteAll(). - */ - public function testDeleteAll() { - $backend_a = $this->getCacheBackend(); - $backend_b = $this->getCacheBackend('bootstrap'); - - // Set both expiring and permanent keys. - $backend_a->set('test1', 1, Cache::PERMANENT); - $backend_a->set('test2', 3, time() + 1000); - $backend_b->set('test3', 4, Cache::PERMANENT); - - $backend_a->deleteAll(); - - $this->assertFalse($backend_a->get('test1'), 'First key has been deleted.'); - $this->assertFalse($backend_a->get('test2'), 'Second key has been deleted.'); - $this->assertTrue($backend_b->get('test3'), 'Item in other bin is preserved.'); - } - - /** - * Test Drupal\Core\Cache\CacheBackendInterface::invalidate() and - * Drupal\Core\Cache\CacheBackendInterface::invalidateMultiple(). - */ - public function testInvalidate() { - $backend = $this->getCacheBackend(); - $backend->set('test1', 1); - $backend->set('test2', 2); - $backend->set('test3', 2); - $backend->set('test4', 2); - - $reference = ['test1', 'test2', 'test3', 'test4']; - - $cids = $reference; - $ret = $backend->getMultiple($cids); - $this->assertEqual(count($ret), 4, 'Four items returned.'); - - $backend->invalidate('test1'); - $backend->invalidateMultiple(['test2', 'test3']); - - $cids = $reference; - $ret = $backend->getMultiple($cids); - $this->assertEqual(count($ret), 1, 'Only one item element returned.'); - - $cids = $reference; - $ret = $backend->getMultiple($cids, TRUE); - $this->assertEqual(count($ret), 4, 'Four items returned.'); - - // Calling invalidateMultiple() with an empty array should not cause an - // error. - $this->assertFalse($backend->invalidateMultiple([])); - } - - /** - * Tests Drupal\Core\Cache\CacheBackendInterface::invalidateTags(). - */ - public function testInvalidateTags() { - $backend = $this->getCacheBackend(); - - // Create two cache entries with the same tag and tag value. - $backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, ['test_tag:2']); - $backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, ['test_tag:2']); - $this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2'), 'Two cache items were created.'); - - // Invalidate test_tag of value 1. This should invalidate both entries. - Cache::invalidateTags(['test_tag:2']); - $this->assertFalse($backend->get('test_cid_invalidate1') || $backend->get('test_cid_invalidate2'), 'Two cache items invalidated after invalidating a cache tag.'); - $this->assertTrue($backend->get('test_cid_invalidate1', TRUE) && $backend->get('test_cid_invalidate2', TRUE), 'Cache items not deleted after invalidating a cache tag.'); - - // Create two cache entries with the same tag and an array tag value. - $backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, ['test_tag:1']); - $backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, ['test_tag:1']); - $this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2'), 'Two cache items were created.'); - - // Invalidate test_tag of value 1. This should invalidate both entries. - Cache::invalidateTags(['test_tag:1']); - $this->assertFalse($backend->get('test_cid_invalidate1') || $backend->get('test_cid_invalidate2'), 'Two caches removed after invalidating a cache tag.'); - $this->assertTrue($backend->get('test_cid_invalidate1', TRUE) && $backend->get('test_cid_invalidate2', TRUE), 'Cache items not deleted after invalidating a cache tag.'); - - // Create three cache entries with a mix of tags and tag values. - $backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, ['test_tag:1']); - $backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, ['test_tag:2']); - $backend->set('test_cid_invalidate3', $this->defaultValue, Cache::PERMANENT, ['test_tag_foo:3']); - $this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2') && $backend->get('test_cid_invalidate3'), 'Three cached items were created.'); - Cache::invalidateTags(['test_tag_foo:3']); - $this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2'), 'Cache items not matching the tag were not invalidated.'); - $this->assertFalse($backend->get('test_cid_invalidated3'), 'Cached item matching the tag was removed.'); - - // Create cache entry in multiple bins. Two cache entries - // (test_cid_invalidate1 and test_cid_invalidate2) still exist from previous - // tests. - $tags = ['test_tag:1', 'test_tag:2', 'test_tag:3']; - $bins = ['path', 'bootstrap', 'page']; - foreach ($bins as $bin) { - $this->getCacheBackend($bin)->set('test', $this->defaultValue, Cache::PERMANENT, $tags); - $this->assertTrue($this->getCacheBackend($bin)->get('test'), 'Cache item was set in bin.'); - } - - Cache::invalidateTags(['test_tag:2']); - - // Test that the cache entry has been invalidated in multiple bins. - foreach ($bins as $bin) { - $this->assertFalse($this->getCacheBackend($bin)->get('test'), 'Tag invalidation affected item in bin.'); - } - // Test that the cache entry with a matching tag has been invalidated. - $this->assertFalse($this->getCacheBackend($bin)->get('test_cid_invalidate2'), 'Cache items matching tag were invalidated.'); - // Test that the cache entry with without a matching tag still exists. - $this->assertTrue($this->getCacheBackend($bin)->get('test_cid_invalidate1'), 'Cache items not matching tag were not invalidated.'); - } - - /** - * Test Drupal\Core\Cache\CacheBackendInterface::invalidateAll(). - */ - public function testInvalidateAll() { - $backend_a = $this->getCacheBackend(); - $backend_b = $this->getCacheBackend('bootstrap'); - - // Set both expiring and permanent keys. - $backend_a->set('test1', 1, Cache::PERMANENT); - $backend_a->set('test2', 3, time() + 1000); - $backend_b->set('test3', 4, Cache::PERMANENT); - - $backend_a->invalidateAll(); - - $this->assertFalse($backend_a->get('test1'), 'First key has been invalidated.'); - $this->assertFalse($backend_a->get('test2'), 'Second key has been invalidated.'); - $this->assertTrue($backend_b->get('test3'), 'Item in other bin is preserved.'); - $this->assertTrue($backend_a->get('test1', TRUE), 'First key has not been deleted.'); - $this->assertTrue($backend_a->get('test2', TRUE), 'Second key has not been deleted.'); - } - - /** - * Tests Drupal\Core\Cache\CacheBackendInterface::removeBin(). - */ - public function testRemoveBin() { - $backend_a = $this->getCacheBackend(); - $backend_b = $this->getCacheBackend('bootstrap'); - - // Set both expiring and permanent keys. - $backend_a->set('test1', 1, Cache::PERMANENT); - $backend_a->set('test2', 3, time() + 1000); - $backend_b->set('test3', 4, Cache::PERMANENT); - - $backend_a->removeBin(); - - $this->assertFalse($backend_a->get('test1'), 'First key has been deleted.'); - $this->assertFalse($backend_a->get('test2', TRUE), 'Second key has been deleted.'); - $this->assertTrue($backend_b->get('test3'), 'Item in other bin is preserved.'); - } - -} diff --git a/core/modules/system/src/Tests/Cache/PageCacheTagsTestBase.php b/core/modules/system/src/Tests/Cache/PageCacheTagsTestBase.php deleted file mode 100644 index 578eb9e71d..0000000000 --- a/core/modules/system/src/Tests/Cache/PageCacheTagsTestBase.php +++ /dev/null @@ -1,69 +0,0 @@ -config('system.performance'); - $config->set('cache.page.max_age', 3600); - $config->save(); - } - - /** - * Verify that when loading a given page, it's a page cache hit or miss. - * - * @param \Drupal\Core\Url $url - * The page for this URL will be loaded. - * @param string $hit_or_miss - * 'HIT' if a page cache hit is expected, 'MISS' otherwise. - * - * @param array|false $tags - * When expecting a page cache hit, you may optionally specify an array of - * expected cache tags. While FALSE, the cache tags will not be verified. - */ - protected function verifyPageCache(Url $url, $hit_or_miss, $tags = FALSE) { - $this->drupalGet($url); - $message = new FormattableMarkup('Page cache @hit_or_miss for %path.', ['@hit_or_miss' => $hit_or_miss, '%path' => $url->toString()]); - $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), $hit_or_miss, $message); - - if ($hit_or_miss === 'HIT' && is_array($tags)) { - $absolute_url = $url->setAbsolute()->toString(); - $cid_parts = [$absolute_url, 'html']; - $cid = implode(':', $cid_parts); - $cache_entry = \Drupal::cache('page')->get($cid); - sort($cache_entry->tags); - $tags = array_unique($tags); - sort($tags); - $this->assertIdentical($cache_entry->tags, $tags); - } - } - -} diff --git a/core/modules/system/src/Tests/Database/DatabaseWebTestBase.php b/core/modules/system/src/Tests/Database/DatabaseWebTestBase.php deleted file mode 100644 index ed40e58d58..0000000000 --- a/core/modules/system/src/Tests/Database/DatabaseWebTestBase.php +++ /dev/null @@ -1,31 +0,0 @@ -grantPermission('view test entity'); - $user_role->save(); - - // Create an entity. - $this->entity = $this->createEntity(); - - // If this is an entity with field UI enabled, then add a configurable - // field. We will use this configurable field in later tests to ensure that - // field configuration invalidate render cache entries. - if ($this->entity->getEntityType()->get('field_ui_base_route')) { - // Add field, so we can modify the field storage and field entities to - // verify that changes to those indeed clear cache tags. - FieldStorageConfig::create([ - 'field_name' => 'configurable_field', - 'entity_type' => $this->entity->getEntityTypeId(), - 'type' => 'test_field', - 'settings' => [], - ])->save(); - FieldConfig::create([ - 'entity_type' => $this->entity->getEntityTypeId(), - 'bundle' => $this->entity->bundle(), - 'field_name' => 'configurable_field', - 'label' => 'Configurable field', - 'settings' => [], - ])->save(); - - // Reload the entity now that a new field has been added to it. - $storage = $this->container - ->get('entity_type.manager') - ->getStorage($this->entity->getEntityTypeId()); - $storage->resetCache(); - $this->entity = $storage->load($this->entity->id()); - } - - // Create a referencing and a non-referencing entity. - list( - $this->referencingEntity, - $this->nonReferencingEntity, - ) = $this->createReferenceTestEntities($this->entity); - } - - /** - * Generates standardized entity cache tags test info. - * - * @param string $entity_type_label - * The label of the entity type whose cache tags to test. - * @param string $group - * The test group. - * - * @return array - * - * @see \Drupal\simpletest\TestBase::getInfo() - */ - protected static function generateStandardizedInfo($entity_type_label, $group) { - return [ - 'name' => "$entity_type_label entity cache tags", - 'description' => "Test the $entity_type_label entity's cache tags.", - 'group' => $group, - ]; - } - - /** - * Creates the entity to be tested. - * - * @return \Drupal\Core\Entity\EntityInterface - * The entity to be tested. - */ - abstract protected function createEntity(); - - /** - * Returns the access cache contexts for the tested entity. - * - * Only list cache contexts that aren't part of the required cache contexts. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity to be tested, as created by createEntity(). - * - * @return string[] - * An array of the additional cache contexts. - * - * @see \Drupal\Core\Entity\EntityAccessControlHandlerInterface - */ - protected function getAccessCacheContextsForEntity(EntityInterface $entity) { - return []; - } - - /** - * Returns the additional (non-standard) cache contexts for the tested entity. - * - * Only list cache contexts that aren't part of the required cache contexts. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity to be tested, as created by createEntity(). - * - * @return string[] - * An array of the additional cache contexts. - * - * @see \Drupal\system\Tests\Entity\EntityCacheTagsTestBase::createEntity() - */ - protected function getAdditionalCacheContextsForEntity(EntityInterface $entity) { - return []; - } - - /** - * Returns the additional (non-standard) cache tags for the tested entity. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity to be tested, as created by createEntity(). - * @return array - * An array of the additional cache tags. - * - * @see \Drupal\system\Tests\Entity\EntityCacheTagsTestBase::createEntity() - */ - protected function getAdditionalCacheTagsForEntity(EntityInterface $entity) { - return []; - } - - /** - * Returns the additional cache tags for the tested entity's listing by type. - * - * @return string[] - * An array of the additional cache contexts. - */ - protected function getAdditionalCacheContextsForEntityListing() { - return []; - } - - /** - * Returns the additional cache tags for the tested entity's listing by type. - * - * Necessary when there are unavoidable default entities of this type, e.g. - * the anonymous and administrator User entities always exist. - * - * @return array - * An array of the additional cache tags. - */ - protected function getAdditionalCacheTagsForEntityListing() { - return []; - } - - /** - * Selects the preferred view mode for the given entity type. - * - * Prefers 'full', picks the first one otherwise, and if none are available, - * chooses 'default'. - */ - protected function selectViewMode($entity_type) { - $view_modes = \Drupal::entityTypeManager() - ->getStorage('entity_view_mode') - ->loadByProperties(['targetEntityType' => $entity_type]); - - if (empty($view_modes)) { - return 'default'; - } - else { - // Prefer the "full" display mode. - if (isset($view_modes[$entity_type . '.full'])) { - return 'full'; - } - else { - $view_modes = array_keys($view_modes); - return substr($view_modes[0], strlen($entity_type) + 1); - } - } - } - - /** - * Creates a referencing and a non-referencing entity for testing purposes. - * - * @param \Drupal\Core\Entity\EntityInterface $referenced_entity - * The entity that the referencing entity should reference. - * - * @return \Drupal\Core\Entity\EntityInterface[] - * An array containing a referencing entity and a non-referencing entity. - */ - protected function createReferenceTestEntities($referenced_entity) { - // All referencing entities should be of the type 'entity_test'. - $entity_type = 'entity_test'; - - // Create a "foo" bundle for the given entity type. - $bundle = 'foo'; - entity_test_create_bundle($bundle, NULL, $entity_type); - - // Add a field of the given type to the given entity type's "foo" bundle. - $field_name = $referenced_entity->getEntityTypeId() . '_reference'; - FieldStorageConfig::create([ - 'field_name' => $field_name, - 'entity_type' => $entity_type, - 'type' => 'entity_reference', - 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, - 'settings' => [ - 'target_type' => $referenced_entity->getEntityTypeId(), - ], - ])->save(); - FieldConfig::create([ - 'field_name' => $field_name, - 'entity_type' => $entity_type, - 'bundle' => $bundle, - 'settings' => [ - 'handler' => 'default', - 'handler_settings' => [ - 'target_bundles' => [ - $referenced_entity->bundle() => $referenced_entity->bundle(), - ], - 'sort' => ['field' => '_none'], - 'auto_create' => FALSE, - ], - ], - ])->save(); - /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */ - $display_repository = \Drupal::service('entity_display.repository'); - - if (!$this->entity->getEntityType()->hasHandlerClass('view_builder')) { - $display_repository->getViewDisplay($entity_type, $bundle, 'full') - ->setComponent($field_name, [ - 'type' => 'entity_reference_label', - ]) - ->save(); - } - else { - $referenced_entity_view_mode = $this->selectViewMode($this->entity->getEntityTypeId()); - $display_repository->getViewDisplay($entity_type, $bundle, 'full') - ->setComponent($field_name, [ - 'type' => 'entity_reference_entity_view', - 'settings' => [ - 'view_mode' => $referenced_entity_view_mode, - ], - ]) - ->save(); - } - - // Create an entity that does reference the entity being tested. - $label_key = \Drupal::entityTypeManager()->getDefinition($entity_type)->getKey('label'); - $referencing_entity = $this->container->get('entity_type.manager') - ->getStorage($entity_type) - ->create([ - $label_key => 'Referencing ' . $entity_type, - 'status' => 1, - 'type' => $bundle, - $field_name => ['target_id' => $referenced_entity->id()], - ]); - $referencing_entity->save(); - - // Create an entity that does not reference the entity being tested. - $non_referencing_entity = $this->container->get('entity_type.manager') - ->getStorage($entity_type) - ->create([ - $label_key => 'Non-referencing ' . $entity_type, - 'status' => 1, - 'type' => $bundle, - ]); - $non_referencing_entity->save(); - - return [ - $referencing_entity, - $non_referencing_entity, - ]; - } - - /** - * Tests cache tags presence and invalidation of the entity when referenced. - * - * Tests the following cache tags: - * - entity type view cache tag: "_view" - * - entity cache tag: ":" - * - entity type list cache tag: "_list" - * - referencing entity type view cache tag: "_view" - * - referencing entity type cache tag: ":" - */ - public function testReferencedEntity() { - $entity_type = $this->entity->getEntityTypeId(); - $referencing_entity_url = $this->referencingEntity->toUrl('canonical'); - $non_referencing_entity_url = $this->nonReferencingEntity->toUrl('canonical'); - $listing_url = Url::fromRoute('entity.entity_test.collection_referencing_entities', [ - 'entity_reference_field_name' => $entity_type . '_reference', - 'referenced_entity_type' => $entity_type, - 'referenced_entity_id' => $this->entity->id(), - ]); - $empty_entity_listing_url = Url::fromRoute('entity.entity_test.collection_empty', ['entity_type_id' => $entity_type]); - $nonempty_entity_listing_url = Url::fromRoute('entity.entity_test.collection_labels_alphabetically', ['entity_type_id' => $entity_type]); - - // The default cache contexts for rendered entities. - $default_cache_contexts = ['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'user.permissions']; - $entity_cache_contexts = $default_cache_contexts; - $page_cache_contexts = Cache::mergeContexts($default_cache_contexts, ['url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT]); - - // Cache tags present on every rendered page. - // 'user.permissions' is a required cache context, and responses that vary - // by this cache context when requested by anonymous users automatically - // also get this cache tag, to ensure correct invalidation. - $page_cache_tags = Cache::mergeTags(['http_response', 'rendered'], ['config:user.role.anonymous']); - // If the block module is used, the Block page display variant is used, - // which adds the block config entity type's list cache tags. - $page_cache_tags = Cache::mergeTags($page_cache_tags, \Drupal::moduleHandler()->moduleExists('block') ? ['config:block_list'] : []); - - $page_cache_tags_referencing_entity = in_array('user.permissions', $this->getAccessCacheContextsForEntity($this->referencingEntity)) ? ['config:user.role.anonymous'] : []; - - $view_cache_tag = []; - if ($this->entity->getEntityType()->hasHandlerClass('view_builder')) { - $view_cache_tag = \Drupal::entityTypeManager()->getViewBuilder($entity_type) - ->getCacheTags(); - } - - $context_metadata = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($entity_cache_contexts); - $cache_context_tags = $context_metadata->getCacheTags(); - - // Generate the cache tags for the (non) referencing entities. - $referencing_entity_cache_tags = Cache::mergeTags($this->referencingEntity->getCacheTags(), \Drupal::entityTypeManager()->getViewBuilder('entity_test')->getCacheTags()); - // Includes the main entity's cache tags, since this entity references it. - $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags, $this->entity->getCacheTags()); - $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags, $this->getAdditionalCacheTagsForEntity($this->entity)); - $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags, $view_cache_tag); - $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags, $cache_context_tags); - $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags, ['rendered']); - - $non_referencing_entity_cache_tags = Cache::mergeTags($this->nonReferencingEntity->getCacheTags(), \Drupal::entityTypeManager()->getViewBuilder('entity_test')->getCacheTags()); - $non_referencing_entity_cache_tags = Cache::mergeTags($non_referencing_entity_cache_tags, ['rendered']); - - // Generate the cache tags for all two possible entity listing paths. - // 1. list cache tag only (listing query has no match) - // 2. list cache tag plus entity cache tag (listing query has a match) - $empty_entity_listing_cache_tags = Cache::mergeTags($this->entity->getEntityType()->getListCacheTags(), $page_cache_tags); - - $nonempty_entity_listing_cache_tags = Cache::mergeTags($this->entity->getEntityType()->getListCacheTags(), $this->entity->getCacheTags()); - $nonempty_entity_listing_cache_tags = Cache::mergeTags($nonempty_entity_listing_cache_tags, $this->getAdditionalCacheTagsForEntityListing($this->entity)); - $nonempty_entity_listing_cache_tags = Cache::mergeTags($nonempty_entity_listing_cache_tags, $page_cache_tags); - - $this->pass("Test referencing entity.", 'Debug'); - $this->verifyPageCache($referencing_entity_url, 'MISS'); - - // Verify a cache hit, but also the presence of the correct cache tags. - $expected_tags = Cache::mergeTags($referencing_entity_cache_tags, $page_cache_tags); - $expected_tags = Cache::mergeTags($expected_tags, $page_cache_tags_referencing_entity); - $this->verifyPageCache($referencing_entity_url, 'HIT', $expected_tags); - - // Also verify the existence of an entity render cache entry. - $cache_keys = ['entity_view', 'entity_test', $this->referencingEntity->id(), 'full']; - $cid = $this->createCacheId($cache_keys, $entity_cache_contexts); - $access_cache_contexts = $this->getAccessCacheContextsForEntity($this->entity); - $additional_cache_contexts = $this->getAdditionalCacheContextsForEntity($this->referencingEntity); - $redirected_cid = NULL; - if (count($access_cache_contexts) || count($additional_cache_contexts)) { - $cache_contexts = Cache::mergeContexts($entity_cache_contexts, $additional_cache_contexts); - $cache_contexts = Cache::mergeContexts($cache_contexts, $access_cache_contexts); - $redirected_cid = $this->createCacheId($cache_keys, $cache_contexts); - $context_metadata = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($cache_contexts); - $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags, $context_metadata->getCacheTags()); - } - $this->verifyRenderCache($cid, $referencing_entity_cache_tags, $redirected_cid); - - $this->pass("Test non-referencing entity.", 'Debug'); - $this->verifyPageCache($non_referencing_entity_url, 'MISS'); - // Verify a cache hit, but also the presence of the correct cache tags. - $this->verifyPageCache($non_referencing_entity_url, 'HIT', Cache::mergeTags($non_referencing_entity_cache_tags, $page_cache_tags)); - // Also verify the existence of an entity render cache entry. - $cache_keys = ['entity_view', 'entity_test', $this->nonReferencingEntity->id(), 'full']; - $cid = $this->createCacheId($cache_keys, $entity_cache_contexts); - $this->verifyRenderCache($cid, $non_referencing_entity_cache_tags); - - $this->pass("Test listing of referencing entities.", 'Debug'); - // Prime the page cache for the listing of referencing entities. - $this->verifyPageCache($listing_url, 'MISS'); - - // Verify a cache hit, but also the presence of the correct cache tags. - $expected_tags = Cache::mergeTags($referencing_entity_cache_tags, $page_cache_tags); - $expected_tags = Cache::mergeTags($expected_tags, $page_cache_tags_referencing_entity); - $this->verifyPageCache($listing_url, 'HIT', $expected_tags); - - $this->pass("Test empty listing.", 'Debug'); - // Prime the page cache for the empty listing. - $this->verifyPageCache($empty_entity_listing_url, 'MISS'); - // Verify a cache hit, but also the presence of the correct cache tags. - $this->verifyPageCache($empty_entity_listing_url, 'HIT', $empty_entity_listing_cache_tags); - // Verify the entity type's list cache contexts are present. - $contexts_in_header = $this->drupalGetHeader('X-Drupal-Cache-Contexts'); - $this->assertEqual(Cache::mergeContexts($page_cache_contexts, $this->getAdditionalCacheContextsForEntityListing()), empty($contexts_in_header) ? [] : explode(' ', $contexts_in_header)); - - $this->pass("Test listing containing referenced entity.", 'Debug'); - // Prime the page cache for the listing containing the referenced entity. - $this->verifyPageCache($nonempty_entity_listing_url, 'MISS', $nonempty_entity_listing_cache_tags); - // Verify a cache hit, but also the presence of the correct cache tags. - $this->verifyPageCache($nonempty_entity_listing_url, 'HIT', $nonempty_entity_listing_cache_tags); - // Verify the entity type's list cache contexts are present. - $contexts_in_header = $this->drupalGetHeader('X-Drupal-Cache-Contexts'); - $this->assertEqual(Cache::mergeContexts($page_cache_contexts, $this->getAdditionalCacheContextsForEntityListing()), empty($contexts_in_header) ? [] : explode(' ', $contexts_in_header)); - - // Verify that after modifying the referenced entity, there is a cache miss - // for every route except the one for the non-referencing entity. - $this->pass("Test modification of referenced entity.", 'Debug'); - $this->entity->save(); - $this->verifyPageCache($referencing_entity_url, 'MISS'); - $this->verifyPageCache($listing_url, 'MISS'); - $this->verifyPageCache($empty_entity_listing_url, 'MISS'); - $this->verifyPageCache($nonempty_entity_listing_url, 'MISS'); - $this->verifyPageCache($non_referencing_entity_url, 'HIT'); - - // Verify cache hits. - $this->verifyPageCache($referencing_entity_url, 'HIT'); - $this->verifyPageCache($listing_url, 'HIT'); - $this->verifyPageCache($empty_entity_listing_url, 'HIT'); - $this->verifyPageCache($nonempty_entity_listing_url, 'HIT'); - - // Verify that after modifying the referencing entity, there is a cache miss - // for every route except the ones for the non-referencing entity and the - // empty entity listing. - $this->pass("Test modification of referencing entity.", 'Debug'); - $this->referencingEntity->save(); - $this->verifyPageCache($referencing_entity_url, 'MISS'); - $this->verifyPageCache($listing_url, 'MISS'); - $this->verifyPageCache($nonempty_entity_listing_url, 'HIT'); - $this->verifyPageCache($non_referencing_entity_url, 'HIT'); - $this->verifyPageCache($empty_entity_listing_url, 'HIT'); - - // Verify cache hits. - $this->verifyPageCache($referencing_entity_url, 'HIT'); - $this->verifyPageCache($listing_url, 'HIT'); - $this->verifyPageCache($nonempty_entity_listing_url, 'HIT'); - - // Verify that after modifying the non-referencing entity, there is a cache - // miss only for the non-referencing entity route. - $this->pass("Test modification of non-referencing entity.", 'Debug'); - $this->nonReferencingEntity->save(); - $this->verifyPageCache($referencing_entity_url, 'HIT'); - $this->verifyPageCache($listing_url, 'HIT'); - $this->verifyPageCache($empty_entity_listing_url, 'HIT'); - $this->verifyPageCache($nonempty_entity_listing_url, 'HIT'); - $this->verifyPageCache($non_referencing_entity_url, 'MISS'); - - // Verify cache hits. - $this->verifyPageCache($non_referencing_entity_url, 'HIT'); - - if ($this->entity->getEntityType()->hasHandlerClass('view_builder')) { - // Verify that after modifying the entity's display, there is a cache miss - // for both the referencing entity, and the listing of referencing - // entities, but not for any other routes. - $referenced_entity_view_mode = $this->selectViewMode($this->entity->getEntityTypeId()); - $this->pass("Test modification of referenced entity's '$referenced_entity_view_mode' display.", 'Debug'); - $entity_display = \Drupal::service('entity_display.repository') - ->getViewDisplay($entity_type, $this->entity->bundle(), $referenced_entity_view_mode); - $entity_display->save(); - $this->verifyPageCache($referencing_entity_url, 'MISS'); - $this->verifyPageCache($listing_url, 'MISS'); - $this->verifyPageCache($non_referencing_entity_url, 'HIT'); - $this->verifyPageCache($empty_entity_listing_url, 'HIT'); - $this->verifyPageCache($nonempty_entity_listing_url, 'HIT'); - - // Verify cache hits. - $this->verifyPageCache($referencing_entity_url, 'HIT'); - $this->verifyPageCache($listing_url, 'HIT'); - } - - if ($bundle_entity_type_id = $this->entity->getEntityType()->getBundleEntityType()) { - // Verify that after modifying the corresponding bundle entity, there is a - // cache miss for both the referencing entity, and the listing of - // referencing entities, but not for any other routes. - $this->pass("Test modification of referenced entity's bundle entity.", 'Debug'); - $bundle_entity = $this->container->get('entity_type.manager') - ->getStorage($bundle_entity_type_id) - ->load($this->entity->bundle()); - $bundle_entity->save(); - $this->verifyPageCache($referencing_entity_url, 'MISS'); - $this->verifyPageCache($listing_url, 'MISS'); - $this->verifyPageCache($non_referencing_entity_url, 'HIT'); - // Special case: entity types may choose to use their bundle entity type - // cache tags, to avoid having excessively granular invalidation. - $is_special_case = $bundle_entity->getCacheTags() == $this->entity->getCacheTags() && $bundle_entity->getEntityType()->getListCacheTags() == $this->entity->getEntityType()->getListCacheTags(); - if ($is_special_case) { - $this->verifyPageCache($empty_entity_listing_url, 'MISS'); - $this->verifyPageCache($nonempty_entity_listing_url, 'MISS'); - } - else { - $this->verifyPageCache($empty_entity_listing_url, 'HIT'); - $this->verifyPageCache($nonempty_entity_listing_url, 'HIT'); - } - - // Verify cache hits. - $this->verifyPageCache($referencing_entity_url, 'HIT'); - $this->verifyPageCache($listing_url, 'HIT'); - if ($is_special_case) { - $this->verifyPageCache($empty_entity_listing_url, 'HIT'); - $this->verifyPageCache($nonempty_entity_listing_url, 'HIT'); - } - } - - if ($this->entity->getEntityType()->get('field_ui_base_route')) { - // Verify that after modifying a configurable field on the entity, there - // is a cache miss. - $this->pass("Test modification of referenced entity's configurable field.", 'Debug'); - $field_storage_name = $this->entity->getEntityTypeId() . '.configurable_field'; - $field_storage = FieldStorageConfig::load($field_storage_name); - $field_storage->save(); - $this->verifyPageCache($referencing_entity_url, 'MISS'); - $this->verifyPageCache($listing_url, 'MISS'); - $this->verifyPageCache($empty_entity_listing_url, 'HIT'); - $this->verifyPageCache($nonempty_entity_listing_url, 'HIT'); - $this->verifyPageCache($non_referencing_entity_url, 'HIT'); - - // Verify cache hits. - $this->verifyPageCache($referencing_entity_url, 'HIT'); - $this->verifyPageCache($listing_url, 'HIT'); - - // Verify that after modifying a configurable field on the entity, there - // is a cache miss. - $this->pass("Test modification of referenced entity's configurable field.", 'Debug'); - $field_name = $this->entity->getEntityTypeId() . '.' . $this->entity->bundle() . '.configurable_field'; - $field = FieldConfig::load($field_name); - $field->save(); - $this->verifyPageCache($referencing_entity_url, 'MISS'); - $this->verifyPageCache($listing_url, 'MISS'); - $this->verifyPageCache($empty_entity_listing_url, 'HIT'); - $this->verifyPageCache($nonempty_entity_listing_url, 'HIT'); - $this->verifyPageCache($non_referencing_entity_url, 'HIT'); - - // Verify cache hits. - $this->verifyPageCache($referencing_entity_url, 'HIT'); - $this->verifyPageCache($listing_url, 'HIT'); - } - - // Verify that after invalidating the entity's cache tag directly, there is - // a cache miss for every route except the ones for the non-referencing - // entity and the empty entity listing. - $this->pass("Test invalidation of referenced entity's cache tag.", 'Debug'); - Cache::invalidateTags($this->entity->getCacheTagsToInvalidate()); - $this->verifyPageCache($referencing_entity_url, 'MISS'); - $this->verifyPageCache($listing_url, 'MISS'); - $this->verifyPageCache($nonempty_entity_listing_url, 'MISS'); - $this->verifyPageCache($non_referencing_entity_url, 'HIT'); - $this->verifyPageCache($empty_entity_listing_url, 'HIT'); - - // Verify cache hits. - $this->verifyPageCache($referencing_entity_url, 'HIT'); - $this->verifyPageCache($listing_url, 'HIT'); - $this->verifyPageCache($nonempty_entity_listing_url, 'HIT'); - - // Verify that after invalidating the entity's list cache tag directly, - // there is a cache miss for both the empty entity listing and the non-empty - // entity listing routes, but not for other routes. - $this->pass("Test invalidation of referenced entity's list cache tag.", 'Debug'); - Cache::invalidateTags($this->entity->getEntityType()->getListCacheTags()); - $this->verifyPageCache($empty_entity_listing_url, 'MISS'); - $this->verifyPageCache($nonempty_entity_listing_url, 'MISS'); - $this->verifyPageCache($referencing_entity_url, 'HIT'); - $this->verifyPageCache($non_referencing_entity_url, 'HIT'); - $this->verifyPageCache($listing_url, 'HIT'); - - // Verify cache hits. - $this->verifyPageCache($empty_entity_listing_url, 'HIT'); - $this->verifyPageCache($nonempty_entity_listing_url, 'HIT'); - - if (!empty($view_cache_tag)) { - // Verify that after invalidating the generic entity type's view cache tag - // directly, there is a cache miss for both the referencing entity, and the - // listing of referencing entities, but not for other routes. - $this->pass("Test invalidation of referenced entity's 'view' cache tag.", 'Debug'); - Cache::invalidateTags($view_cache_tag); - $this->verifyPageCache($referencing_entity_url, 'MISS'); - $this->verifyPageCache($listing_url, 'MISS'); - $this->verifyPageCache($non_referencing_entity_url, 'HIT'); - $this->verifyPageCache($empty_entity_listing_url, 'HIT'); - $this->verifyPageCache($nonempty_entity_listing_url, 'HIT'); - - // Verify cache hits. - $this->verifyPageCache($referencing_entity_url, 'HIT'); - $this->verifyPageCache($listing_url, 'HIT'); - } - - // Verify that after deleting the entity, there is a cache miss for every - // route except for the non-referencing entity one. - $this->pass('Test deletion of referenced entity.', 'Debug'); - $this->entity->delete(); - $this->verifyPageCache($referencing_entity_url, 'MISS'); - $this->verifyPageCache($listing_url, 'MISS'); - $this->verifyPageCache($empty_entity_listing_url, 'MISS'); - $this->verifyPageCache($nonempty_entity_listing_url, 'MISS'); - $this->verifyPageCache($non_referencing_entity_url, 'HIT'); - - // Verify cache hits. - $referencing_entity_cache_tags = Cache::mergeTags($this->referencingEntity->getCacheTags(), \Drupal::entityTypeManager()->getViewBuilder('entity_test')->getCacheTags()); - $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags, ['http_response', 'rendered']); - - $nonempty_entity_listing_cache_tags = Cache::mergeTags($this->entity->getEntityType()->getListCacheTags(), $this->getAdditionalCacheTagsForEntityListing()); - $nonempty_entity_listing_cache_tags = Cache::mergeTags($nonempty_entity_listing_cache_tags, $page_cache_tags); - - $this->verifyPageCache($referencing_entity_url, 'HIT', Cache::mergeTags($referencing_entity_cache_tags, $page_cache_tags)); - $this->verifyPageCache($listing_url, 'HIT', $page_cache_tags); - $this->verifyPageCache($empty_entity_listing_url, 'HIT', $empty_entity_listing_cache_tags); - $this->verifyPageCache($nonempty_entity_listing_url, 'HIT', $nonempty_entity_listing_cache_tags); - } - - /** - * Creates a cache ID from a list of cache keys and a set of cache contexts. - * - * @param string[] $keys - * A list of cache keys. - * @param string[] $contexts - * A set of cache contexts. - * - * @return string - * The cache ID string. - */ - protected function createCacheId(array $keys, array $contexts) { - $cid_parts = $keys; - - $contexts = \Drupal::service('cache_contexts_manager')->convertTokensToKeys($contexts); - $cid_parts = array_merge($cid_parts, $contexts->getKeys()); - - return implode(':', $cid_parts); - } - - /** - * Verify that a given render cache entry exists, with the correct cache tags. - * - * @param string $cid - * The render cache item ID. - * @param array $tags - * An array of expected cache tags. - * @param string|null $redirected_cid - * (optional) The redirected render cache item ID. - */ - protected function verifyRenderCache($cid, array $tags, $redirected_cid = NULL) { - // Also verify the existence of an entity render cache entry. - $cache_entry = \Drupal::cache('render')->get($cid); - $this->assertTrue($cache_entry, 'A render cache entry exists.'); - sort($cache_entry->tags); - sort($tags); - $this->assertIdentical($cache_entry->tags, $tags); - $is_redirecting_cache_item = isset($cache_entry->data['#cache_redirect']); - if ($redirected_cid === NULL) { - $this->assertFalse($is_redirecting_cache_item, 'Render cache entry is not a redirect.'); - // If this is a redirecting cache item unlike we expected, log it. - if ($is_redirecting_cache_item) { - debug($cache_entry->data); - } - } - else { - // Verify that $cid contains a cache redirect. - $this->assertTrue($is_redirecting_cache_item, 'Render cache entry is a redirect.'); - // If this is not a redirecting cache item unlike we expected, log it. - if (!$is_redirecting_cache_item) { - debug($cache_entry->data); - } - // Verify that the cache redirect points to the expected CID. - $redirect_cache_metadata = $cache_entry->data['#cache']; - $actual_redirection_cid = $this->createCacheId( - $redirect_cache_metadata['keys'], - $redirect_cache_metadata['contexts'] - ); - $this->assertIdentical($redirected_cid, $actual_redirection_cid); - // Finally, verify that the redirected CID exists and has the same cache - // tags. - $this->verifyRenderCache($redirected_cid, $tags); - } - } - -} diff --git a/core/modules/system/src/Tests/Entity/EntityWithUriCacheTagsTestBase.php b/core/modules/system/src/Tests/Entity/EntityWithUriCacheTagsTestBase.php deleted file mode 100644 index 9d49c882cd..0000000000 --- a/core/modules/system/src/Tests/Entity/EntityWithUriCacheTagsTestBase.php +++ /dev/null @@ -1,157 +0,0 @@ -_view" - * - ":" - */ - public function testEntityUri() { - $entity_url = $this->entity->toUrl(); - $entity_type = $this->entity->getEntityTypeId(); - - // Selects the view mode that will be used. - $view_mode = $this->selectViewMode($entity_type); - - // The default cache contexts for rendered entities. - $entity_cache_contexts = $this->getDefaultCacheContexts(); - - // Generate the standardized entity cache tags. - $cache_tag = $this->entity->getCacheTags(); - $view_cache_tag = \Drupal::entityTypeManager()->getViewBuilder($entity_type)->getCacheTags(); - $render_cache_tag = 'rendered'; - - $this->pass("Test entity.", 'Debug'); - $this->verifyPageCache($entity_url, 'MISS'); - - // Verify a cache hit, but also the presence of the correct cache tags. - $this->verifyPageCache($entity_url, 'HIT'); - - // Also verify the existence of an entity render cache entry, if this entity - // type supports render caching. - if (\Drupal::entityTypeManager()->getDefinition($entity_type)->isRenderCacheable()) { - $cache_keys = ['entity_view', $entity_type, $this->entity->id(), $view_mode]; - $cid = $this->createCacheId($cache_keys, $entity_cache_contexts); - $redirected_cid = NULL; - $additional_cache_contexts = $this->getAdditionalCacheContextsForEntity($this->entity); - if (count($additional_cache_contexts)) { - $redirected_cid = $this->createCacheId($cache_keys, Cache::mergeContexts($entity_cache_contexts, $additional_cache_contexts)); - } - $expected_cache_tags = Cache::mergeTags($cache_tag, $view_cache_tag); - $expected_cache_tags = Cache::mergeTags($expected_cache_tags, $this->getAdditionalCacheTagsForEntity($this->entity)); - $expected_cache_tags = Cache::mergeTags($expected_cache_tags, [$render_cache_tag]); - $this->verifyRenderCache($cid, $expected_cache_tags, $redirected_cid); - } - - // Verify that after modifying the entity, there is a cache miss. - $this->pass("Test modification of entity.", 'Debug'); - $this->entity->save(); - $this->verifyPageCache($entity_url, 'MISS'); - - // Verify a cache hit. - $this->verifyPageCache($entity_url, 'HIT'); - - // Verify that after modifying the entity's display, there is a cache miss. - $this->pass("Test modification of entity's '$view_mode' display.", 'Debug'); - $entity_display = \Drupal::service('entity_display.repository') - ->getViewDisplay($entity_type, $this->entity->bundle(), $view_mode); - $entity_display->save(); - $this->verifyPageCache($entity_url, 'MISS'); - - // Verify a cache hit. - $this->verifyPageCache($entity_url, 'HIT'); - - if ($bundle_entity_type_id = $this->entity->getEntityType()->getBundleEntityType()) { - // Verify that after modifying the corresponding bundle entity, there is a - // cache miss. - $this->pass("Test modification of entity's bundle entity.", 'Debug'); - $bundle_entity = $this->container->get('entity_type.manager') - ->getStorage($bundle_entity_type_id) - ->load($this->entity->bundle()); - $bundle_entity->save(); - $this->verifyPageCache($entity_url, 'MISS'); - - // Verify a cache hit. - $this->verifyPageCache($entity_url, 'HIT'); - } - - if ($this->entity->getEntityType()->get('field_ui_base_route')) { - // Verify that after modifying a configurable field on the entity, there - // is a cache miss. - $this->pass("Test modification of entity's configurable field.", 'Debug'); - $field_storage_name = $this->entity->getEntityTypeId() . '.configurable_field'; - $field_storage = FieldStorageConfig::load($field_storage_name); - $field_storage->save(); - $this->verifyPageCache($entity_url, 'MISS'); - - // Verify a cache hit. - $this->verifyPageCache($entity_url, 'HIT'); - - // Verify that after modifying a configurable field on the entity, there - // is a cache miss. - $this->pass("Test modification of entity's configurable field.", 'Debug'); - $field_name = $this->entity->getEntityTypeId() . '.' . $this->entity->bundle() . '.configurable_field'; - $field = FieldConfig::load($field_name); - $field->save(); - $this->verifyPageCache($entity_url, 'MISS'); - - // Verify a cache hit. - $this->verifyPageCache($entity_url, 'HIT'); - } - - // Verify that after invalidating the entity's cache tag directly, there is - // a cache miss. - $this->pass("Test invalidation of entity's cache tag.", 'Debug'); - Cache::invalidateTags($this->entity->getCacheTagsToInvalidate()); - $this->verifyPageCache($entity_url, 'MISS'); - - // Verify a cache hit. - $this->verifyPageCache($entity_url, 'HIT'); - - // Verify that after invalidating the generic entity type's view cache tag - // directly, there is a cache miss. - $this->pass("Test invalidation of entity's 'view' cache tag.", 'Debug'); - Cache::invalidateTags($view_cache_tag); - $this->verifyPageCache($entity_url, 'MISS'); - - // Verify a cache hit. - $this->verifyPageCache($entity_url, 'HIT'); - - // Verify that after deleting the entity, there is a cache miss. - $this->pass('Test deletion of entity.', 'Debug'); - $this->entity->delete(); - $this->verifyPageCache($entity_url, 'MISS'); - $this->assertResponse(404); - } - - /** - * Gets the default cache contexts for rendered entities. - * - * @return array - * The default cache contexts for rendered entities. - */ - protected function getDefaultCacheContexts() { - return ['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'user.permissions']; - } - -} diff --git a/core/modules/system/src/Tests/Image/ToolkitTestBase.php b/core/modules/system/src/Tests/Image/ToolkitTestBase.php deleted file mode 100644 index fd8c7e245f..0000000000 --- a/core/modules/system/src/Tests/Image/ToolkitTestBase.php +++ /dev/null @@ -1,161 +0,0 @@ -imageFactory = $this->container->get('image.factory'); - - // Pick a file for testing. - $file = current($this->drupalGetTestFiles('image')); - $this->file = $file->uri; - - // Setup a dummy image to work with. - $this->image = $this->getImage(); - - // Clear out any hook calls. - $this->imageTestReset(); - } - - /** - * Sets up an image with the custom toolkit. - * - * @return \Drupal\Core\Image\ImageInterface - * The image object. - */ - protected function getImage() { - $image = $this->imageFactory->get($this->file, 'test'); - $this->assertTrue($image->isValid(), 'Image file was parsed.'); - return $image; - } - - /** - * Assert that all of the specified image toolkit operations were called - * exactly once once, other values result in failure. - * - * @param $expected - * Array with string containing with the operation name, e.g. 'load', - * 'save', 'crop', etc. - */ - public function assertToolkitOperationsCalled(array $expected) { - // If one of the image operations is expected, apply should be expected as - // well. - $operations = [ - 'resize', - 'rotate', - 'crop', - 'desaturate', - 'create_new', - 'scale', - 'scale_and_crop', - 'my_operation', - 'convert', - ]; - if (count(array_intersect($expected, $operations)) > 0 && !in_array('apply', $expected)) { - $expected[] = 'apply'; - } - - // Determine which operations were called. - $actual = array_keys(array_filter($this->imageTestGetAllCalls())); - - // Determine if there were any expected that were not called. - $uncalled = array_diff($expected, $actual); - if (count($uncalled)) { - $this->assertTrue(FALSE, new FormattableMarkup('Expected operations %expected to be called but %uncalled was not called.', ['%expected' => implode(', ', $expected), '%uncalled' => implode(', ', $uncalled)])); - } - else { - $this->assertTrue(TRUE, new FormattableMarkup('All the expected operations were called: %expected', ['%expected' => implode(', ', $expected)])); - } - - // Determine if there were any unexpected calls. - // If all unexpected calls are operations and apply was expected, we do not - // count it as an error. - $unexpected = array_diff($actual, $expected); - if (count($unexpected) && (!in_array('apply', $expected) || count(array_intersect($unexpected, $operations)) !== count($unexpected))) { - $this->assertTrue(FALSE, new FormattableMarkup('Unexpected operations were called: %unexpected.', ['%unexpected' => implode(', ', $unexpected)])); - } - else { - $this->assertTrue(TRUE, 'No unexpected operations were called.'); - } - } - - /** - * Resets/initializes the history of calls to the test toolkit functions. - */ - public function imageTestReset() { - // Keep track of calls to these operations - $results = [ - 'parseFile' => [], - 'save' => [], - 'settings' => [], - 'apply' => [], - 'resize' => [], - 'rotate' => [], - 'crop' => [], - 'desaturate' => [], - 'create_new' => [], - 'scale' => [], - 'scale_and_crop' => [], - 'convert' => [], - ]; - \Drupal::state()->set('image_test.results', $results); - } - - /** - * Gets an array of calls to the test toolkit. - * - * @return array - * An array keyed by operation name ('parseFile', 'save', 'settings', - * 'resize', 'rotate', 'crop', 'desaturate') with values being arrays of - * parameters passed to each call. - */ - public function imageTestGetAllCalls() { - return \Drupal::state()->get('image_test.results') ?: []; - } - -} diff --git a/core/modules/system/src/Tests/Installer/ConfigAfterInstallerTestBase.php b/core/modules/system/src/Tests/Installer/ConfigAfterInstallerTestBase.php deleted file mode 100644 index ea83c7569e..0000000000 --- a/core/modules/system/src/Tests/Installer/ConfigAfterInstallerTestBase.php +++ /dev/null @@ -1,49 +0,0 @@ -container->get('config.storage'); - /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */ - $config_manager = $this->container->get('config.manager'); - - $default_install_path = 'core/profiles/' . $this->profile . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY; - $profile_config_storage = new FileStorage($default_install_path, StorageInterface::DEFAULT_COLLECTION); - - foreach ($profile_config_storage->listAll() as $config_name) { - $result = $config_manager->diff($profile_config_storage, $active_config_storage, $config_name); - try { - $this->assertConfigDiff($result, $config_name, $skipped_config); - } - catch (\Exception $e) { - $this->fail($e->getMessage()); - } - } - } - -} diff --git a/core/modules/system/src/Tests/Menu/AssertBreadcrumbTrait.php b/core/modules/system/src/Tests/Menu/AssertBreadcrumbTrait.php deleted file mode 100644 index 9104f3bbb3..0000000000 --- a/core/modules/system/src/Tests/Menu/AssertBreadcrumbTrait.php +++ /dev/null @@ -1,117 +0,0 @@ -drupalGet($goto); - } - $this->assertBreadcrumbParts($trail); - - // Additionally assert page title, if given. - if (isset($page_title)) { - $this->assertTitle(strtr('@title | Drupal', ['@title' => $page_title])); - } - - // Additionally assert active trail in a menu tree output, if given. - if ($tree) { - $this->assertMenuActiveTrail($tree, $last_active); - } - } - - /** - * Assert that a trail exists in the internal browser. - * - * @param array $trail - * An associative array whose keys are expected breadcrumb link paths and - * whose values are expected breadcrumb link texts (not sanitized). - */ - protected function assertBreadcrumbParts($trail) { - // Compare paths with actual breadcrumb. - $parts = $this->getBreadcrumbParts(); - $pass = TRUE; - // There may be more than one breadcrumb on the page. If $trail is empty - // this test would go into an infinite loop, so we need to check that too. - while ($trail && !empty($parts)) { - foreach ($trail as $path => $title) { - // If the path is empty, generate the path from the route. If - // the path does not start with a leading slash, then run it through - // Url::fromUri('base:')->toString() to get the correct base - // prepended. - if ($path == '') { - $url = Url::fromRoute('')->toString(); - } - elseif ($path[0] != '/') { - $url = Url::fromUri('base:' . $path)->toString(); - } - else { - $url = $path; - } - $part = array_shift($parts); - $pass = ($pass && $part['href'] === $url && $part['text'] === Html::escape($title)); - } - } - // No parts must be left, or an expected "Home" will always pass. - $pass = ($pass && empty($parts)); - - $this->assertTrue($pass, new FormattableMarkup('Breadcrumb %parts found on @path.', [ - '%parts' => implode(' » ', $trail), - '@path' => $this->getUrl(), - ])); - } - - /** - * Returns the breadcrumb contents of the current page in the internal browser. - */ - protected function getBreadcrumbParts() { - $parts = []; - $elements = $this->xpath('//nav[@class="breadcrumb"]/ol/li/a'); - if (!empty($elements)) { - foreach ($elements as $element) { - $parts[] = [ - 'text' => (string) $element, - 'href' => (string) $element['href'], - 'title' => (string) $element['title'], - ]; - } - } - return $parts; - } - -} diff --git a/core/modules/system/src/Tests/Menu/AssertMenuActiveTrailTrait.php b/core/modules/system/src/Tests/Menu/AssertMenuActiveTrailTrait.php deleted file mode 100644 index ff4ce1b44f..0000000000 --- a/core/modules/system/src/Tests/Menu/AssertMenuActiveTrailTrait.php +++ /dev/null @@ -1,71 +0,0 @@ - $link_title) { - $part_xpath = (!$i ? '//' : '/following-sibling::ul/descendant::'); - $part_xpath .= 'li[contains(@class, :class)]/a[contains(@href, :href) and contains(text(), :title)]'; - $part_args = [ - ':class' => 'menu-item--active-trail', - ':href' => Url::fromUri('base:' . $link_path)->toString(), - ':title' => $link_title, - ]; - $xpath .= $this->buildXPathQuery($part_xpath, $part_args); - $i++; - } - $elements = $this->xpath($xpath); - $this->assertTrue(!empty($elements), 'Active trail to current page was found in menu tree.'); - - // Append prefix for active link asserted below. - $xpath .= '/following-sibling::ul/descendant::'; - } - else { - $xpath .= '//'; - } - $xpath_last_active = ($last_active ? 'and contains(@class, :class-active)' : ''); - $xpath .= 'li[contains(@class, :class-trail)]/a[contains(@href, :href) ' . $xpath_last_active . 'and contains(text(), :title)]'; - $args = [ - ':class-trail' => 'menu-item--active-trail', - ':class-active' => 'is-active', - ':href' => Url::fromUri('base:' . $active_link_path)->toString(), - ':title' => $active_link_title, - ]; - $elements = $this->xpath($xpath, $args); - $this->assertTrue(!empty($elements), new FormattableMarkup('Active link %title was found in menu tree, including active trail links %tree.', [ - '%title' => $active_link_title, - '%tree' => implode(' » ', $tree), - ])); - } - -} diff --git a/core/modules/system/src/Tests/Menu/MenuTestBase.php b/core/modules/system/src/Tests/Menu/MenuTestBase.php deleted file mode 100644 index 4769293380..0000000000 --- a/core/modules/system/src/Tests/Menu/MenuTestBase.php +++ /dev/null @@ -1,19 +0,0 @@ -adminUser = $this->drupalCreateUser(['access administration pages', 'administer modules']); - $this->drupalLogin($this->adminUser); - } - - /** - * Assert there are tables that begin with the specified base table name. - * - * @param $base_table - * Beginning of table name to look for. - * @param $count - * (optional) Whether or not to assert that there are tables that match the - * specified base table. Defaults to TRUE. - */ - public function assertTableCount($base_table, $count = TRUE) { - $connection = Database::getConnection(); - $tables = $connection->schema()->findTables($connection->prefixTables('{' . $base_table . '}') . '%'); - - if ($count) { - return $this->assertTrue($tables, new FormattableMarkup('Tables matching "@base_table" found.', ['@base_table' => $base_table])); - } - return $this->assertFalse($tables, new FormattableMarkup('Tables matching "@base_table" not found.', ['@base_table' => $base_table])); - } - - /** - * Assert that all tables defined in a module's hook_schema() exist. - * - * @param $module - * The name of the module. - */ - public function assertModuleTablesExist($module) { - $tables = array_keys(drupal_get_module_schema($module)); - $tables_exist = TRUE; - $schema = Database::getConnection()->schema(); - foreach ($tables as $table) { - if (!$schema->tableExists($table)) { - $tables_exist = FALSE; - } - } - return $this->assertTrue($tables_exist, new FormattableMarkup('All database tables defined by the @module module exist.', ['@module' => $module])); - } - - /** - * Assert that none of the tables defined in a module's hook_schema() exist. - * - * @param $module - * The name of the module. - */ - public function assertModuleTablesDoNotExist($module) { - $tables = array_keys(drupal_get_module_schema($module)); - $tables_exist = FALSE; - $schema = Database::getConnection()->schema(); - foreach ($tables as $table) { - if ($schema->tableExists($table)) { - $tables_exist = TRUE; - } - } - return $this->assertFalse($tables_exist, new FormattableMarkup('None of the database tables defined by the @module module exist.', ['@module' => $module])); - } - - /** - * Asserts that the default configuration of a module has been installed. - * - * @param string $module - * The name of the module. - * - * @return bool|null - * TRUE if configuration has been installed, FALSE otherwise. Returns NULL - * if the module configuration directory does not exist or does not contain - * any configuration files. - */ - public function assertModuleConfig($module) { - $module_config_dir = drupal_get_path('module', $module) . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY; - if (!is_dir($module_config_dir)) { - return; - } - $module_file_storage = new FileStorage($module_config_dir); - - // Verify that the module's default config directory is not empty and - // contains default configuration files (instead of something else). - $all_names = $module_file_storage->listAll(); - if (empty($all_names)) { - // Module has an empty config directory. For example it might contain a - // schema directory. - return; - } - $this->assertTrue($all_names); - - // Look up each default configuration object name in the active - // configuration, and if it exists, remove it from the stack. - // Only default config that belongs to $module is guaranteed to exist; any - // other default config depends on whether other modules are enabled. Thus, - // list all default config once more, but filtered by $module. - $names = $module_file_storage->listAll($module . '.'); - foreach ($names as $key => $name) { - if ($this->config($name)->get()) { - unset($names[$key]); - } - } - // Verify that all configuration has been installed (which means that $names - // is empty). - return $this->assertFalse($names, new FormattableMarkup('All default configuration of @module module found.', ['@module' => $module])); - } - - /** - * Asserts that no configuration exists for a given module. - * - * @param string $module - * The name of the module. - * - * @return bool - * TRUE if no configuration was found, FALSE otherwise. - */ - public function assertNoModuleConfig($module) { - $names = \Drupal::configFactory()->listAll($module . '.'); - return $this->assertFalse($names, new FormattableMarkup('No configuration found for @module module.', ['@module' => $module])); - } - - /** - * Assert the list of modules are enabled or disabled. - * - * @param $modules - * Module list to check. - * @param $enabled - * Expected module state. - */ - public function assertModules(array $modules, $enabled) { - $this->rebuildContainer(); - foreach ($modules as $module) { - if ($enabled) { - $message = 'Module "@module" is enabled.'; - } - else { - $message = 'Module "@module" is not enabled.'; - } - $this->assertEqual($this->container->get('module_handler')->moduleExists($module), $enabled, new FormattableMarkup($message, ['@module' => $module])); - } - } - - /** - * Verify a log entry was entered for a module's status change. - * - * @param $type - * The category to which this message belongs. - * @param $message - * The message to store in the log. Keep $message translatable - * by not concatenating dynamic values into it! Variables in the - * message should be added by using placeholder strings alongside - * the variables argument to declare the value of the placeholders. - * See t() for documentation on how $message and $variables interact. - * @param $variables - * Array of variables to replace in the message on display or - * NULL if message is already translated or not possible to - * translate. - * @param $severity - * The severity of the message, as per RFC 3164. - * @param $link - * A link to associate with the message. - */ - public function assertLogMessage($type, $message, $variables = [], $severity = RfcLogLevel::NOTICE, $link = '') { - $count = Database::getConnection()->select('watchdog', 'w') - ->condition('type', $type) - ->condition('message', $message) - ->condition('variables', serialize($variables)) - ->condition('severity', $severity) - ->condition('link', $link) - ->countQuery() - ->execute() - ->fetchField(); - $this->assertTrue($count > 0, new FormattableMarkup('watchdog table contains @count rows for @message', ['@count' => $count, '@message' => new FormattableMarkup($message, $variables)])); - } - -} diff --git a/core/modules/system/src/Tests/System/SystemConfigFormTestBase.php b/core/modules/system/src/Tests/System/SystemConfigFormTestBase.php deleted file mode 100644 index be134c7710..0000000000 --- a/core/modules/system/src/Tests/System/SystemConfigFormTestBase.php +++ /dev/null @@ -1,75 +0,0 @@ - array( - * '#value' => $this->randomString(), - * '#config_name' => 'user.mail', - * '#config_key' => 'cancel_confirm.body', - * ), - * ); - * @endcode - * - * @var array - */ - protected $values; - - /** - * Submit the system_config_form ensure the configuration has expected values. - */ - public function testConfigForm() { - // Programmatically submit the given values. - $values = []; - foreach ($this->values as $form_key => $data) { - $values[$form_key] = $data['#value']; - } - $form_state = (new FormState())->setValues($values); - \Drupal::formBuilder()->submitForm($this->form, $form_state); - - // Check that the form returns an error when expected, and vice versa. - $errors = $form_state->getErrors(); - $valid_form = empty($errors); - $args = [ - '%values' => print_r($values, TRUE), - '%errors' => $valid_form ? t('None') : implode(' ', $errors), - ]; - $this->assertTrue($valid_form, new FormattableMarkup('Input values: %values
Validation handler errors: %errors', $args)); - - foreach ($this->values as $data) { - $this->assertEqual($data['#value'], $this->config($data['#config_name'])->get($data['#config_key'])); - } - } - -} diff --git a/core/modules/system/src/Tests/Update/DbUpdatesTrait.php b/core/modules/system/src/Tests/Update/DbUpdatesTrait.php deleted file mode 100644 index e25832b7bd..0000000000 --- a/core/modules/system/src/Tests/Update/DbUpdatesTrait.php +++ /dev/null @@ -1,61 +0,0 @@ -container->get('state')->set($module . '.db_updates.' . $group, $index); - } - - /** - * Applies any pending DB updates through the Update UI. - */ - protected function applyUpdates() { - $this->drupalGet(Url::fromRoute('system.db_update')); - $this->clickLink($this->t('Continue')); - $this->clickLink($this->t('Apply pending updates')); - } - - /** - * Conditionally load Update API functions for the specified group. - * - * @param string $module - * The name of the module defining the update functions. - * @param string $group - * A name identifying the group of update functions to enable. - */ - public static function includeUpdates($module, $group) { - if ($index = \Drupal::state()->get($module . '.db_updates.' . $group)) { - module_load_include('inc', $module, 'update/' . $group . '_' . $index); - } - } - -} diff --git a/core/modules/system/src/Tests/Update/UpdatePathTestBase.php b/core/modules/system/src/Tests/Update/UpdatePathTestBase.php deleted file mode 100644 index e231862c6d..0000000000 --- a/core/modules/system/src/Tests/Update/UpdatePathTestBase.php +++ /dev/null @@ -1,358 +0,0 @@ -databaseDumpFiles variable to the - * database dump files, and then call parent::setUp() to run the base setUp() - * method in this class. - * - In your test method, call $this->runUpdates() to run the necessary updates, - * and then use test assertions to verify that the result is what you expect. - * - In order to test both with a "bare" database dump as well as with a - * database dump filled with content, extend your update path test class with - * a new test class that overrides the bare database dump. Refer to - * UpdatePathTestBaseFilledTest for an example. - * - * @ingroup update_api - * - * @deprecated in drupal:8.4.0 and is removed from drupal:9.0.0. - * Use \Drupal\FunctionalTests\Update\UpdatePathTestBase. - * @see https://www.drupal.org/node/2896640 - * - * @see hook_update_N() - */ -abstract class UpdatePathTestBase extends WebTestBase { - - use SchemaCheckTestTrait; - - /** - * Modules to enable after the database is loaded. - */ - protected static $modules = []; - - /** - * The file path(s) to the dumped database(s) to load into the child site. - * - * The file system/tests/fixtures/update/drupal-8.bare.standard.php.gz is - * normally included first -- this sets up the base database from a bare - * standard Drupal installation. - * - * The file system/tests/fixtures/update/drupal-8.filled.standard.php.gz - * can also be used in case we want to test with a database filled with - * content, and with all core modules enabled. - * - * @var array - */ - protected $databaseDumpFiles = []; - - /** - * The install profile used in the database dump file. - * - * @var string - */ - protected $installProfile = 'standard'; - - /** - * Flag that indicates whether the child site has been updated. - * - * @var bool - */ - protected $upgradedSite = FALSE; - - /** - * Array of errors triggered during the update process. - * - * @var array - */ - protected $upgradeErrors = []; - - /** - * Array of modules loaded when the test starts. - * - * @var array - */ - protected $loadedModules = []; - - /** - * Flag to indicate whether zlib is installed or not. - * - * @var bool - */ - protected $zlibInstalled = TRUE; - - /** - * Flag to indicate whether there are pending updates or not. - * - * @var bool - */ - protected $pendingUpdates = TRUE; - - /** - * The update URL. - * - * @var string - */ - protected $updateUrl; - - /** - * Disable strict config schema checking. - * - * The schema is verified at the end of running the update. - * - * @var bool - */ - protected $strictConfigSchema = FALSE; - - /** - * Fail the test if there are failed updates. - * - * @var bool - */ - protected $checkFailedUpdates = TRUE; - - /** - * Constructs an UpdatePathTestCase object. - * - * @param $test_id - * (optional) The ID of the test. Tests with the same id are reported - * together. - */ - public function __construct($test_id = NULL) { - parent::__construct($test_id); - $this->zlibInstalled = function_exists('gzopen'); - } - - /** - * Overrides WebTestBase::setUp() for update testing. - * - * The main difference in this method is that rather than performing the - * installation via the installer, a database is loaded. Additional work is - * then needed to set various things such as the config directories and the - * container that would normally be done via the installer. - */ - protected function setUp() { - $this->runDbTasks(); - // Allow classes to set database dump files. - $this->setDatabaseDumpFiles(); - - // We are going to set a missing zlib requirement property for usage - // during the performUpgrade() and tearDown() methods. Also set that the - // tests failed. - if (!$this->zlibInstalled) { - parent::setUp(); - return; - } - - // Set the update url. This must be set here rather than in - // self::__construct() or the old URL generator will leak additional test - // sites. - $this->updateUrl = Url::fromRoute('system.db_update'); - - // These methods are called from parent::setUp(). - $this->setBatch(); - $this->initUserSession(); - $this->prepareSettings(); - - // Load the database(s). - foreach ($this->databaseDumpFiles as $file) { - if (substr($file, -3) == '.gz') { - $file = "compress.zlib://$file"; - } - require $file; - } - - $this->initSettings(); - $request = Request::createFromGlobals(); - $container = $this->initKernel($request); - $this->initConfig($container); - - // Restore the original Simpletest batch. - $this->restoreBatch(); - - // Set the container. parent::rebuildAll() would normally do this, but this - // not safe to do here, because the database has not been updated yet. - $this->container = \Drupal::getContainer(); - - $this->replaceUser1(); - - require_once \Drupal::root() . '/core/includes/update.inc'; - } - - /** - * Set database dump files to be used. - */ - abstract protected function setDatabaseDumpFiles(); - - /** - * Add settings that are missed since the installer isn't run. - */ - protected function prepareSettings() { - parent::prepareSettings(); - - // Remember the profile which was used. - $settings['settings']['install_profile'] = (object) [ - 'value' => $this->installProfile, - 'required' => TRUE, - ]; - // Generate a hash salt. - $settings['settings']['hash_salt'] = (object) [ - 'value' => Crypt::randomBytesBase64(55), - 'required' => TRUE, - ]; - - // Since the installer isn't run, add the database settings here too. - $settings['databases']['default'] = (object) [ - 'value' => Database::getConnectionInfo(), - 'required' => TRUE, - ]; - - $this->writeSettings($settings); - } - - /** - * Helper function to run pending database updates. - */ - protected function runUpdates() { - if (!$this->zlibInstalled) { - $this->fail('Missing zlib requirement for update tests.'); - return FALSE; - } - // The site might be broken at the time so logging in using the UI might - // not work, so we use the API itself. - drupal_rewrite_settings([ - 'settings' => [ - 'update_free_access' => (object) [ - 'value' => TRUE, - 'required' => TRUE, - ], - ], - ]); - - $this->drupalGet($this->updateUrl); - $this->clickLink(t('Continue')); - - $this->doSelectionTest(); - // Run the update hooks. - $this->clickLink(t('Apply pending updates')); - - // Ensure there are no failed updates. - if ($this->checkFailedUpdates) { - $this->assertNoRaw('' . t('Failed:') . ''); - - // Ensure that there are no pending updates. - foreach (['update', 'post_update'] as $update_type) { - switch ($update_type) { - case 'update': - $all_updates = update_get_update_list(); - break; - case 'post_update': - $all_updates = \Drupal::service('update.post_update_registry')->getPendingUpdateInformation(); - break; - } - foreach ($all_updates as $module => $updates) { - if (!empty($updates['pending'])) { - foreach (array_keys($updates['pending']) as $update_name) { - $this->fail("The $update_name() update function from the $module module did not run."); - } - } - } - } - // Reset the static cache of drupal_get_installed_schema_version() so that - // more complex update path testing works. - drupal_static_reset('drupal_get_installed_schema_version'); - - // The config schema can be incorrect while the update functions are being - // executed. But once the update has been completed, it needs to be valid - // again. Assert the schema of all configuration objects now. - $names = $this->container->get('config.storage')->listAll(); - /** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config */ - $typed_config = $this->container->get('config.typed'); - $typed_config->clearCachedDefinitions(); - foreach ($names as $name) { - $config = $this->config($name); - $this->assertConfigSchema($typed_config, $name, $config->get()); - } - - // Ensure that the update hooks updated all entity schema. - $needs_updates = \Drupal::entityDefinitionUpdateManager()->needsUpdates(); - $this->assertFalse($needs_updates, 'After all updates ran, entity schema is up to date.'); - if ($needs_updates) { - foreach (\Drupal::entityDefinitionUpdateManager() - ->getChangeSummary() as $entity_type_id => $summary) { - foreach ($summary as $message) { - $this->fail($message); - } - } - } - } - } - - /** - * Runs the install database tasks for the driver used by the test runner. - */ - protected function runDbTasks() { - // Create a minimal container so that t() works. - // @see install_begin_request() - $container = new ContainerBuilder(); - $container->setParameter('language.default_values', Language::$defaultValues); - $container - ->register('language.default', 'Drupal\Core\Language\LanguageDefault') - ->addArgument('%language.default_values%'); - $container - ->register('string_translation', 'Drupal\Core\StringTranslation\TranslationManager') - ->addArgument(new Reference('language.default')); - \Drupal::setContainer($container); - - require_once __DIR__ . '/../../../../../includes/install.inc'; - $connection = Database::getConnection(); - $errors = db_installer_object($connection->driver())->runTasks(); - if (!empty($errors)) { - $this->fail('Failed to run installer database tasks: ' . implode(', ', $errors)); - } - } - - /** - * Replace User 1 with the user created here. - */ - protected function replaceUser1() { - /** @var \Drupal\user\UserInterface $account */ - // @todo: Saving the account before the update is problematic. - // https://www.drupal.org/node/2560237 - $account = User::load(1); - $account->setPassword($this->rootUser->pass_raw); - $account->setEmail($this->rootUser->getEmail()); - $account->setUsername($this->rootUser->getAccountName()); - $account->save(); - } - - /** - * Tests the selection page. - */ - protected function doSelectionTest() { - // No-op. Tests wishing to do test the selection page or the general - // update.php environment before running update.php can override this method - // and implement their required tests. - } - -} diff --git a/core/modules/system/system.install b/core/modules/system/system.install index fb3d5eac82..e6ee8bdd0a 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -526,38 +526,6 @@ function system_requirements($phase) { } } - // Test that path.temporary config is not set. - if ($phase == 'runtime') { - if (!Settings::get('file_temp_path')) { - $filesystem_config = \Drupal::config('system.file'); - if ($temp_path = $filesystem_config->get('path.temporary')) { - $requirements['temp_directory'] = [ - 'title' => t('Temporary Directory'), - 'severity' => REQUIREMENT_WARNING, - 'value' => 'Deprecated configuration', - 'description' => [ - [ - '#markup' => t('You are using deprecated configuration for the temporary files path.'), - '#suffix' => ' ', - ], - ], - ]; - if ($temp_path === FileSystemComponent::getOsTemporaryDirectory()) { - $requirements['temp_directory']['description'][] = [ - '#markup' => t('Your temporary directory configuration matches the OS default and can be safely removed.'), - '#suffix' => ' ', - ]; - } - else { - $requirements['temp_directory']['description'][] = [ - '#markup' => t('Remove the configuration and add the following to settings.php. $settings["file_temp_path"] = "%temp_path"', ['%temp_path' => $temp_path]), - '#suffix' => ' ', - ]; - } - } - } - } - // Report cron status. if ($phase == 'runtime') { $cron_config = \Drupal::config('system.cron'); diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 0baa96a6b3..d6d910eba5 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -13,10 +13,7 @@ use Drupal\Core\Block\BlockPluginInterface; use Drupal\Core\Cache\Cache; use Drupal\Core\Database\Query\AlterableInterface; -use Drupal\Core\Extension\Dependency; use Drupal\Core\Extension\Extension; -use Drupal\Core\Entity\Display\EntityFormDisplayInterface; -use Drupal\Core\Field\Plugin\Field\FieldWidget\EntityReferenceAutocompleteWidget; use Drupal\Core\File\Exception\FileException; use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Form\FormStateInterface; @@ -962,110 +959,6 @@ function system_check_directory($form_element, FormStateInterface $form_state) { return $form_element; } -/** - * Returns an array of information about enabled modules or themes. - * - * This function returns the contents of the .info.yml file for each installed - * module or theme. - * - * @param $type - * Either 'module' or 'theme'. - * @param $name - * (optional) The name of a module or theme whose information shall be - * returned. If omitted, all records for the provided $type will be returned. - * If $name does not exist in the provided $type or is not enabled, an empty - * array will be returned. - * - * @return - * An associative array of module or theme information keyed by name, or only - * information for $name, if given. If no records are available, an empty - * array is returned. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use - * \Drupal::service('extension.list.$type')->getExtensionInfo() or - * \Drupal::service('extension.list.$type')->getAllInstalledInfo() instead. - * - * @see https://www.drupal.org/node/2709919 - * @see \Drupal\Core\Extension\ModuleExtensionList::getList() - * @see \Drupal\Core\Extension\ThemeExtensionList - */ -function system_get_info($type, $name = NULL) { - @trigger_error("system_get_info() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal::service('extension.list.$type')->getExtensionInfo() or \Drupal::service('extension.list.$type')->getAllInstalledInfo() instead. See https://www.drupal.org/node/2709919", E_USER_DEPRECATED); - /** @var \Drupal\Core\Extension\ExtensionList $extension_list */ - $extension_list = \Drupal::service('extension.list.' . $type); - if (isset($name)) { - try { - return $extension_list->getExtensionInfo($name); - } - catch (\InvalidArgumentException $e) { - return []; - } - } - return $extension_list->getAllInstalledInfo(); -} - -/** - * Ensures that dependencies of required modules are also required. - * - * @param \Drupal\Core\Extension\Extension $module - * The module info. - * @param \Drupal\Core\Extension\Extension[] $modules - * The array of all module info. - * - * @deprecated in drupal:8.5.0 and is removed from drupal:9.0.0. This - * function is no longer used in Drupal core. - * - * @see https://www.drupal.org/node/2709919 - */ -function _system_rebuild_module_data_ensure_required($module, &$modules) { - @trigger_error("_system_rebuild_module_data_ensure_required() is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. This function is no longer used in Drupal core. See https://www.drupal.org/node/2709919", E_USER_DEPRECATED); - if (!empty($module->info['required'])) { - foreach ($module->info['dependencies'] as $dependency) { - $dependency_name = Dependency::createFromString($dependency)->getName(); - if (!isset($modules[$dependency_name]->info['required'])) { - $modules[$dependency_name]->info['required'] = TRUE; - $modules[$dependency_name]->info['explanation'] = t('Dependency of required module @module', ['@module' => $module->info['name']]); - // Ensure any dependencies it has are required. - _system_rebuild_module_data_ensure_required($modules[$dependency_name], $modules); - } - } - } -} - -/** - * Helper function to scan and collect module .info.yml data. - * - * @return \Drupal\Core\Extension\Extension[] - * An associative array of module information. - * - * @deprecated in drupal:8.5.0 and is removed from drupal:9.0.0. - * Use \Drupal::service('extension.list.module')->reset()->getList() - * instead. Note: You probably don't need the reset() method. - * - * @see https://www.drupal.org/node/2709919 - */ -function _system_rebuild_module_data() { - @trigger_error("_system_rebuild_module_data() is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Instead, you should use \\Drupal::service('extension.list.module')->reset()->getList(). See https://www.drupal.org/node/2709919", E_USER_DEPRECATED); - return \Drupal::service('extension.list.module')->reset()->getList(); -} - -/** - * Rebuild, save, and return data about all currently available modules. - * - * @return \Drupal\Core\Extension\Extension[] - * Array of all available modules and their data. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. - * Use \Drupal::service('extension.list.module')->getList() instead. - * Note: use reset() only when you really need to rescan and rebuild the list. - * - * @see https://www.drupal.org/node/2709919 - */ -function system_rebuild_module_data() { - @trigger_error('system_rebuild_module_data() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Instead, you should use \Drupal::service("extension.list.module")->getList(). See https://www.drupal.org/node/2709919', E_USER_DEPRECATED); - return \Drupal::service('extension.list.module')->reset()->getList(); -} - /** * Get a list of available regions from a specified theme. * @@ -1468,32 +1361,3 @@ function system_modules_uninstalled($modules) { } } } - -/** - * Implements hook_ENTITY_TYPE_presave() for entity_form_display entities. - * - * Provides a BC layer for modules providing old configurations. - * - * @todo Remove this hook in Drupal 9.0.x https://www.drupal.org/project/drupal/issues/3086388 - */ -function system_entity_form_display_presave(EntityFormDisplayInterface $display) { - /** @var \Drupal\Core\Field\WidgetPluginManager $field_widget_manager */ - $field_widget_manager = \Drupal::service('plugin.manager.field.widget'); - - foreach ($display->getComponents() as $field_name => $component) { - if (empty($component['type'])) { - continue; - } - - $plugin_definition = $field_widget_manager->getDefinition($component['type'], FALSE); - if (!is_a($plugin_definition['class'], EntityReferenceAutocompleteWidget::class, TRUE)) { - continue; - } - - if (!isset($component['settings']['match_limit'])) { - @trigger_error(sprintf('Any entity_reference_autocomplete component of an entity_form_display must have a match_limit setting. The %s field on the %s form display is missing it. This BC layer will be removed before 9.0.0. See https://www.drupal.org/node/2863188', $field_name, $display->id()), E_USER_DEPRECATED); - $component['settings']['match_limit'] = 10; - $display->setComponent($field_name, $component); - } - } -} diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index d8fb46e0cf..8eb2c3d740 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -355,106 +355,6 @@ function entity_test_form_node_form_alter(&$form, FormStateInterface $form_state \Drupal::state()->set('entity_test.form_langcode', $langcode); } -/** - * Loads a test entity. - * - * @param int $id - * A test entity ID. - * @param bool $reset - * A boolean indicating that the internal cache should be reset. - * - * @return \Drupal\entity_test\Entity\EntityTest - * The loaded entity object, or NULL if the entity cannot be loaded. - * - * @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use - * \Drupal::entityTypeManager()->getStorage('entity_test')->load(). - * - * @see https://www.drupal.org/node/2266845 - */ -function entity_test_load($id, $reset = FALSE) { - @trigger_error('entity_test_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getStorage(\'entity_test\')->load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED); - $storage = \Drupal::entityTypeManager()->getStorage('entity_test'); - if ($reset) { - $storage->resetCache([$id]); - } - return $storage->load($id); -} - -/** - * Loads a test entity. - * - * @param int $id - * A test entity ID. - * @param bool $reset - * A boolean indicating that the internal cache should be reset. - * - * @return \Drupal\entity_test\Entity\EntityTestRev - * The loaded entity object, or NULL if the entity cannot be loaded. - * - * @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use - * \Drupal::entityTypeManager()->getStorage('entity_test_rev')->load(). - * - * @see https://www.drupal.org/node/2266845 - */ -function entity_test_rev_load($id, $reset = FALSE) { - @trigger_error('entity_test_rev_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getStorage(\'entity_test_rev\')->load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED); - $storage = \Drupal::entityTypeManager()->getStorage('entity_test_rev'); - if ($reset) { - $storage->resetCache([$id]); - } - return $storage->load($id); -} - -/** - * Loads a test entity. - * - * @param int $id - * A test entity ID. - * @param bool $reset - * A boolean indicating that the internal cache should be reset. - * - * @return \Drupal\entity_test\Entity\EntityTestMul - * The loaded entity object, or FALSE if the entity cannot be loaded. - * - * @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use - * \Drupal::entityTypeManager()->getStorage('entity_test_mul')->load(). - * - * @see https://www.drupal.org/node/2266845 - */ -function entity_test_mul_load($id, $reset = FALSE) { - @trigger_error('entity_test_mul_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getStorage(\'entity_test_mul\')->load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED); - $storage = \Drupal::entityTypeManager()->getStorage('entity_test_mul'); - if ($reset) { - $storage->resetCache([$id]); - } - return $storage->load($id); -} - -/** - * Loads a test entity. - * - * @param int $id - * A test entity ID. - * @param bool $reset - * A boolean indicating that the internal cache should be reset. - * - * @return \Drupal\entity_test\Entity\EntityTestMulRev - * The loaded entity object, or NULL if the entity cannot be loaded. - * - * @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use - * \Drupal::entityTypeManager()->getStorage('entity_test_mulrev_load')->load(). - * - * @see https://www.drupal.org/node/2266845 - */ -function entity_test_mulrev_load($id, $reset = FALSE) { - @trigger_error('entity_test_mulrev_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getStorage(\'entity_test_mulrev\')->load(). See https://www.drupal.org/node/2266845', E_USER_DEPRECATED); - $storage = \Drupal::entityTypeManager()->getStorage('entity_test_mulrev'); - if ($reset) { - $storage->resetCache([$id]); - } - return $storage->load($id); -} - /** * Implements hook_ENTITY_TYPE_insert() for 'entity_test'. */ diff --git a/core/modules/system/tests/src/FunctionalJavascript/OffCanvasTestBase.php b/core/modules/system/tests/src/FunctionalJavascript/OffCanvasTestBase.php index 3907768b9c..94ec6cc8e3 100644 --- a/core/modules/system/tests/src/FunctionalJavascript/OffCanvasTestBase.php +++ b/core/modules/system/tests/src/FunctionalJavascript/OffCanvasTestBase.php @@ -95,22 +95,6 @@ protected function getOffCanvasDialog() { return $off_canvas_dialog; } - /** - * Waits for an element to be removed from the page. - * - * @param string $selector - * CSS selector. - * @param int $timeout - * (optional) Timeout in milliseconds, defaults to 10000. - * - * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use - * Drupal\FunctionalJavascriptTests\JSWebAssert::assertNoElementAfterWait() - */ - protected function waitForNoElement($selector, $timeout = 10000) { - @trigger_error('::waitForNoElement is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use \Drupal\FunctionalJavascriptTests\JSWebAssert::assertNoElementAfterWait() instead.', E_USER_DEPRECATED); - $this->assertSession()->assertNoElementAfterWait('css', $selector, $timeout); - } - /** * Get themes to test. * diff --git a/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php b/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php index 8d0ef50df2..35dfa12a4f 100644 --- a/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php +++ b/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php @@ -7,7 +7,6 @@ use Drupal\system\Entity\Menu; use Drupal\block\Entity\Block; use Drupal\Core\Render\Element; -use Drupal\system\Plugin\Block\SystemMenuBlock; use Drupal\system\Tests\Routing\MockRouteProvider; use Drupal\Tests\Core\Menu\MenuLinkMock; use Drupal\user\Entity\User; @@ -354,20 +353,6 @@ public function configExpandedTestCases() { ]; } - /** - * @deprecationMessage The menu.active_trail service must be passed to SystemMenuBlock::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2669550. - * @group legacy - */ - public function testConstructorDeprecation() { - $block = new SystemMenuBlock([], 'test', ['provider' => 'test'], $this->container->get('menu.link_tree')); - - // Ensure the BC layer injects the correct object. - $reflection_object = new \ReflectionObject($block); - $reflection_property = $reflection_object->getProperty('menuActiveTrail'); - $reflection_property->setAccessible(TRUE); - $this->assertSame($reflection_property->getValue($block), $this->container->get('menu.active_trail')); - } - /** * Helper method to allow for easy menu link tree structure assertions. * diff --git a/core/modules/system/tests/src/Kernel/System/SystemGetInfoTest.php b/core/modules/system/tests/src/Kernel/System/SystemGetInfoTest.php deleted file mode 100644 index 881005b026..0000000000 --- a/core/modules/system/tests/src/Kernel/System/SystemGetInfoTest.php +++ /dev/null @@ -1,48 +0,0 @@ -getExtensionInfo() or \Drupal::service('extension.list.module')->getAllInstalledInfo() instead. See https://www.drupal.org/node/2709919 - * @expectedDeprecation system_get_info() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal::service('extension.list.theme')->getExtensionInfo() or \Drupal::service('extension.list.theme')->getAllInstalledInfo() instead. See https://www.drupal.org/node/2709919 - */ - public function testSystemGetInfo() { - $system_module_info = system_get_info('module', 'system'); - $this->assertSame('System', $system_module_info['name']); - $this->assertSame(['system' => $system_module_info], system_get_info('module')); - - // The User module is not installed so system_get_info() should return - // an empty array. - $this->assertSame([], system_get_info('module', 'user')); - - // Install the User module and check system_get_info() returns the correct - // information. - $this->container->get('module_installer')->install(['user']); - $user_module_info = system_get_info('module', 'user'); - $this->assertSame('User', $user_module_info['name']); - $this->assertSame(['system' => $system_module_info, 'user' => $user_module_info], system_get_info('module')); - - // Test theme info. There are no themes installed yet. - $this->assertSame([], system_get_info('theme', 'stable')); - $this->assertSame([], system_get_info('theme')); - $this->container->get('theme_installer')->install(['stable']); - $stable_theme_info = system_get_info('theme', 'stable'); - $this->assertSame('Stable', $stable_theme_info['name']); - $this->assertSame(['stable' => $stable_theme_info], system_get_info('theme')); - } - -} diff --git a/core/modules/system/tests/src/Kernel/SystemFunctionsLegacyTest.php b/core/modules/system/tests/src/Kernel/SystemFunctionsLegacyTest.php deleted file mode 100644 index c047dab267..0000000000 --- a/core/modules/system/tests/src/Kernel/SystemFunctionsLegacyTest.php +++ /dev/null @@ -1,30 +0,0 @@ -getList(). See https://www.drupal.org/node/2709919 - * @see system_rebuild_module_data() - */ - public function testSystemRebuildModuleDataDeprecation() { - $list = system_rebuild_module_data(); - $this->assertInstanceOf(Extension::class, $list['system']); - } - -} diff --git a/core/modules/system/tests/src/Unit/SystemRequirementsTest.php b/core/modules/system/tests/src/Unit/SystemRequirementsTest.php deleted file mode 100644 index 3fbcfedec7..0000000000 --- a/core/modules/system/tests/src/Unit/SystemRequirementsTest.php +++ /dev/null @@ -1,38 +0,0 @@ -assertEquals($expected, SystemRequirements::phpVersionWithPdoDisallowMultipleStatements($version)); - } - - public function providerTestPhpVersionWithPdoDisallowMultipleStatements() { - $data = []; - $data[] = ['5.4.2', FALSE]; - $data[] = ['5.4.21', FALSE]; - $data[] = ['5.5.9', FALSE]; - $data[] = ['5.5.20', FALSE]; - $data[] = ['5.5.21', TRUE]; - $data[] = ['5.5.30', TRUE]; - $data[] = ['5.6.2', FALSE]; - $data[] = ['5.6.5', TRUE]; - $data[] = ['5.5.21', TRUE]; - return $data; - } - -} diff --git a/core/modules/views/tests/src/Kernel/PluginInstanceTest.php b/core/modules/views/tests/src/Kernel/PluginInstanceTest.php index 8000c960c9..4421b1e1f3 100644 --- a/core/modules/views/tests/src/Kernel/PluginInstanceTest.php +++ b/core/modules/views/tests/src/Kernel/PluginInstanceTest.php @@ -40,15 +40,6 @@ class PluginInstanceTest extends ViewsKernelTestBase { 'wizard', ]; - /** - * List of deprecated plugin classes. - * - * @var string[] - */ - protected $deprecatedPlugins = [ - 'Drupal\system\Plugin\views\field\BulkForm', - ]; - /** * An array of plugin definitions, keyed by plugin type. * @@ -80,20 +71,6 @@ public function testPluginData() { $this->assertTrue(empty($diff), 'All plugins were found and matched.'); } - /** - * Tests creating instances of deprecated views plugin. - * - * This will iterate through all plugins from _views_fetch_plugin_data() and - * test only deprecated plugins. - * - * @group legacy - * - * @expectedDeprecation Drupal\system\Plugin\views\field\BulkForm is deprecated in drupal:8.5.0, will be removed before drupal:9.0.0. Use \Drupal\views\Plugin\views\field\BulkForm instead. See https://www.drupal.org/node/2916716. - */ - public function testDeprecatedPluginInstances() { - $this->assertPluginInstances(TRUE); - } - /** * Tests creating instances of every views plugin. * @@ -101,23 +78,17 @@ public function testDeprecatedPluginInstances() { * filtering out deprecated plugins. */ public function testPluginInstances() { - $this->assertPluginInstances(FALSE); + $this->assertPluginInstances(); } /** * Asserts that instances of every views plugin can be created. - * - * @param bool $test_deprecated - * Indicates if deprecated plugins should be tested or skipped. */ - protected function assertPluginInstances($test_deprecated) { + protected function assertPluginInstances() { foreach ($this->definitions as $type => $plugins) { // Get a plugin manager for this type. $manager = $this->container->get("plugin.manager.views.$type"); foreach ($plugins as $id => $definition) { - if ($test_deprecated !== in_array($definition['class'], $this->deprecatedPlugins)) { - continue; - } // Get a reflection class for this plugin. // We only want to test true plugins, i.e. They extend PluginBase. $reflection = new \ReflectionClass($definition['class']);