function ComponentRenderTest::checkPropValidation

Same name in this branch
  1. 10 core/tests/Drupal/KernelTests/Components/ComponentRenderTest.php \Drupal\KernelTests\Components\ComponentRenderTest::checkPropValidation()
Same name in other branches
  1. 11.x core/modules/sdc/tests/src/Kernel/ComponentRenderTest.php \Drupal\Tests\sdc\Kernel\ComponentRenderTest::checkPropValidation()
  2. 11.x core/tests/Drupal/KernelTests/Components/ComponentRenderTest.php \Drupal\KernelTests\Components\ComponentRenderTest::checkPropValidation()

Ensures the schema violations are reported properly.

1 call to ComponentRenderTest::checkPropValidation()
ComponentRenderTest::testRender in core/modules/sdc/tests/src/Kernel/ComponentRenderTest.php
Test that components render correctly.

File

core/modules/sdc/tests/src/Kernel/ComponentRenderTest.php, line 146

Class

ComponentRenderTest
Tests the correct rendering of components.

Namespace

Drupal\Tests\sdc\Kernel

Code

protected function checkPropValidation() : void {
    // 1. Violates the minLength for the text property.
    $content = [
        'label' => '1',
    ];
    $build = [
        '#type' => 'inline_template',
        '#context' => [
            'content' => $content,
        ],
        '#template' => "{{ include('sdc_test:my-button', { text: content.label, iconType: 'external' }, with_context = false) }}",
    ];
    try {
        $this->renderComponentRenderArray($build);
        $this->fail('Invalid prop did not cause an exception');
    } catch (\Throwable $e) {
        $this->addToAssertionCount(1);
    }
    // 2. Violates the required header property.
    $build = [
        '#type' => 'inline_template',
        '#context' => [],
        '#template' => "{{ include('sdc_theme_test:my-card', with_context = false) }}",
    ];
    try {
        $this->renderComponentRenderArray($build);
        $this->fail('Invalid prop did not cause an exception');
    } catch (\Throwable $e) {
        $this->addToAssertionCount(1);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.