class ComponentRenderTest

Same name in this branch
  1. 10 core/tests/Drupal/KernelTests/Components/ComponentRenderTest.php \Drupal\KernelTests\Components\ComponentRenderTest
  2. 10 core/tests/Drupal/FunctionalTests/Components/ComponentRenderTest.php \Drupal\FunctionalTests\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/FunctionalTests/Components/ComponentRenderTest.php \Drupal\FunctionalTests\Components\ComponentRenderTest
  3. 11.x core/tests/Drupal/FunctionalJavascriptTests/Components/ComponentRenderTest.php \Drupal\FunctionalJavascriptTests\Components\ComponentRenderTest
  4. 11.x core/tests/Drupal/KernelTests/Component/ComponentRenderTest.php \Drupal\KernelTests\Component\ComponentRenderTest

Tests the correct rendering of components.

@group sdc

Hierarchy

Expanded class hierarchy of ComponentRenderTest

File

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

Namespace

Drupal\FunctionalJavascriptTests\Components
View source
class ComponentRenderTest extends WebDriverTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'system',
    'sdc_test',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'sdc_theme_test';
  
  /**
   * Tests that the correct libraries are put on the page using CSS.
   *
   * This also covers all the path translations necessary to produce the correct
   * path to the assets.
   */
  public function testCssLibraryAttachesCorrectly() : void {
    $build = [
      '#type' => 'inline_template',
      '#template' => "{{ include('sdc_theme_test:lib-overrides') }}",
    ];
    \Drupal::state()->set('sdc_test_component', $build);
    $this->drupalGet('sdc-test-component');
    $wrapper = $this->getSession()
      ->getPage()
      ->find('css', '#sdc-wrapper');
    // Opacity is set to 0 in the CSS file (see another-stylesheet.css).
    $this->assertFalse($wrapper->isVisible());
  }
  
  /**
   * Tests that the correct libraries are put on the page using JS.
   *
   * This also covers all the path translations necessary to produce the correct
   * path to the assets.
   */
  public function testJsLibraryAttachesCorrectly() : void {
    $build = [
      '#type' => 'inline_template',
      '#template' => "{{ include('sdc_test:my-button', {\n        text: 'Click'\n      }, with_context = false) }}",
    ];
    \Drupal::state()->set('sdc_test_component', $build);
    $this->drupalGet('sdc-test-component');
    $page = $this->getSession()
      ->getPage();
    $page->find('css', '[data-component-id="sdc_test:my-button"]')
      ->click();
    $this->assertSame('Click power (1)', $page->find('css', '[data-component-id="sdc_test:my-button"]')
      ->getText());
  }

}

Members

Title Sort descending Modifiers Object type Summary
ComponentRenderTest::$defaultTheme protected property The theme to install as the default for testing.
ComponentRenderTest::$modules protected static property Modules to install.
ComponentRenderTest::testCssLibraryAttachesCorrectly public function Tests that the correct libraries are put on the page using CSS.
ComponentRenderTest::testJsLibraryAttachesCorrectly public function Tests that the correct libraries are put on the page using JS.
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.

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