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

Issue #3200534 by quietone, longwave, Kristen Pol: Use dataprovider for...

Issue #3200534 by quietone, longwave, Kristen Pol: Use dataprovider for constructor test in ContentEntityTest
parent cb14cbaf
Branches
Tags
Loading
<?php
namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source;
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\KernelTests\KernelTestBase;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_drupal\Plugin\migrate\source\ContentEntity;
/**
* Tests the constructor of the entity content source plugin.
*
* @group migrate_drupal
*/
class ContentEntityConstructorTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'migrate',
'migrate_drupal',
'node',
'system',
'user',
];
/**
* Tests the constructor.
*
* @dataProvider providerTestConstructor
*/
public function testConstructor($configuration, $plugin_definition, $exception_class, $expected) {
$migration = $this->prophesize(MigrationInterface::class)->reveal();
$this->expectException($exception_class);
$this->expectExceptionMessage($expected);
ContentEntity::create($this->container, $configuration, 'content_entity', $plugin_definition, $migration);
}
/**
* Provides data for constructor tests.
*/
public function providerTestConstructor() {
return [
'entity type missing' => [
[],
['entity_type' => ''],
InvalidPluginDefinitionException::class,
'Missing required "entity_type" definition.',
],
'non content entity' => [
[],
['entity_type' => 'node_type'],
InvalidPluginDefinitionException::class,
'The entity type (node_type) is not supported. The "content_entity" source plugin only supports content entities.',
],
'not bundleable' => [
['bundle' => 'foo'],
['entity_type' => 'user'],
\InvalidArgumentException::class,
'A bundle was provided but the entity type (user) is not bundleable.',
],
'invalid bundle' => [
['bundle' => 'foo'],
['entity_type' => 'node'],
\InvalidArgumentException::class,
'The provided bundle (foo) is not valid for the (node) entity type.',
],
];
}
}
......@@ -2,7 +2,6 @@
namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source;
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
......@@ -11,8 +10,6 @@
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\media\Entity\Media;
use Drupal\migrate\Plugin\MigrateSourceInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_drupal\Plugin\migrate\source\ContentEntity;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\taxonomy\Entity\Term;
......@@ -179,66 +176,6 @@ protected function setUp(): void {
$this->migrationPluginManager = $this->container->get('plugin.manager.migration');
}
/**
* Tests the constructor for missing entity_type.
*/
public function testConstructorEntityTypeMissing() {
$migration = $this->prophesize(MigrationInterface::class)->reveal();
$configuration = [];
$plugin_definition = [
'entity_type' => '',
];
$this->expectException(InvalidPluginDefinitionException::class);
$this->expectExceptionMessage('Missing required "entity_type" definition.');
ContentEntity::create($this->container, $configuration, 'content_entity', $plugin_definition, $migration);
}
/**
* Tests the constructor for non content entity.
*/
public function testConstructorNonContentEntity() {
$migration = $this->prophesize(MigrationInterface::class)->reveal();
$configuration = [];
$plugin_definition = [
'entity_type' => 'node_type',
];
$this->expectException(InvalidPluginDefinitionException::class);
$this->expectExceptionMessage('The entity type (node_type) is not supported. The "content_entity" source plugin only supports content entities.');
ContentEntity::create($this->container, $configuration, 'content_entity:node_type', $plugin_definition, $migration);
}
/**
* Tests the constructor for not bundleable entity.
*/
public function testConstructorNotBundable() {
$migration = $this->prophesize(MigrationInterface::class)->reveal();
$configuration = [
'bundle' => 'foo',
];
$plugin_definition = [
'entity_type' => 'user',
];
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('A bundle was provided but the entity type (user) is not bundleable');
ContentEntity::create($this->container, $configuration, 'content_entity:user', $plugin_definition, $migration);
}
/**
* Tests the constructor for invalid entity bundle.
*/
public function testConstructorInvalidBundle() {
$migration = $this->prophesize(MigrationInterface::class)->reveal();
$configuration = [
'bundle' => 'foo',
];
$plugin_definition = [
'entity_type' => 'node',
];
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The provided bundle (foo) is not valid for the (node) entity type.');
ContentEntity::create($this->container, $configuration, 'content_entity:node', $plugin_definition, $migration);
}
/**
* Helper to assert IDs structure.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment