class ComponentRenderTest

Same name in this branch
  1. main core/tests/Drupal/KernelTests/Components/ComponentRenderTest.php \Drupal\KernelTests\Components\ComponentRenderTest
  2. main core/tests/Drupal/KernelTests/Component/ComponentRenderTest.php \Drupal\KernelTests\Component\ComponentRenderTest
  3. main core/tests/Drupal/FunctionalJavascriptTests/Components/ComponentRenderTest.php \Drupal\FunctionalJavascriptTests\Components\ComponentRenderTest
Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Components/ComponentRenderTest.php \Drupal\KernelTests\Components\ComponentRenderTest
  2. 11.x core/tests/Drupal/KernelTests/Component/ComponentRenderTest.php \Drupal\KernelTests\Component\ComponentRenderTest
  3. 11.x core/tests/Drupal/FunctionalTests/Components/ComponentRenderTest.php \Drupal\FunctionalTests\Components\ComponentRenderTest
  4. 11.x core/tests/Drupal/FunctionalJavascriptTests/Components/ComponentRenderTest.php \Drupal\FunctionalJavascriptTests\Components\ComponentRenderTest
  5. 10 core/tests/Drupal/KernelTests/Components/ComponentRenderTest.php \Drupal\KernelTests\Components\ComponentRenderTest
  6. 10 core/tests/Drupal/FunctionalTests/Components/ComponentRenderTest.php \Drupal\FunctionalTests\Components\ComponentRenderTest
  7. 10 core/tests/Drupal/FunctionalJavascriptTests/Components/ComponentRenderTest.php \Drupal\FunctionalJavascriptTests\Components\ComponentRenderTest

Tests the correct rendering of components.

Attributes

#[Group('sdc')] #[RunTestsInSeparateProcesses]

Hierarchy

Expanded class hierarchy of ComponentRenderTest

File

core/tests/Drupal/FunctionalTests/Components/ComponentRenderTest.php, line 14

Namespace

Drupal\FunctionalTests\Components
View source
class ComponentRenderTest extends BrowserTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'system',
    'sdc_test',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'sdc_theme_test';
  
  /**
   * Tests libraryOverrides.
   */
  public function testLibraryOverrides() : void {
    $build = [
      '#type' => 'inline_template',
      '#template' => "{{ include('sdc_theme_test:lib-overrides') }}",
    ];
    \Drupal::state()->set('sdc_test_component', $build);
    $output = $this->drupalGet('sdc-test-component');
    $this->assertStringContainsString('another-stylesheet.css', $output);
    // Since libraryOverrides is taking control of CSS, and it's not listing
    // lib-overrides.css, then it should not be there. Even if it's the CSS
    // that usually gets auto-attached.
    $this->assertStringNotContainsString('lib-overrides.css', $output);
    // Ensure that libraryDependencies adds the expected assets.
    $this->assertStringContainsString('dialog.position.js', $output);
    // Ensure that libraryOverrides processes attributes properly.
    $this->assertMatchesRegularExpression('@<script.*src="[^"]*lib-overrides\\.js\\?v=1[^"]*".*defer.*bar="foo"></script>@', $output);
    // Ensure that libraryOverrides processes external CSS properly.
    $this->assertMatchesRegularExpression('@<link.*href="https://drupal\\.org/fake-dependency/styles\\.css" />@', $output);
    // Ensure that libraryOverrides processes external JS properly.
    $this->assertMatchesRegularExpression('@<script.*src="https://drupal\\.org/fake-dependency/index\\.min\\.js"></script>@', $output);
  }

}

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