Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Block / BlockManagerTest.php
index 1e9bb436db5ddfbababc084fdfbe4759d965c3e9..0f92b8efbc625bd7114348f4885d512e8a77f543 100644 (file)
@@ -4,9 +4,11 @@ namespace Drupal\Tests\Core\Block;
 
 use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
 use Drupal\Core\Block\BlockManager;
+use Drupal\Core\Block\Plugin\Block\Broken;
 use Drupal\Core\Cache\CacheBackendInterface;
 use Drupal\Core\Extension\ModuleHandlerInterface;
 use Drupal\Tests\UnitTestCase;
+use Psr\Log\LoggerInterface;
 
 /**
  * @coversDefaultClass \Drupal\Core\Block\BlockManager
@@ -22,6 +24,13 @@ class BlockManagerTest extends UnitTestCase {
    */
   protected $blockManager;
 
+  /**
+   * The logger.
+   *
+   * @var \Psr\Log\LoggerInterface
+   */
+  protected $logger;
+
   /**
    * {@inheritdoc}
    */
@@ -30,7 +39,8 @@ class BlockManagerTest extends UnitTestCase {
 
     $cache_backend = $this->prophesize(CacheBackendInterface::class);
     $module_handler = $this->prophesize(ModuleHandlerInterface::class);
-    $this->blockManager = new BlockManager(new \ArrayObject(), $cache_backend->reveal(), $module_handler->reveal());
+    $this->logger = $this->prophesize(LoggerInterface::class);
+    $this->blockManager = new BlockManager(new \ArrayObject(), $cache_backend->reveal(), $module_handler->reveal(), $this->logger->reveal());
     $this->blockManager->setStringTranslation($this->getStringTranslationStub());
 
     $discovery = $this->prophesize(DiscoveryInterface::class);
@@ -40,6 +50,8 @@ class BlockManagerTest extends UnitTestCase {
       'broken' => [
         'admin_label' => 'Broken/Missing',
         'category' => 'Block',
+        'class' => Broken::class,
+        'provider' => 'core',
       ],
       'block1' => [
         'admin_label' => 'Coconut',
@@ -86,4 +98,13 @@ class BlockManagerTest extends UnitTestCase {
     $this->assertSame(['block3', 'block1'], array_keys($definitions['Group 2']));
   }
 
+  /**
+   * @covers ::handlePluginNotFound
+   */
+  public function testHandlePluginNotFound() {
+    $this->logger->warning('The "%plugin_id" was not found', ['%plugin_id' => 'invalid'])->shouldBeCalled();
+    $plugin = $this->blockManager->createInstance('invalid');
+    $this->assertSame('broken', $plugin->getPluginId());
+  }
+
 }