Skip to content
Snippets Groups Projects
Unverified Commit f26adfd7 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2797421 by dcam, mikeryan, chx, id.conky, mkalkbrenner, mikelutz:...

Issue #2797421 by dcam, mikeryan, chx, id.conky, mkalkbrenner, mikelutz: Sourceless migration plugins are broken

(cherry picked from commit c42f5d93)
parent 66a2caac
No related branches found
No related tags found
No related merge requests found
Pipeline #475022 passed with warnings
Pipeline: drupal

#475060

    Pipeline: drupal

    #475053

      Pipeline: drupal

      #475042

        +1
        ......@@ -36,7 +36,7 @@ public function getDefinitions() {
        /** @var \Drupal\Component\Plugin\PluginManagerInterface $source_plugin_manager */
        $source_plugin_manager = \Drupal::service('plugin.manager.migrate.source');
        return array_filter($this->decorated->getDefinitions(), function (array $definition) use ($source_plugin_manager) {
        return $source_plugin_manager->hasDefinition($definition['source']['plugin']);
        return !empty($definition['source']['plugin']) && $source_plugin_manager->hasDefinition($definition['source']['plugin']);
        });
        }
        ......
        <?php
        declare(strict_types=1);
        namespace Drupal\Tests\migrate\Unit\Plugin;
        use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
        use Drupal\Core\DependencyInjection\ContainerBuilder;
        use Drupal\migrate\Plugin\MigrateSourcePluginManager;
        use Drupal\migrate\Plugin\NoSourcePluginDecorator;
        use Drupal\Tests\UnitTestCase;
        /**
        * @coversDefaultClass \Drupal\migrate\Plugin\NoSourcePluginDecorator
        * @group migrate
        */
        class NoSourcePluginDecoratorTest extends UnitTestCase {
        /**
        * @covers ::getDefinitions
        * @dataProvider providerGetDefinitions
        */
        public function testGetDefinitions(array $definition, bool $source_exists): void {
        $source_manager = $this->createMock(MigrateSourcePluginManager::class);
        $source_manager->expects($this->any())
        ->method('hasDefinition')
        ->willReturn($source_exists);
        $container = new ContainerBuilder();
        $container->set('plugin.manager.migrate.source', $source_manager);
        \Drupal::setContainer($container);
        $discovery_interface = $this->createMock(DiscoveryInterface::class);
        $discovery_interface->expects($this->once())
        ->method('getDefinitions')
        ->willReturn([$definition]);
        $decorator = new NoSourcePluginDecorator($discovery_interface);
        $results = $decorator->getDefinitions();
        if ($source_exists) {
        $this->assertEquals([$definition], $results);
        }
        else {
        $this->assertEquals([], $results);
        }
        }
        /**
        * Provides data for testGetDefinitions().
        */
        public static function providerGetDefinitions(): array {
        return [
        'source exists' => [
        [
        'source' => ['plugin' => 'valid_plugin'],
        'process' => [],
        'destination' => [],
        ],
        TRUE,
        ],
        'source does not exist' => [
        [
        'source' => ['plugin' => 'invalid_plugin'],
        'process' => [],
        'destination' => [],
        ],
        FALSE,
        ],
        'source is not defined' => [
        [
        'process' => [],
        'destination' => [],
        ],
        FALSE,
        ],
        ];
        }
        }
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment