You are here

public function LocalTasksTest::testLocalTaskBlock in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Menu/LocalTasksTest.php \Drupal\Tests\system\Functional\Menu\LocalTasksTest::testLocalTaskBlock()
  2. 9 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 214

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);
}