function BlockFormTest::getBlockMockWithMachineName

Same name and namespace in other branches
  1. 9 core/modules/block/tests/src/Unit/BlockFormTest.php \Drupal\Tests\block\Unit\BlockFormTest::getBlockMockWithMachineName()
  2. 8.9.x core/modules/block/tests/src/Unit/BlockFormTest.php \Drupal\Tests\block\Unit\BlockFormTest::getBlockMockWithMachineName()
  3. 10 core/modules/block/tests/src/Unit/BlockFormTest.php \Drupal\Tests\block\Unit\BlockFormTest::getBlockMockWithMachineName()

Mocks a block with a block plugin.

Parameters

string $machine_name: The machine name of the block plugin.

Return value

\Drupal\block\BlockInterface|\PHPUnit\Framework\MockObject\MockObject The mocked block.

1 call to BlockFormTest::getBlockMockWithMachineName()
BlockFormTest::testGetUniqueMachineName in core/modules/block/tests/src/Unit/BlockFormTest.php
Tests the unique machine name generator.

File

core/modules/block/tests/src/Unit/BlockFormTest.php, line 123

Class

BlockFormTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21block%21src%21BlockForm.php/class/BlockForm/11.x" title="Provides form for block instance forms." class="local">\Drupal\block\BlockForm</a> @group block

Namespace

Drupal\Tests\block\Unit

Code

protected function getBlockMockWithMachineName($machine_name) {
    $plugin = $this->getMockBuilder(BlockBase::class)
        ->disableOriginalConstructor()
        ->getMock();
    $plugin->expects($this->any())
        ->method('getMachineNameSuggestion')
        ->willReturn($machine_name);
    $block = $this->getMockBuilder(Block::class)
        ->disableOriginalConstructor()
        ->getMock();
    $block->expects($this->any())
        ->method('getPlugin')
        ->willReturn($plugin);
    return $block;
}

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