Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / block / tests / src / Unit / BlockFormTest.php
index b8463490bd3637996aac485094986640e6a3ac53..f19f92116786deb0b24c73cf0da49af98164cbc8 100644 (file)
@@ -3,6 +3,8 @@
 namespace Drupal\Tests\block\Unit;
 
 use Drupal\block\BlockForm;
+use Drupal\block\Entity\Block;
+use Drupal\Core\Block\BlockBase;
 use Drupal\Core\Plugin\PluginFormFactoryInterface;
 use Drupal\Tests\UnitTestCase;
 
@@ -82,6 +84,32 @@ class BlockFormTest extends UnitTestCase {
     $this->pluginFormFactory = $this->prophesize(PluginFormFactoryInterface::class);
   }
 
+  /**
+   * Mocks a block with a block plugin.
+   *
+   * @param string $machine_name
+   *   The machine name of the block plugin.
+   *
+   * @return \Drupal\block\BlockInterface|\PHPUnit_Framework_MockObject_MockObject
+   *   The mocked block.
+   */
+  protected function getBlockMockWithMachineName($machine_name) {
+    $plugin = $this->getMockBuilder(BlockBase::class)
+      ->disableOriginalConstructor()
+      ->getMock();
+    $plugin->expects($this->any())
+      ->method('getMachineNameSuggestion')
+      ->will($this->returnValue($machine_name));
+
+    $block = $this->getMockBuilder(Block::class)
+      ->disableOriginalConstructor()
+      ->getMock();
+    $block->expects($this->any())
+      ->method('getPlugin')
+      ->will($this->returnValue($plugin));
+    return $block;
+  }
+
   /**
    * Tests the unique machine name generator.
    *