From 27a94ebdc0fdf67310cfcffa97d8b32714d1e838 Mon Sep 17 00:00:00 2001 From: webchick <webchick@24967.no-reply.drupal.org> Date: Fri, 3 Jan 2014 00:07:02 -0800 Subject: [PATCH] Issue #2152355 by chx: Refactor the entity dedupe test to use dataProvider. --- .../Tests/process/DedupeEntityTest.php | 74 +++++++------------ 1 file changed, 28 insertions(+), 46 deletions(-) diff --git a/core/modules/migrate/tests/Drupal/migrate/Tests/process/DedupeEntityTest.php b/core/modules/migrate/tests/Drupal/migrate/Tests/process/DedupeEntityTest.php index e4ccc753393a..4948dab1673c 100644 --- a/core/modules/migrate/tests/Drupal/migrate/Tests/process/DedupeEntityTest.php +++ b/core/modules/migrate/tests/Drupal/migrate/Tests/process/DedupeEntityTest.php @@ -10,8 +10,12 @@ use Drupal\migrate\Plugin\migrate\process\DedupeEntity; /** + * Test the deduplication entity process plugin. + * * @group migrate * @group Drupal + * + * @see \Drupal\migrate\Plugin\migrate\process\DedupeEntity */ class DedupeEntityTest extends MigrateProcessTestCase { @@ -44,65 +48,43 @@ public function setUp() { } /** - * Tests the entity deduplication plugin when there is no duplication. - */ - public function testDedupeEntityNoDuplication() { - $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. + * Tests entity based deduplication based on providerTestDedupe() values. + * + * @dataProvider providerTestDedupe */ - public function testDedupeEntityNoDuplicationWithPostfix() { + public function testDedupe($count, $postfix = '') { $configuration = array( 'entity_type' => 'test_entity_type', 'field' => 'test_field', - 'postfix' => '_', ); + if ($postfix) { + $configuration['postfix'] = $postfix; + } $plugin = new TestDedupeEntity($configuration, 'dedupe_entity', array()); - $this->entityQueryExpects(0); + $this->entityQueryExpects($count); $plugin->setEntityQuery($this->entityQuery); $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() { - $configuration = array( - 'entity_type' => 'test_entity_type', - 'field' => 'test_field', - 'postfix' => '_', + public function providerTestDedupe() { + return array( + // Tests the entity deduplication plugin when there is no duplication + // and no 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'); } /** -- GitLab