Same filename and directory in other branches
- 8.9.x core/modules/system/tests/src/Kernel/PhpStorage/PhpStorageFactoryTest.php
- 9 core/modules/system/tests/src/Kernel/PhpStorage/PhpStorageFactoryTest.php
Namespace
Drupal\Tests\system\Kernel\PhpStorage
File
core/modules/system/tests/src/Kernel/PhpStorage/PhpStorageFactoryTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\system\Kernel\PhpStorage;
use Drupal\Component\PhpStorage\MTimeProtectedFileStorage;
use Drupal\Core\PhpStorage\PhpStorageFactory;
use Drupal\Core\Site\Settings;
use Drupal\Core\StreamWrapper\PublicStream;
use Drupal\system\PhpStorage\MockPhpStorage;
use Drupal\KernelTests\KernelTestBase;
class PhpStorageFactoryTest extends KernelTestBase {
protected function setUp() : void {
parent::setUp();
$settings = Settings::getAll();
unset($settings['php_storage']);
new Settings($settings);
}
public function testGetNoSettings() {
$php = PhpStorageFactory::get('test');
$this
->assertInstanceOf(MTimeProtectedFileStorage::class, $php);
}
public function testGetDefault() {
$this
->setSettings();
$php = PhpStorageFactory::get('test');
$this
->assertInstanceOf(MockPhpStorage::class, $php);
}
public function testGetOverride() {
$this
->setSettings('test');
$php = PhpStorageFactory::get('test');
$this
->assertInstanceOf(MockPhpStorage::class, $php);
$this
->setSettings('test', [
'bin' => NULL,
]);
$php = PhpStorageFactory::get('test');
$this
->assertInstanceOf(MockPhpStorage::class, $php);
$this
->assertSame('test', $php
->getConfigurationValue('bin'), 'Name value was used for bin.');
$this
->setSettings('test', [
'directory' => NULL,
]);
$php = PhpStorageFactory::get('test');
$this
->assertInstanceOf(MockPhpStorage::class, $php);
$this
->assertSame(PublicStream::basePath() . '/php', $php
->getConfigurationValue('directory'), 'Default file directory was used.');
$this
->setSettings('test', [
'class' => NULL,
]);
$php = PhpStorageFactory::get('test');
$this
->assertInstanceOf(MTimeProtectedFileStorage::class, $php);
$this
->setSettings('test');
$php = PhpStorageFactory::get('test');
$this
->assertNotEquals('mock hash salt', $php
->getConfigurationValue('secret'), 'The default secret is not used if a secret is set in the overridden settings.');
$this
->setSettings('test', [
'secret' => NULL,
]);
$php = PhpStorageFactory::get('test');
$this
->assertSame('mock hash salt', $php
->getConfigurationValue('secret'), 'The default secret is used if one is not set in the overridden settings.');
}
protected function setSettings($name = 'default', array $configuration = []) {
$settings['php_storage'][$name] = $configuration + [
'class' => 'Drupal\\system\\PhpStorage\\MockPhpStorage',
'directory' => 'tmp://',
'secret' => $this
->randomString(),
'bin' => 'test',
];
$settings['hash_salt'] = 'mock hash salt';
new Settings($settings);
}
}
Classes