function BlockHookOperationTest::testBlockOperationAlter

Same name in other branches
  1. 9 core/modules/block/tests/src/Functional/BlockHookOperationTest.php \Drupal\Tests\block\Functional\BlockHookOperationTest::testBlockOperationAlter()
  2. 8.9.x core/modules/block/tests/src/Functional/BlockHookOperationTest.php \Drupal\Tests\block\Functional\BlockHookOperationTest::testBlockOperationAlter()
  3. 10 core/modules/block/tests/src/Functional/BlockHookOperationTest.php \Drupal\Tests\block\Functional\BlockHookOperationTest::testBlockOperationAlter()

Tests the block list to see if the test_operation link is added.

File

core/modules/block/tests/src/Functional/BlockHookOperationTest.php, line 44

Class

BlockHookOperationTest
Tests for Block module regarding hook_entity_operations_alter().

Namespace

Drupal\Tests\block\Functional

Code

public function testBlockOperationAlter() : void {
    // Add a test block, any block will do.
    // Set the machine name so the test_operation link can be built later.
    $block_id = $this->randomMachineName(16);
    $this->drupalPlaceBlock('system_powered_by_block', [
        'id' => $block_id,
    ]);
    // Get the Block listing.
    $this->drupalGet('admin/structure/block');
    $test_operation_link = 'admin/structure/block/manage/' . $block_id . '/test_operation';
    // Test if the test_operation link is on the page.
    $this->assertSession()
        ->linkByHrefExists($test_operation_link);
}

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