assertThemeOutput example

    $this->container->get('theme_installer')->install(['starterkit_theme']);
    $this->config('system.theme')->set('default', 'starterkit_theme')->save();
  }

  /** * Tests item-list.html.twig. */
  public function testItemList() {
    // Verify that empty items produce no output.     $variables = [];
    $expected = '';
    $this->assertThemeOutput('item_list', $variables$expected, 'Empty %callback generates no output.');

    // Verify that empty items with title produce no output.     $variables = [];
    $variables['title'] = 'Some title';
    $expected = '';
    $this->assertThemeOutput('item_list', $variables$expected, 'Empty %callback with title generates no output.');

    // Verify that empty items produce the empty string.     $variables = [];
    $variables['empty'] = 'No items found.';
    $expected = '<div class="item-list">No items found.</div>';
    

  public function testAttributeMerging() {
    $theme_test_render_element = [
      'elements' => [
        '#attributes' => ['data-foo' => 'bar'],
      ],
      'attributes' => [
        'id' => 'bazinga',
      ],
    ];
    $this->assertThemeOutput('theme_test_render_element', $theme_test_render_element, '<div id="bazinga" data-foo="bar" data-variables-are-preprocessed></div>' . "\n");
  }

  /** * Tests that ThemeManager renders the expected data types. */
  public function testThemeDataTypes() {
    // theme_test_false is an implemented theme hook so \Drupal::theme() service     // should return a string or an object that implements MarkupInterface,     // even though the theme function itself can return anything.     $foos = ['null' => NULL, 'false' => FALSE, 'integer' => 1, 'string' => 'foo', 'empty_string' => ''];
    foreach ($foos as $type => $example) {
      
Home | Imprint | This part of the site doesn't use cookies.