function ExtensionDiscoveryTest::testExtensionDiscoveryCache
Same name in other branches
- 10 core/tests/Drupal/Tests/Core/Extension/ExtensionDiscoveryTest.php \Drupal\Tests\Core\Extension\ExtensionDiscoveryTest::testExtensionDiscoveryCache()
- 11.x core/tests/Drupal/Tests/Core/Extension/ExtensionDiscoveryTest.php \Drupal\Tests\Core\Extension\ExtensionDiscoveryTest::testExtensionDiscoveryCache()
Tests changing extension discovery file cache objects to arrays.
@covers ::scan @runInSeparateProcess
File
-
core/
tests/ Drupal/ Tests/ Core/ Extension/ ExtensionDiscoveryTest.php, line 73
Class
- ExtensionDiscoveryTest
- Tests discovery of extensions.
Namespace
Drupal\Tests\Core\ExtensionCode
public function testExtensionDiscoveryCache() {
// Set up an extension object in the cache to mimic site prior to changing
// \Drupal\Core\Extension\ExtensionDiscovery::scanDirectory() to cache an
// array instead of an object. Note we cannot use the VFS file system
// because FileCache does not support stream wrappers.
$extension = new Extension($this->root, 'module', 'core/modules/user/user.info.yml', 'user.module');
$extension->subpath = 'modules/user';
$extension->origin = 'core';
// Undo \Drupal\Tests\UnitTestCase::setUp() so FileCache works.
FileCacheFactory::setConfiguration([]);
$file_cache = FileCacheFactory::get('extension_discovery');
$file_cache->set($this->root . '/core/modules/user/user.info.yml', $extension);
// Create an ExtensionDiscovery object to test.
$extension_discovery = new ExtensionDiscovery($this->root, TRUE, [], 'sites/default');
$modules = $extension_discovery->scan('module', FALSE);
$this->assertArrayHasKey('user', $modules);
$this->assertEquals((array) $extension, (array) $modules['user']);
$this->assertNotSame($extension, $modules['user']);
// FileCache item should now be an array.
$this->assertSame([
'type' => 'module',
'pathname' => 'core/modules/user/user.info.yml',
'filename' => 'user.module',
'subpath' => 'modules/user',
], $file_cache->get($this->root . '/core/modules/user/user.info.yml'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.