function ComponentNegotiatorTest::testRenderWithReplacements

Same name in this branch
  1. 10 core/modules/sdc/tests/src/Kernel/ComponentNegotiatorTest.php \Drupal\Tests\sdc\Kernel\ComponentNegotiatorTest::testRenderWithReplacements()
Same name in other branches
  1. 11.x core/modules/sdc/tests/src/Kernel/ComponentNegotiatorTest.php \Drupal\Tests\sdc\Kernel\ComponentNegotiatorTest::testRenderWithReplacements()
  2. 11.x core/tests/Drupal/Tests/Core/Theme/Component/ComponentNegotiatorTest.php \Drupal\Tests\Core\Theme\Component\ComponentNegotiatorTest::testRenderWithReplacements()
  3. 11.x core/tests/Drupal/KernelTests/Components/ComponentNegotiatorTest.php \Drupal\KernelTests\Components\ComponentNegotiatorTest::testRenderWithReplacements()

Tests rendering components with component replacement.

File

core/tests/Drupal/Tests/Core/Theme/Component/ComponentNegotiatorTest.php, line 60

Class

ComponentNegotiatorTest
Tests the component negotiator.

Namespace

Drupal\Tests\Core\Theme\Component

Code

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.