From 515a55e75f6c67d48bce20fc4da39b17a2e80a9b Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Sun, 23 Oct 2016 13:10:43 -0700 Subject: [PATCH] Issue #2807879 by peaton, phenaproxima, alexpott: Convert Contact's Migrate source tests to new base class --- .../migrate/source/ContactCategoryTest.php | 57 +++++++++++++++++++ .../migrate/source/d6/ContactSettingsTest.php | 54 ++++++++++++++++++ .../migrate/source/ContactCategoryTest.php | 54 ------------------ .../migrate/source/d6/ContactSettingsTest.php | 55 ------------------ 4 files changed, 111 insertions(+), 109 deletions(-) create mode 100644 core/modules/contact/tests/src/Kernel/Plugin/migrate/source/ContactCategoryTest.php create mode 100644 core/modules/contact/tests/src/Kernel/Plugin/migrate/source/d6/ContactSettingsTest.php delete mode 100644 core/modules/contact/tests/src/Unit/Plugin/migrate/source/ContactCategoryTest.php delete mode 100644 core/modules/contact/tests/src/Unit/Plugin/migrate/source/d6/ContactSettingsTest.php diff --git a/core/modules/contact/tests/src/Kernel/Plugin/migrate/source/ContactCategoryTest.php b/core/modules/contact/tests/src/Kernel/Plugin/migrate/source/ContactCategoryTest.php new file mode 100644 index 000000000000..619e0cd10bb5 --- /dev/null +++ b/core/modules/contact/tests/src/Kernel/Plugin/migrate/source/ContactCategoryTest.php @@ -0,0 +1,57 @@ +<?php + +namespace Drupal\Tests\contact\Kernel\Plugin\migrate\source; + +use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase; + +/** + * Tests D6 contact category source plugin. + * + * @covers \Drupal\contact\Plugin\migrate\source\ContactCategory + * @group contact + */ +class ContactCategoryTest extends MigrateSqlSourceTestBase { + + /** + * {@inheritdoc} + */ + public static $modules = ['contact', 'migrate_drupal', 'user']; + + /** + * {@inheritdoc} + */ + public function providerSource() { + $tests = [ + [ + 'source_data' => [], + 'expected_data' => [], + ], + ]; + + $tests[0]['expected_data'] = [ + [ + 'cid' => 1, + 'category' => 'contact category value 1', + 'recipients' => ['admin@example.com', 'user@example.com'], + 'reply' => 'auto reply value 1', + 'weight' => 0, + 'selected' => 0, + ], + [ + 'cid' => 2, + 'category' => 'contact category value 2', + 'recipients' => ['admin@example.com', 'user@example.com'], + 'reply' => 'auto reply value 2', + 'weight' => 0, + 'selected' => 0, + ], + ]; + + foreach ($tests[0]['expected_data'] as $k => $row) { + $row['recipients'] = implode(',', $row['recipients']); + $tests[0]['source_data']['contact'][$k] = $row; + } + return $tests; + } + +} diff --git a/core/modules/contact/tests/src/Kernel/Plugin/migrate/source/d6/ContactSettingsTest.php b/core/modules/contact/tests/src/Kernel/Plugin/migrate/source/d6/ContactSettingsTest.php new file mode 100644 index 000000000000..72ea7f269498 --- /dev/null +++ b/core/modules/contact/tests/src/Kernel/Plugin/migrate/source/d6/ContactSettingsTest.php @@ -0,0 +1,54 @@ +<?php + +namespace Drupal\Tests\contact\Kernel\Plugin\migrate\source\d6; + +use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase; + +/** + * Tests D6 contact settings source plugin. + * + * @covers \Drupal\contact\Plugin\migrate\source\ContactSettings + * @group contact + */ +class ContactSettingsTest extends MigrateSqlSourceTestBase { + + /** + * {@inheritdoc} + */ + public static $modules = ['contact', 'migrate_drupal', 'user']; + + /** + * {@inheritdoc} + */ + public function providerSource() { + $tests = []; + + $tests[0]['source_data']['variable'] = [ + [ + 'name' => 'site_name', + 'value' => serialize('Blorf!'), + ], + ]; + $tests[0]['source_data']['contact'] = [ + [ + 'cid' => '1', + 'category' => 'Website feedback', + 'recipients' => 'admin@example.com', + 'reply' => '', + 'weight' => '0', + 'selected' => '1', + ] + ]; + $tests[0]['expected_data'] = [ + [ + 'default_category' => '1', + 'site_name' => 'Blorf!', + ], + ]; + $tests[0]['expected_count'] = NULL; + $tests[0]['configuration']['variables'] = ['site_name']; + + return $tests; + } + +} diff --git a/core/modules/contact/tests/src/Unit/Plugin/migrate/source/ContactCategoryTest.php b/core/modules/contact/tests/src/Unit/Plugin/migrate/source/ContactCategoryTest.php deleted file mode 100644 index cbdd688459f5..000000000000 --- a/core/modules/contact/tests/src/Unit/Plugin/migrate/source/ContactCategoryTest.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php - -namespace Drupal\Tests\contact\Unit\Plugin\migrate\source; - -use Drupal\contact\Plugin\migrate\source\ContactCategory; -use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase; - -/** - * Tests contact_category source plugin. - * - * @group contact - */ -class ContactCategoryTest extends MigrateSqlSourceTestCase { - - const PLUGIN_CLASS = ContactCategory::class; - - protected $migrationConfiguration = array( - 'id' => 'test', - 'source' => array( - 'plugin' => 'contact_category', - ), - ); - - protected $expectedResults = array( - array( - 'cid' => 1, - 'category' => 'contact category value 1', - 'recipients' => array('admin@example.com', 'user@example.com'), - 'reply' => 'auto reply value 1', - 'weight' => 0, - 'selected' => 0, - ), - array( - 'cid' => 2, - 'category' => 'contact category value 2', - 'recipients' => array('admin@example.com', 'user@example.com'), - 'reply' => 'auto reply value 2', - 'weight' => 0, - 'selected' => 0, - ), - ); - - /** - * {@inheritdoc} - */ - protected function setUp() { - foreach ($this->expectedResults as $k => $row) { - $this->databaseContents['contact'][$k] = $row; - $this->databaseContents['contact'][$k]['recipients'] = implode(',', $row['recipients']); - } - parent::setUp(); - } - -} diff --git a/core/modules/contact/tests/src/Unit/Plugin/migrate/source/d6/ContactSettingsTest.php b/core/modules/contact/tests/src/Unit/Plugin/migrate/source/d6/ContactSettingsTest.php deleted file mode 100644 index 95850cdae8a7..000000000000 --- a/core/modules/contact/tests/src/Unit/Plugin/migrate/source/d6/ContactSettingsTest.php +++ /dev/null @@ -1,55 +0,0 @@ -<?php - -namespace Drupal\Tests\contact\Unit\Plugin\migrate\source\d6; - -use Drupal\contact\Plugin\migrate\source\ContactSettings; -use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase; - -/** - * Tests D6 contact settings source plugin. - * - * @group contact - */ -class ContactSettingsTest extends MigrateSqlSourceTestCase { - - const PLUGIN_CLASS = ContactSettings::class; - - protected $migrationConfiguration = array( - 'id' => 'test', - 'source' => array( - 'plugin' => 'd6_contact_settings', - 'variables' => array('site_name'), - ), - ); - - protected $expectedResults = array( - array( - 'default_category' => '1', - 'site_name' => 'Blorf!', - ), - ); - - /** - * {@inheritdoc} - */ - protected function setUp() { - $this->databaseContents['variable'] = array( - array( - 'name' => 'site_name', - 'value' => serialize('Blorf!'), - ), - ); - $this->databaseContents['contact'] = array( - array( - 'cid' => '1', - 'category' => 'Website feedback', - 'recipients' => 'admin@example.com', - 'reply' => '', - 'weight' => '0', - 'selected' => '1', - ) - ); - parent::setUp(); - } - -} -- GitLab