Skip to content
Snippets Groups Projects
Commit 27a94ebd authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2152355 by chx: Refactor the entity dedupe test to use dataProvider.

parent d5efc596
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -10,8 +10,12 @@ ...@@ -10,8 +10,12 @@
use Drupal\migrate\Plugin\migrate\process\DedupeEntity; use Drupal\migrate\Plugin\migrate\process\DedupeEntity;
/** /**
* Test the deduplication entity process plugin.
*
* @group migrate * @group migrate
* @group Drupal * @group Drupal
*
* @see \Drupal\migrate\Plugin\migrate\process\DedupeEntity
*/ */
class DedupeEntityTest extends MigrateProcessTestCase { class DedupeEntityTest extends MigrateProcessTestCase {
...@@ -44,65 +48,43 @@ public function setUp() { ...@@ -44,65 +48,43 @@ public function setUp() {
} }
/** /**
* Tests the entity deduplication plugin when there is no duplication. * Tests entity based deduplication based on providerTestDedupe() values.
*/ *
public function testDedupeEntityNoDuplication() { * @dataProvider providerTestDedupe
$configuration = array(
'entity_type' => 'test_entity_type',
'field' => 'test_field',
);
$plugin = new TestDedupeEntity($configuration, 'dedupe_entity', array());
$this->entityQueryExpects(0);
$plugin->setEntityQuery($this->entityQuery);
$return = $plugin->transform('test', $this->migrateExecutable, $this->row, 'testpropertty');
$this->assertSame($return, 'test');
}
/**
* Tests the entity deduplication plugin when there is duplication.
*/
public function testDedupeEntityDuplication() {
$configuration = array(
'entity_type' => 'test_entity_type',
'field' => 'test_field',
);
$plugin = new TestDedupeEntity($configuration, 'dedupe_entity', array());
$this->entityQueryExpects(3);
$plugin->setEntityQuery($this->entityQuery);
$return = $plugin->transform('test', $this->migrateExecutable, $this->row, 'testpropertty');
$this->assertSame($return, 'test3');
}
/**
* Tests the entity deduplication plugin when there is no duplication.
*/ */
public function testDedupeEntityNoDuplicationWithPostfix() { public function testDedupe($count, $postfix = '') {
$configuration = array( $configuration = array(
'entity_type' => 'test_entity_type', 'entity_type' => 'test_entity_type',
'field' => 'test_field', 'field' => 'test_field',
'postfix' => '_',
); );
if ($postfix) {
$configuration['postfix'] = $postfix;
}
$plugin = new TestDedupeEntity($configuration, 'dedupe_entity', array()); $plugin = new TestDedupeEntity($configuration, 'dedupe_entity', array());
$this->entityQueryExpects(0); $this->entityQueryExpects($count);
$plugin->setEntityQuery($this->entityQuery); $plugin->setEntityQuery($this->entityQuery);
$return = $plugin->transform('test', $this->migrateExecutable, $this->row, 'testpropertty'); $return = $plugin->transform('test', $this->migrateExecutable, $this->row, 'testpropertty');
$this->assertSame($return, 'test'); $this->assertSame($return, 'test' . ($count ? $postfix . $count : ''));
} }
/** /**
* Tests the entity deduplication plugin when there is duplication. * Data provider for testDedupe().
*/ */
public function testDedupeEntityDuplicationWithPostfix() { public function providerTestDedupe() {
$configuration = array( return array(
'entity_type' => 'test_entity_type', // Tests the entity deduplication plugin when there is no duplication
'field' => 'test_field', // and no postfix.
'postfix' => '_', array(0),
// Tests the entity deduplication plugin when there is duplication but
// no postfix.
array(3),
// Tests the entity deduplication plugin when there is no duplication
// but there is a postfix.
array(0, '_'),
// Tests the entity deduplication plugin when there is duplication and
// there is a postfix.
array(2, '_'),
); );
$plugin = new TestDedupeEntity($configuration, 'dedupe_entity', array());
$this->entityQueryExpects(2);
$plugin->setEntityQuery($this->entityQuery);
$return = $plugin->transform('test', $this->migrateExecutable, $this->row, 'testpropertty');
$this->assertSame($return, 'test_2');
} }
/** /**
......
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