Skip to content
Snippets Groups Projects
Verified Commit ae84c94c authored by quietone's avatar quietone
Browse files

Issue #2820411 by Akhil Babu, smustgrave, larowlan, joachim, quietone: Improve...

Issue #2820411 by Akhil Babu, smustgrave, larowlan, joachim, quietone: Improve the exception message when an entity handler class does not exist
parent 1c2c5636
No related branches found
No related tags found
12 merge requests!8376Drupal views: adding more granularity to the ‘use ajax’ functionality,!8300Issue #3443586 View area displays even when parent view has no results.,!7567Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7565Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7509Change label "Block description" to "Block type",!7344Issue #3292350 by O'Briat, KlemenDEV, hswong3i, smustgrave, quietone: Update...,!6922Issue #3412959 by quietone, smustgrave, longwave: Fix 12 'un' words,!6848Issue #3417553 by longwave: Remove withConsecutive() in CacheCollectorTest,!6720Revert "Issue #3358581 by pfrenssen, _tarik_, a.dmitriiev, smustgrave:...,!6560Update ClaroPreRender.php, confirming classes provided are in array format,!6528Issue #3414261 by catch: Add authenticated user umami performance tests,!6501Issue #3263668 by omkar-pd, Wim Leers, hooroomoo: Re-enable inline form errors...
Pipeline #89423 passed
Pipeline: drupal

#89425

    ......@@ -253,7 +253,11 @@ public function getHandler($entity_type_id, $handler_type) {
    $definition = $this->getDefinition($entity_type_id);
    $class = $definition->getHandlerClass($handler_type);
    if (!$class) {
    throw new InvalidPluginDefinitionException($entity_type_id, sprintf('The "%s" entity type did not specify a %s handler.', $entity_type_id, $handler_type));
    $handlers = $definition->getHandlerClasses();
    if (!isset($handlers[$handler_type])) {
    throw new InvalidPluginDefinitionException($entity_type_id, sprintf('The "%s" entity type did not specify a %s handler.', $entity_type_id, $handler_type));
    }
    throw new InvalidPluginDefinitionException($entity_type_id, sprintf('The %s handler of the "%s" entity type specifies a non-existent class "%s".', $handler_type, $entity_type_id, $handlers[$handler_type]));
    }
    $this->handlers[$handler_type][$entity_type_id] = $this->createHandlerInstance($class, $definition);
    }
    ......
    ......@@ -280,17 +280,49 @@ public function testGetHandler() {
    $this->assertInstanceOf(TranslationInterface::class, $apple_controller->stringTranslation);
    }
    /**
    * Provides test data for testGetHandlerMissingHandler().
    *
    * @return array
    * Test data.
    */
    public function provideMissingHandlerData() : array {
    return [
    'missing_handler' => [
    'test_entity_type',
    'storage',
    '',
    'The "test_entity_type" entity type did not specify a storage handler.',
    ],
    'missing_handler_class' => [
    'test_entity_type',
    'storage',
    'Non_Existing_Class',
    'The storage handler of the "test_entity_type" entity type specifies a non-existent class "Non_Existing_Class".',
    ],
    ];
    }
    /**
    * Tests the getHandler() method when no controller is defined.
    *
    * @covers ::getHandler
    *
    * @dataProvider provideMissingHandlerData
    */
    public function testGetHandlerMissingHandler() {
    public function testGetHandlerMissingHandler(string $entity_type, string $handler_name, string $handler_class, $exception_message) : void {
    $entity = $this->prophesize(EntityTypeInterface::class);
    $entity->getHandlerClass('storage')->willReturn('');
    $this->setUpEntityTypeDefinitions(['test_entity_type' => $entity]);
    $entity->getHandlerClass($handler_name)->willReturn(NULL);
    if (!$handler_class) {
    $entity->getHandlerClasses()->willReturn([]);
    }
    else {
    $entity->getHandlerClasses()->willReturn([$handler_name => $handler_class]);
    }
    $this->setUpEntityTypeDefinitions([$entity_type => $entity]);
    $this->expectException(InvalidPluginDefinitionException::class);
    $this->entityTypeManager->getHandler('test_entity_type', 'storage');
    $this->expectExceptionMessage($exception_message);
    $this->entityTypeManager->getHandler($entity_type, $handler_name);
    }
    /**
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment