function AddComponentTest::provider

Data provider for testAddComponent.

File

core/modules/layout_builder/tests/src/Kernel/Plugin/ConfigAction/AddComponentTest.php, line 114

Class

AddComponentTest
@coversDefaultClass \Drupal\layout_builder\Plugin\ConfigAction\AddComponent

Namespace

Drupal\Tests\layout_builder\Kernel\Plugin\ConfigAction

Code

public static function provider() : \Generator {
    (yield 'add component at first position of a non-empty region' => [
        [
            'section' => 0,
            'position' => 0,
            'component' => [
                'region' => [
                    'layout_test_plugin' => 'content',
                    'layout_twocol_section' => 'first',
                ],
                'default_region' => 'content',
                'configuration' => [
                    'id' => 'my_plugin_id',
                ],
            ],
        ],
        'first',
        1,
        2,
    ]);
    (yield 'edit existing component by giving the same uuid' => [
        [
            'section' => 0,
            'position' => 0,
            'component' => [
                'uuid' => '1445597a-c674-431d-ac0a-277d99347a7f',
                'region' => [
                    'layout_test_plugin' => 'content',
                    'layout_twocol_section' => 'first',
                ],
                'default_region' => 'content',
                'configuration' => [
                    'id' => 'my_plugin_id',
                ],
            ],
        ],
        'first',
        1,
        1,
    ]);
    (yield 'add component at second position of a non-empty region' => [
        [
            'section' => 0,
            'position' => 1,
            'component' => [
                'region' => [
                    'layout_test_plugin' => 'content',
                    'layout_twocol_section' => 'first',
                ],
                'default_region' => 'content',
                'configuration' => [
                    'id' => 'my_plugin_id',
                    'some_configuration' => 'my_configuration_value',
                ],
                'additional' => [
                    'some_additional_value' => 'my_custom_value',
                ],
            ],
        ],
        'first',
        2,
        1,
    ]);
    (yield 'add component at a position larger than the region size on an empty region' => [
        [
            'section' => 0,
            'position' => 4,
            'component' => [
                'region' => [
                    'layout_test_plugin' => 'content',
                    'layout_twocol_section' => 'second',
                ],
                'default_region' => 'content',
                'configuration' => [
                    'id' => 'my_plugin_id',
                    'some_configuration' => 'my_configuration_value',
                ],
                'additional' => [
                    'some_additional_value' => 'my_custom_value',
                ],
            ],
        ],
        'second',
        // As there is no other block in that section's region, weight is 0 no matter
        // of the 4th position we asked for.
0,
        1,
    ]);
    (yield 'add component at a region not defined in the mapping' => [
        [
            'section' => 0,
            'position' => 4,
            'component' => [
                'region' => [
                    'layout_test_plugin' => 'content',
                ],
                'default_region' => 'second',
                'configuration' => [
                    'id' => 'my_plugin_id',
                ],
            ],
        ],
        // Assigned to the default region, as no mapping matched.
'second',
        0,
        1,
    ]);
    (yield 'add component at a region defined in the mapping while no default region exist' => [
        [
            'section' => 0,
            'position' => 4,
            'component' => [
                'region' => [
                    'layout_twocol_section' => 'second',
                ],
                'configuration' => [
                    'id' => 'my_plugin_id',
                ],
            ],
        ],
        // Assigned to the matching region, even if no default_region.
'second',
        0,
        1,
    ]);
    (yield 'add component with only default_region and no region mapping' => [
        [
            'section' => 0,
            'position' => 4,
            'component' => [
                'default_region' => 'second',
                'configuration' => [
                    'id' => 'my_plugin_id',
                ],
            ],
        ],
        // Assigned to the default region, even with no mapping.
'second',
        0,
        1,
    ]);
    (yield 'exception when cannot determine a region with mapping and default' => [
        [
            'section' => 0,
            'position' => 4,
            'component' => [
                'region' => [
                    'layout_test_plugin' => 'content',
                ],
                'configuration' => [
                    'id' => 'my_plugin_id',
                ],
            ],
        ],
        'second',
        0,
        1,
        // No default_region, no matching region, so we error.
[
            ConfigActionException::class,
            'Cannot determine which region of the section to place this component into, because no default region was provided.',
        ],
        (yield 'exception when no region given' => [
            [
                'section' => 0,
                'position' => 4,
                'component' => [
                    'configuration' => [
                        'id' => 'my_plugin_id',
                    ],
                ],
            ],
            'second',
            0,
            1,
            // No default_region, no matching region, so we error.
[
                ConfigActionException::class,
                'Cannot determine which region of the section to place this component into, because no region was provided.',
            ],
        ]),
        (yield 'exception when no configuration given' => [
            [
                'section' => 0,
                'position' => 4,
                'component' => [
                    'region' => [
                        'layout_test_plugin' => 'content',
                    ],
                    'default_region' => 'content',
                ],
            ],
            'second',
            0,
            1,
            // No component configuration.
[
                ConfigActionException::class,
                'Cannot determine the component configuration, or misses a plugin ID.',
            ],
        ]),
        (yield 'exception when no id in configuration is given' => [
            [
                'section' => 0,
                'position' => 4,
                'component' => [
                    'region' => [
                        'layout_test_plugin' => 'content',
                    ],
                    'default_region' => 'content',
                    'configuration' => [
                        'no_id' => 'my_plugin_id',
                    ],
                ],
            ],
            'second',
            0,
            1,
            // No component configuration id.
[
                ConfigActionException::class,
                'Cannot determine the component configuration, or misses a plugin ID.',
            ],
        ]),
    ]);
}

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