function LocalTasksTest::testLocalTaskBlock

Same name in other branches
  1. 8.9.x core/modules/system/tests/src/Functional/Menu/LocalTasksTest.php \Drupal\Tests\system\Functional\Menu\LocalTasksTest::testLocalTaskBlock()
  2. 10 core/modules/system/tests/src/Functional/Menu/LocalTasksTest.php \Drupal\Tests\system\Functional\Menu\LocalTasksTest::testLocalTaskBlock()
  3. 11.x core/modules/system/tests/src/Functional/Menu/LocalTasksTest.php \Drupal\Tests\system\Functional\Menu\LocalTasksTest::testLocalTaskBlock()

Tests that local task blocks are configurable to show a specific level.

File

core/modules/system/tests/src/Functional/Menu/LocalTasksTest.php, line 209

Class

LocalTasksTest
Tests local tasks derived from router and added/altered via hooks.

Namespace

Drupal\Tests\system\Functional\Menu

Code

public function testLocalTaskBlock() {
    // Remove the default block and create a new one.
    $this->sut
        ->delete();
    $this->sut = $this->drupalPlaceBlock('local_tasks_block', [
        'id' => 'tabs_block',
        'primary' => TRUE,
        'secondary' => FALSE,
    ]);
    $this->drupalGet(Url::fromRoute('menu_test.local_task_test_tasks_settings'));
    // Verify that local tasks in the first level appear.
    $this->assertLocalTasks([
        [
            'menu_test.local_task_test_tasks_view',
            [],
        ],
        [
            'menu_test.local_task_test_tasks_edit',
            [],
        ],
        [
            'menu_test.local_task_test_tasks_settings',
            [],
        ],
        [
            'menu_test.local_task_test_tasks_settings_dynamic',
            [],
        ],
    ]);
    // Verify that local tasks in the second level doesn't appear.
    $this->assertNoLocalTasks(1);
    $this->sut
        ->delete();
    $this->sut = $this->drupalPlaceBlock('local_tasks_block', [
        'id' => 'tabs_block',
        'primary' => FALSE,
        'secondary' => TRUE,
    ]);
    $this->drupalGet(Url::fromRoute('menu_test.local_task_test_tasks_settings'));
    // Verify that local tasks in the first level doesn't appear.
    $this->assertNoLocalTasks(0);
    // Verify that local tasks in the second level appear.
    $sub_tasks = [
        [
            'menu_test.local_task_test_tasks_settings_sub1',
            [],
        ],
        [
            'menu_test.local_task_test_tasks_settings_sub2',
            [],
        ],
        [
            'menu_test.local_task_test_tasks_settings_sub3',
            [],
        ],
        [
            'menu_test.local_task_test_tasks_settings_derived',
            [
                'placeholder' => 'derive1',
            ],
        ],
        [
            'menu_test.local_task_test_tasks_settings_derived',
            [
                'placeholder' => 'derive2',
            ],
        ],
    ];
    $this->assertLocalTasks($sub_tasks, 1);
}

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