function ClaroTableTest::testThemeTablePositionStickyPreRender

Same name in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Theme/ClaroTableTest.php \Drupal\KernelTests\Core\Theme\ClaroTableTest::testThemeTablePositionStickyPreRender()

Confirm Claro prerender callback is not executed for non-array class.

File

core/tests/Drupal/KernelTests/Core/Theme/ClaroTableTest.php, line 47

Class

ClaroTableTest
Tests Claro specific table functionality.

Namespace

Drupal\KernelTests\Core\Theme

Code

public function testThemeTablePositionStickyPreRender() : void {
    // Enable the Claro theme.
    \Drupal::service('theme_installer')->install([
        'claro',
    ]);
    $this->config('system.theme')
        ->set('default', 'claro')
        ->save();
    $header = [
        'one',
        'two',
        'three',
    ];
    $rows = [
        [
            1,
            2,
            3,
        ],
        [
            4,
            5,
            6,
        ],
        [
            7,
            8,
            9,
        ],
    ];
    $table = [
        '#type' => 'table',
        '#header' => $header,
        '#rows' => $rows,
        '#sticky' => TRUE,
        '#attributes' => [
            'class' => 'class',
        ],
        '#pre_render' => [
            [
                ClaroPreRender::class,
                'tablePositionSticky',
            ],
        ],
    ];
    $renderedTable = (string) \Drupal::service('renderer')->renderRoot($table);
    // Confirm that table is rendered.
    $this->assertStringContainsString('class="class"', $renderedTable);
}

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