You are here

protected function UnitTestCase::getBlockMockWithMachineName in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/UnitTestCase.php \Drupal\Tests\UnitTestCase::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 UnitTestCase::getBlockMockWithMachineName()
BlockFormTest::testGetUniqueMachineName in core/modules/block/tests/src/Unit/BlockFormTest.php
Tests the unique machine name generator.

File

core/tests/Drupal/Tests/UnitTestCase.php, line 186
Contains \Drupal\Tests\UnitTestCase.

Class

UnitTestCase
Provides a base class and helpers for Drupal unit tests.

Namespace

Drupal\Tests

Code

protected function getBlockMockWithMachineName($machine_name) {
  $plugin = $this
    ->getMockBuilder('Drupal\\Core\\Block\\BlockBase')
    ->disableOriginalConstructor()
    ->getMock();
  $plugin
    ->expects($this
    ->any())
    ->method('getMachineNameSuggestion')
    ->will($this
    ->returnValue($machine_name));
  $block = $this
    ->getMockBuilder('Drupal\\block\\Entity\\Block')
    ->disableOriginalConstructor()
    ->getMock();
  $block
    ->expects($this
    ->any())
    ->method('getPlugin')
    ->will($this
    ->returnValue($plugin));
  return $block;
}