function LocalActionManagerTest::getActionsForRouteProvider

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php \Drupal\Tests\Core\Menu\LocalActionManagerTest::getActionsForRouteProvider()
  2. 8.9.x core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php \Drupal\Tests\Core\Menu\LocalActionManagerTest::getActionsForRouteProvider()
  3. 11.x core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php \Drupal\Tests\Core\Menu\LocalActionManagerTest::getActionsForRouteProvider()

File

core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php, line 196

Class

LocalActionManagerTest
@coversDefaultClass \Drupal\Core\Menu\LocalActionManager @group Menu

Namespace

Drupal\Tests\Core\Menu

Code

public static function getActionsForRouteProvider() {
    $cache_contexts_manager = (new Prophet())->prophesize(CacheContextsManager::class);
    $cache_contexts_manager->assertValidTokens(Argument::any())
        ->willReturn(TRUE);
    $container = new Container();
    $container->set('cache_contexts_manager', $cache_contexts_manager->reveal());
    \Drupal::setContainer($container);
    // Single available and single expected plugins.
    $data[] = [
        'test_route',
        [
            'plugin_id_1' => [
                'appears_on' => [
                    'test_route',
                ],
                'route_name' => 'test_route_2',
                'title' => 'Plugin ID 1',
                'weight' => 0,
            ],
        ],
        [
            '#cache' => [
                'tags' => [],
                'contexts' => [
                    'route',
                    'user.permissions',
                ],
                'max-age' => 0,
            ],
            'plugin_id_1' => [
                '#theme' => 'menu_local_action',
                '#link' => [
                    'title' => 'Plugin ID 1',
                    'url' => Url::fromRoute('test_route_2'),
                    'localized_options' => '',
                ],
                '#access' => AccessResult::forbidden()->cachePerPermissions(),
                '#weight' => 0,
            ],
        ],
    ];
    // Multiple available and single expected plugins.
    $data[] = [
        'test_route',
        [
            'plugin_id_1' => [
                'appears_on' => [
                    'test_route',
                ],
                'route_name' => 'test_route_2',
                'title' => 'Plugin ID 1',
                'weight' => 0,
            ],
            'plugin_id_2' => [
                'appears_on' => [
                    'test_route2',
                ],
                'route_name' => 'test_route_3',
                'title' => 'Plugin ID 2',
                'weight' => 0,
            ],
        ],
        [
            '#cache' => [
                'tags' => [],
                'contexts' => [
                    'route',
                    'user.permissions',
                ],
                'max-age' => 0,
            ],
            'plugin_id_1' => [
                '#theme' => 'menu_local_action',
                '#link' => [
                    'title' => 'Plugin ID 1',
                    'url' => Url::fromRoute('test_route_2'),
                    'localized_options' => '',
                ],
                '#access' => AccessResult::forbidden()->cachePerPermissions(),
                '#weight' => 0,
            ],
        ],
    ];
    // Multiple available and multiple expected plugins and specified weight.
    $data[] = [
        'test_route',
        [
            'plugin_id_1' => [
                'appears_on' => [
                    'test_route',
                ],
                'route_name' => 'test_route_2',
                'title' => 'Plugin ID 1',
                'weight' => 1,
            ],
            'plugin_id_2' => [
                'appears_on' => [
                    'test_route',
                ],
                'route_name' => 'test_route_3',
                'title' => 'Plugin ID 2',
                'weight' => 0,
            ],
        ],
        [
            '#cache' => [
                'contexts' => [
                    'route',
                    'user.permissions',
                ],
                'tags' => [],
                'max-age' => 0,
            ],
            'plugin_id_1' => [
                '#theme' => 'menu_local_action',
                '#link' => [
                    'title' => 'Plugin ID 1',
                    'url' => Url::fromRoute('test_route_2'),
                    'localized_options' => '',
                ],
                '#access' => AccessResult::forbidden()->cachePerPermissions(),
                '#weight' => 1,
            ],
            'plugin_id_2' => [
                '#theme' => 'menu_local_action',
                '#link' => [
                    'title' => 'Plugin ID 2',
                    'url' => Url::fromRoute('test_route_3'),
                    'localized_options' => '',
                ],
                '#access' => AccessResult::forbidden()->cachePerPermissions(),
                '#weight' => 0,
            ],
        ],
    ];
    // Two plugins with the same route name but different route parameters.
    $data[] = [
        'test_route',
        [
            'plugin_id_1' => [
                'appears_on' => [
                    'test_route',
                ],
                'route_name' => 'test_route_2',
                'route_parameters' => [
                    'test1',
                ],
                'title' => 'Plugin ID 1',
                'weight' => 1,
            ],
            'plugin_id_2' => [
                'appears_on' => [
                    'test_route',
                ],
                'route_name' => 'test_route_2',
                'route_parameters' => [
                    'test2',
                ],
                'title' => 'Plugin ID 2',
                'weight' => 0,
            ],
        ],
        [
            '#cache' => [
                'contexts' => [
                    'route',
                    'user.permissions',
                ],
                'tags' => [],
                'max-age' => 0,
            ],
            'plugin_id_1' => [
                '#theme' => 'menu_local_action',
                '#link' => [
                    'title' => 'Plugin ID 1',
                    'url' => Url::fromRoute('test_route_2', [
                        'test1',
                    ]),
                    'localized_options' => '',
                ],
                '#access' => AccessResult::forbidden()->cachePerPermissions(),
                '#weight' => 1,
            ],
            'plugin_id_2' => [
                '#theme' => 'menu_local_action',
                '#link' => [
                    'title' => 'Plugin ID 2',
                    'url' => Url::fromRoute('test_route_2', [
                        'test2',
                    ]),
                    'localized_options' => '',
                ],
                '#access' => AccessResult::forbidden()->cachePerPermissions(),
                '#weight' => 0,
            ],
        ],
    ];
    return $data;
}

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