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

Issue #2807879 by peaton, phenaproxima, alexpott: Convert Contact's Migrate...

Issue #2807879 by peaton, phenaproxima, alexpott: Convert Contact's Migrate source tests to new base class
parent 6b9d34c9
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
<?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;
}
}
<?php <?php
namespace Drupal\Tests\contact\Unit\Plugin\migrate\source\d6; namespace Drupal\Tests\contact\Kernel\Plugin\migrate\source\d6;
use Drupal\contact\Plugin\migrate\source\ContactSettings; use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/** /**
* Tests D6 contact settings source plugin. * Tests D6 contact settings source plugin.
* *
* @covers \Drupal\contact\Plugin\migrate\source\ContactSettings
* @group contact * @group contact
*/ */
class ContactSettingsTest extends MigrateSqlSourceTestCase { class ContactSettingsTest extends MigrateSqlSourceTestBase {
const PLUGIN_CLASS = ContactSettings::class; /**
* {@inheritdoc}
protected $migrationConfiguration = array( */
'id' => 'test', public static $modules = ['contact', 'migrate_drupal', 'user'];
'source' => array(
'plugin' => 'd6_contact_settings',
'variables' => array('site_name'),
),
);
protected $expectedResults = array(
array(
'default_category' => '1',
'site_name' => 'Blorf!',
),
);
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function setUp() { public function providerSource() {
$this->databaseContents['variable'] = array( $tests = [];
array(
$tests[0]['source_data']['variable'] = [
[
'name' => 'site_name', 'name' => 'site_name',
'value' => serialize('Blorf!'), 'value' => serialize('Blorf!'),
), ],
); ];
$this->databaseContents['contact'] = array( $tests[0]['source_data']['contact'] = [
array( [
'cid' => '1', 'cid' => '1',
'category' => 'Website feedback', 'category' => 'Website feedback',
'recipients' => 'admin@example.com', 'recipients' => 'admin@example.com',
'reply' => '', 'reply' => '',
'weight' => '0', 'weight' => '0',
'selected' => '1', 'selected' => '1',
) ]
); ];
parent::setUp(); $tests[0]['expected_data'] = [
[
'default_category' => '1',
'site_name' => 'Blorf!',
],
];
$tests[0]['expected_count'] = NULL;
$tests[0]['configuration']['variables'] = ['site_name'];
return $tests;
} }
} }
<?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();
}
}
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