class ComponentLoaderTest
Unit tests for the component loader class.
@coversDefaultClass \Drupal\Core\Template\Loader\ComponentLoader @group sdc
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\UnitTestCaseTest extends \Drupal\Tests\UnitTestCase
- class \Drupal\Tests\Core\Theme\Component\ComponentLoaderTest extends \Drupal\Tests\UnitTestCaseTest
- class \Drupal\Tests\UnitTestCaseTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of ComponentLoaderTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Theme/ Component/ ComponentLoaderTest.php, line 20
Namespace
Drupal\Tests\Core\Theme\ComponentView source
class ComponentLoaderTest extends UnitTestCaseTest {
/**
* Tests the is fresh function for component loader.
*/
public function testIsFresh() : void {
$vfs_root = vfsStream::setup();
$component_directory = vfsStream::newDirectory('loader-test')->at($vfs_root);
$current_time = time();
$component_twig_file = vfsStream::newFile('loader-test.twig')->at($component_directory)
->setContent('twig')
->lastModified($current_time - 1000);
$component_yml_file = vfsStream::newFile('loader-test.component.yml')->at($component_directory)
->setContent('')
->lastModified($current_time - 1000);
$component = new Component([
'app_root' => '/fake/root',
], 'sdc_test:loader-test', [
'machineName' => 'loader-test',
'extension_type' => 'module',
'id' => 'sdc_test:loader-test',
'path' => 'vfs://' . $component_directory->path(),
'provider' => 'sdc_test',
'template' => 'loader-test.twig',
'group' => 'my-group',
'description' => 'My description',
'_discovered_file_path' => 'vfs://' . $component_yml_file->path(),
]);
$component_manager = $this->prophesize(ComponentPluginManager::class);
$component_manager->find('sdc_test:loader-test')
->willReturn($component);
$component_loader = new ComponentLoader($component_manager->reveal(), $this->createMock(LoggerInterface::class));
// Assert the component is fresh, as it changed before the current time.
$this->assertTrue($component_loader->isFresh('sdc_test:loader-test', $current_time), 'Twig and YAML files were supposed to be fresh');
// Pretend that we changed the twig file.
// It shouldn't matter that the time is in "future".
$component_twig_file->lastModified($current_time + 1000);
// Clear stat cache, to make sure component loader gets updated time.
clearstatcache();
// Component shouldn't be "fresh" anymore.
$this->assertFalse($component_loader->isFresh('sdc_test:loader-test', $current_time), 'Twig file was supposed to be outdated');
// Pretend that we changed the YAML file.
// It shouldn't matter that the time is in "future".
$component_twig_file->lastModified($current_time);
$component_yml_file->lastModified($current_time + 1000);
// Clear stat cache, to make sure component loader gets updated time.
clearstatcache();
// Component shouldn't be "fresh" anymore.
$this->assertFalse($component_loader->isFresh('sdc_test:loader-test', $current_time), 'YAML file was supposed to be outdated');
// Pretend that we changed both files.
// It shouldn't matter that the time is in "future".
$component_twig_file->lastModified($current_time + 1000);
$component_yml_file->lastModified($current_time + 1000);
// Clear stat cache, to make sure component loader gets updated time.
clearstatcache();
// Component shouldn't be "fresh" anymore.
$this->assertFalse($component_loader->isFresh('sdc_test:loader-test', $current_time), 'Twig and YAML files were supposed to be outdated');
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
ComponentLoaderTest::testIsFresh | public | function | Tests the is fresh function for component loader. | |
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
UnitTestCase::$root | protected | property | The app root. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | |
UnitTestCase::setUp | protected | function | 372 | |
UnitTestCaseTest::testVarDumpSameProcess | public | function | Tests the dump() function in a test run in the same process. | |
UnitTestCaseTest::testVarDumpSeparateProcess | public | function | Tests the dump() function in a test run in a separate process. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.