Commit cee4a5c9 authored by alexpott's avatar alexpott

Issue #3016840 by tim.plunkett, EclipseGc, alexpott: When an invalid plugin ID...

Issue #3016840 by tim.plunkett, EclipseGc, alexpott: When an invalid plugin ID is requested, include valid ones in the exception message
parent 9ca03e71
......@@ -49,7 +49,8 @@ protected function doGetDefinition(array $definitions, $plugin_id, $exception_on
return NULL;
}
throw new PluginNotFoundException($plugin_id, sprintf('The "%s" plugin does not exist.', $plugin_id));
$valid_ids = implode(', ', array_keys($definitions));
throw new PluginNotFoundException($plugin_id, sprintf('The "%s" plugin does not exist. Valid plugin IDs for %s are: %s', $plugin_id, static::class, $valid_ids));
}
/**
......
......@@ -109,7 +109,7 @@ public function testMissingEffectPlugin() {
$count = 0;
foreach ($messages as $message) {
$count++;
$this->assertEqual($message->message, 'The "image_deprecated_scale" plugin does not exist.');
$this->assertContains('The "image_deprecated_scale" plugin does not exist.', $message->message);
$this->assertEqual($message->level, MigrationInterface::MESSAGE_ERROR);
}
// There should be only the one message.
......
......@@ -4,6 +4,7 @@
use Drupal\Component\Plugin\Definition\PluginDefinition;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\Context\ContextDefinition;
......@@ -132,6 +133,16 @@ public function testDefaultPluginManagerWithObjects() {
$this->assertEmpty($plugin_manager->getDefinition('cherry', FALSE), 'Plugin information is available');
}
/**
* Tests the plugin manager behavior for a missing plugin ID.
*/
public function testGetDefinitionPluginNotFoundException() {
$plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions);
$this->setExpectedException(PluginNotFoundException::class, 'The "missing" plugin does not exist. Valid plugin IDs for Drupal\Tests\Core\Plugin\TestPluginManager are: apple, banana');
$plugin_manager->getDefinition('missing');
}
/**
* Tests the plugin manager with no cache and altering.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment