function BlockPageVariantTest::providerBuild

Same name and namespace in other branches
  1. 8.9.x core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php \Drupal\Tests\block\Unit\Plugin\DisplayVariant\BlockPageVariantTest::providerBuild()
  2. 10 core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php \Drupal\Tests\block\Unit\Plugin\DisplayVariant\BlockPageVariantTest::providerBuild()
  3. 11.x core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php \Drupal\Tests\block\Unit\Plugin\DisplayVariant\BlockPageVariantTest::providerBuild()

File

core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php, line 69

Class

BlockPageVariantTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21block%21src%21Plugin%21DisplayVariant%21BlockPageVariant.php/class/BlockPageVariant/9" title="Provides a page display variant that decorates the main content with blocks." class="local">\Drupal\block\Plugin\DisplayVariant\BlockPageVariant</a> @group block

Namespace

Drupal\Tests\block\Unit\Plugin\DisplayVariant

Code

public function providerBuild() {
    $blocks_config = [
        'block1' => [
            // region, is main content block, is messages block, is title block
'top',
            FALSE,
            FALSE,
            FALSE,
        ],
        // Test multiple blocks in the same region.
'block2' => [
            'bottom',
            FALSE,
            FALSE,
            FALSE,
        ],
        'block3' => [
            'bottom',
            FALSE,
            FALSE,
            FALSE,
        ],
        // Test a block implementing MainContentBlockPluginInterface.
'block4' => [
            'center',
            TRUE,
            FALSE,
            FALSE,
        ],
        // Test a block implementing MessagesBlockPluginInterface.
'block5' => [
            'center',
            FALSE,
            TRUE,
            FALSE,
        ],
        // Test a block implementing TitleBlockPluginInterface.
'block6' => [
            'center',
            FALSE,
            FALSE,
            TRUE,
        ],
    ];
    $test_cases = [];
    $test_cases[] = [
        $blocks_config,
        6,
        [
            '#cache' => [
                'tags' => [
                    'config:block_list',
                    'route',
                ],
                'contexts' => [],
                'max-age' => -1,
            ],
            'top' => [
                'block1' => [],
                '#sorted' => TRUE,
            ],
            // The main content was rendered via a block.
'center' => [
                'block4' => [],
                'block5' => [],
                'block6' => [],
                '#sorted' => TRUE,
            ],
            'bottom' => [
                'block2' => [],
                'block3' => [],
                '#sorted' => TRUE,
            ],
        ],
    ];
    unset($blocks_config['block5']);
    $test_cases[] = [
        $blocks_config,
        5,
        [
            '#cache' => [
                'tags' => [
                    'config:block_list',
                    'route',
                ],
                'contexts' => [],
                'max-age' => -1,
            ],
            'top' => [
                'block1' => [],
                '#sorted' => TRUE,
            ],
            'center' => [
                'block4' => [],
                'block6' => [],
                '#sorted' => TRUE,
            ],
            'bottom' => [
                'block2' => [],
                'block3' => [],
                '#sorted' => TRUE,
            ],
            // The messages are rendered via the fallback in case there is no block
            // rendering the main content.
'content' => [
                'messages' => [
                    '#weight' => -1000,
                    '#type' => 'status_messages',
                    '#include_fallback' => TRUE,
                ],
            ],
        ],
    ];
    unset($blocks_config['block4']);
    unset($blocks_config['block6']);
    $test_cases[] = [
        $blocks_config,
        3,
        [
            '#cache' => [
                'tags' => [
                    'config:block_list',
                    'route',
                ],
                'contexts' => [],
                'max-age' => -1,
            ],
            'top' => [
                'block1' => [],
                '#sorted' => TRUE,
            ],
            'bottom' => [
                'block2' => [],
                'block3' => [],
                '#sorted' => TRUE,
            ],
            // The main content & messages are rendered via the fallback in case
            // there are no blocks rendering them.
'content' => [
                'system_main' => [
                    '#markup' => 'Hello kittens!',
                ],
                'messages' => [
                    '#weight' => -1000,
                    '#type' => 'status_messages',
                    '#include_fallback' => TRUE,
                ],
            ],
        ],
    ];
    return $test_cases;
}

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