class FileCacheFactoryTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php \Drupal\Tests\Component\FileCache\FileCacheFactoryTest
@coversDefaultClass \Drupal\Component\FileCache\FileCacheFactory @group FileCache
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Component\FileCache\FileCacheFactoryTest
Expanded class hierarchy of FileCacheFactoryTest
File
- core/
tests/ Drupal/ Tests/ Component/ FileCache/ FileCacheFactoryTest.php, line 17 - Contains \Drupal\Tests\Component\FileCache\FileCacheFactoryTest.
Namespace
Drupal\Tests\Component\FileCacheView source
class FileCacheFactoryTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$settings = [
'collection' => 'test-23',
'cache_backend_class' => '\\Drupal\\Tests\\Component\\FileCache\\StaticFileCacheBackend',
'cache_backend_configuration' => [
'bin' => 'dog',
],
];
$configuration = FileCacheFactory::getConfiguration();
if (!$configuration) {
$configuration = [];
}
$configuration += [
'test_foo_settings' => $settings,
];
FileCacheFactory::setConfiguration($configuration);
FileCacheFactory::setPrefix('prefix');
}
/**
* @covers ::get
*/
public function testGet() {
$file_cache = FileCacheFactory::get('test_foo_settings', []);
// Ensure the right backend and configuration is used.
$filename = __DIR__ . '/Fixtures/llama-23.txt';
$realpath = realpath($filename);
$cid = 'prefix:test-23:' . $realpath;
$file_cache
->set($filename, 23);
$static_cache = new StaticFileCacheBackend([
'bin' => 'dog',
]);
$result = $static_cache
->fetch([
$cid,
]);
$this
->assertNotEmpty($result);
// Cleanup static caches.
$file_cache
->delete($filename);
}
/**
* @covers ::get
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Required prefix configuration is missing
*/
public function testGetNoPrefix() {
FileCacheFactory::setPrefix(NULL);
FileCacheFactory::get('test_foo_settings', []);
}
/**
* @covers ::getConfiguration
* @covers ::setConfiguration
*/
public function testGetSetConfiguration() {
$configuration = FileCacheFactory::getConfiguration();
$configuration['test_foo_bar'] = [
'bar' => 'llama',
];
FileCacheFactory::setConfiguration($configuration);
$configuration = FileCacheFactory::getConfiguration();
$this
->assertEquals([
'bar' => 'llama',
], $configuration['test_foo_bar']);
}
/**
* @covers ::getPrefix
* @covers ::setPrefix
*/
public function testGetSetPrefix() {
$prefix = $this
->randomMachineName();
FileCacheFactory::setPrefix($prefix);
$this
->assertEquals($prefix, FileCacheFactory::getPrefix());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FileCacheFactoryTest:: |
protected | function |
Overrides UnitTestCase:: |
|
FileCacheFactoryTest:: |
public | function | @covers ::get | |
FileCacheFactoryTest:: |
public | function | @covers ::get | |
FileCacheFactoryTest:: |
public | function | @covers ::getConfiguration @covers ::setConfiguration | |
FileCacheFactoryTest:: |
public | function | @covers ::getPrefix @covers ::setPrefix | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |