class ComponentNegotiatorTest
Same name in this branch
- 11.x core/modules/sdc/tests/src/Kernel/ComponentNegotiatorTest.php \Drupal\Tests\sdc\Kernel\ComponentNegotiatorTest
- 11.x core/tests/Drupal/Tests/Core/Theme/Component/ComponentNegotiatorTest.php \Drupal\Tests\Core\Theme\Component\ComponentNegotiatorTest
Same name in other branches
- 10 core/modules/sdc/tests/src/Kernel/ComponentNegotiatorTest.php \Drupal\Tests\sdc\Kernel\ComponentNegotiatorTest
- 10 core/tests/Drupal/Tests/Core/Theme/Component/ComponentNegotiatorTest.php \Drupal\Tests\Core\Theme\Component\ComponentNegotiatorTest
Tests the component negotiator.
@coversDefaultClass \Drupal\Core\Theme\ComponentNegotiator @group sdc
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait
- class \Drupal\KernelTests\Components\ComponentKernelTestBase extends \Drupal\KernelTests\KernelTestBase
- class \Drupal\KernelTests\Components\ComponentNegotiatorTest extends \Drupal\KernelTests\Components\ComponentKernelTestBase
- class \Drupal\KernelTests\Components\ComponentKernelTestBase extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of ComponentNegotiatorTest
File
-
core/
tests/ Drupal/ KernelTests/ Components/ ComponentNegotiatorTest.php, line 13
Namespace
Drupal\KernelTests\ComponentsView source
class ComponentNegotiatorTest extends ComponentKernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'sdc_test',
'sdc_test_replacements',
];
/**
* Themes to install.
*
* @var string[]
*/
protected static $themes = [
'sdc_theme_test_enforce_schema',
'sdc_theme_test',
];
/**
* @covers ::negotiate
*/
public function testNegotiate() : void {
$data = [
[
'sdc_test:my-banner',
NULL,
],
[
'sdc_theme_test:my-card',
'sdc_theme_test_enforce_schema:my-card',
],
[
'sdc_test:my-button',
'sdc_test_replacements:my-button',
],
[
'invalid:component',
NULL,
],
[
'invalid^component',
NULL,
],
[
'',
NULL,
],
];
array_walk($data, function ($test_input) {
[
$requested_id,
$expected_id,
] = $test_input;
$negotiated_id = $this->negotiator
->negotiate($requested_id, $this->manager
->getDefinitions());
$this->assertSame($expected_id, $negotiated_id);
});
}
/**
* Tests rendering components with component replacement.
*/
public function testRenderWithReplacements() : void {
$build = [
'#type' => 'inline_template',
'#template' => "{{ include('sdc_test:my-button') }}",
'#context' => [
'text' => 'Like!',
'iconType' => 'like',
],
];
$crawler = $this->renderComponentRenderArray($build);
$this->assertNotEmpty($crawler->filter('#sdc-wrapper button[data-component-id="sdc_test_replacements:my-button"]'));
$this->assertNotEmpty($crawler->filter('#sdc-wrapper button .sdc-id:contains("sdc_test_replacements:my-button")'));
// Now test component replacement on themes.
$build = [
'#type' => 'inline_template',
'#template' => "{{ include('sdc_theme_test:my-card') }}",
'#context' => [
'header' => 'Foo bar',
],
];
$crawler = $this->renderComponentRenderArray($build);
$this->assertNotEmpty($crawler->filter('#sdc-wrapper .component--my-card--replaced__body'));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.