function TypographyTest::setupContainer
Sets up service container as needed by the plugin.
Parameters
array $configuration: The typography plugin configuration.
File
-
core/
tests/ Drupal/ Tests/ Core/ Theme/ DesignToken/ Plugin/ TypographyTest.php, line 167
Class
- TypographyTest
- Tests typography value plugin.
Namespace
Drupal\Tests\Core\Theme\DesignToken\PluginCode
protected function setupContainer(array $configuration) : void {
$properties = $this->properties;
$instances = [];
foreach ($properties as $property => $propertyType) {
$propertyConfig = DesignTokenValuePluginBase::prepareConfiguration($configuration[$property]);
switch ($propertyType) {
case 'dimension':
$instances[$property] = new Dimension($propertyConfig, $propertyType, []);
break;
case 'fontFamily':
$instances[$property] = new FontFamily($propertyConfig, $propertyType, []);
break;
case 'fontWeight':
$instances[$property] = new FontWeight($propertyConfig, $propertyType, []);
break;
case 'number':
$instances[$property] = new Number($propertyConfig, $propertyType, []);
break;
}
}
$designTokenValuePluginManager = $this->createMock(DesignTokenValuePluginManagerInterface::class);
$designTokenValuePluginManager->expects($this->exactly(5))
->method('createInstance')
->willReturnCallback(static function (string $type, array $preparedPropertyConfig) use ($properties, $configuration, $instances) {
foreach ($properties as $property => $propertyType) {
if ($propertyType != $type) {
continue;
}
$propertyConfig = DesignTokenValuePluginBase::prepareConfiguration($configuration[$property]);
if ($propertyConfig == $preparedPropertyConfig) {
return $instances[$property];
}
}
return '';
});
$container = new ContainerBuilder();
$container->set(DesignTokenValuePluginManagerInterface::class, $designTokenValuePluginManager);
\Drupal::setContainer($container);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.