Commit bdcd4979 authored by alexpott's avatar alexpott

Issue #2807875 by quietone, Jo Fitzgerald, erozqba, phenaproxima: Convert...

Issue #2807875 by quietone, Jo Fitzgerald, erozqba, phenaproxima: Convert Comment's Migrate source tests to new base class
parent 5bd7f43d
<?php
namespace Drupal\Tests\comment\Kernel\Plugin\migrate\source\d6;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests the Drupal 6 comment source w/ high water handling.
*
* @covers \Drupal\comment\Plugin\migrate\source\d6\Comment
*
* @group comment
*/
class CommentSourceWithHighWaterTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['comments'] = [
[
'cid' => 1,
'pid' => 0,
'nid' => 2,
'uid' => 3,
'subject' => 'subject value 1',
'comment' => 'comment value 1',
'hostname' => 'hostname value 1',
'timestamp' => 1382255613,
'status' => 0,
'thread' => '',
'name' => '',
'mail' => '',
'homepage' => '',
'format' => 'testformat1',
'type' => 'story',
],
[
'cid' => 2,
'pid' => 1,
'nid' => 3,
'uid' => 4,
'subject' => 'subject value 2',
'comment' => 'comment value 2',
'hostname' => 'hostname value 2',
'timestamp' => 1382255662,
'status' => 0,
'thread' => '',
'name' => '',
'mail' => '',
'homepage' => '',
'format' => 'testformat2',
'type' => 'page',
],
];
$tests[0]['source_data']['node'] = [
[
'nid' => 2,
'type' => 'story',
],
[
'nid' => 3,
'type' => 'page',
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'cid' => 2,
'pid' => 1,
'nid' => 3,
'uid' => 4,
'subject' => 'subject value 2',
'comment' => 'comment value 2',
'hostname' => 'hostname value 2',
'timestamp' => 1382255662,
'status' => 1,
'thread' => '',
'name' => '',
'mail' => '',
'homepage' => '',
'format' => 'testformat2',
'type' => 'page',
],
];
// The expected count.
$tests[0]['expected_count'] = NULL;
$tests[0]['configuration']['high_water_property']['name'] = 'timestamp';
$tests[0]['high_water'] = $tests[0]['source_data']['comments'][0]['timestamp'];
return $tests;
}
}
<?php
namespace Drupal\Tests\comment\Kernel\Plugin\migrate\source\d6;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests D6 comment source plugin.
*
* @covers \Drupal\comment\Plugin\migrate\source\d6\Comment
* @group comment
*/
class CommentTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['comments'] = [
[
'cid' => 1,
'pid' => 0,
'nid' => 2,
'uid' => 3,
'subject' => 'subject value 1',
'comment' => 'comment value 1',
'hostname' => 'hostname value 1',
'timestamp' => 1382255613,
'status' => 0,
'thread' => '',
'name' => '',
'mail' => '',
'homepage' => '',
'format' => 'testformat1',
'type' => 'story',
],
[
'cid' => 2,
'pid' => 1,
'nid' => 3,
'uid' => 4,
'subject' => 'subject value 2',
'comment' => 'comment value 2',
'hostname' => 'hostname value 2',
'timestamp' => 1382255662,
'status' => 0,
'thread' => '',
'name' => '',
'mail' => '',
'homepage' => '',
'format' => 'testformat2',
'type' => 'page',
],
];
$tests[0]['source_data']['node'] = [
[
'nid' => 2,
'type' => 'story',
],
[
'nid' => 3,
'type' => 'page',
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'cid' => 1,
'pid' => 0,
'nid' => 2,
'uid' => 3,
'subject' => 'subject value 1',
'comment' => 'comment value 1',
'hostname' => 'hostname value 1',
'timestamp' => 1382255613,
'status' => 1,
'thread' => '',
'name' => '',
'mail' => '',
'homepage' => '',
'format' => 'testformat1',
'type' => 'story',
],
[
'cid' => 2,
'pid' => 1,
'nid' => 3,
'uid' => 4,
'subject' => 'subject value 2',
'comment' => 'comment value 2',
'hostname' => 'hostname value 2',
'timestamp' => 1382255662,
'status' => 1,
'thread' => '',
'name' => '',
'mail' => '',
'homepage' => '',
'format' => 'testformat2',
'type' => 'page',
],
];
return $tests;
}
}
<?php
namespace Drupal\Tests\comment\Unit\Migrate\d6;
namespace Drupal\Tests\comment\Kernel\Plugin\migrate\source\d6;
use Drupal\comment\Plugin\migrate\source\d6\CommentVariablePerCommentType;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* @coversDefaultClass \Drupal\comment\Plugin\migrate\source\d6\CommentVariablePerCommentType
* Tests comment variable per comment type source plugin.
*
* @covers \Drupal\comment\Plugin\migrate\source\d6\CommentVariablePerCommentType
* @group comment
*/
class CommentVariablePerCommentTypeTest extends MigrateSqlSourceTestCase {
class CommentVariablePerCommentTypeTest extends MigrateSqlSourceTestBase {
const PLUGIN_CLASS = CommentVariablePerCommentType::class;
protected $migrationConfiguration = [
'id' => 'test',
'source' => [
'plugin' => 'd6_comment_variable_per_comment_type',
],
];
protected $expectedResults = [
// Each result will also include a label and description, but those are
// static values set by the source plugin and don't need to be asserted.
[
'comment_type' => 'comment',
],
[
'comment_type' => 'comment_no_subject',
],
];
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->databaseContents['node_type'] = [
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['node_type'] = [
[
'type' => 'page',
],
......@@ -43,7 +32,8 @@ protected function setUp() {
'type' => 'story',
],
];
$this->databaseContents['variable'] = [
$tests[0]['source_data']['variable'] = [
[
'name' => 'comment_subject_field_page',
'value' => serialize(1),
......@@ -53,7 +43,20 @@ protected function setUp() {
'value' => serialize(0),
],
];
parent::setUp();
// The expected results.
// Each result will also include a label and description, but those are
// static values set by the source plugin and don't need to be asserted.
$tests[0]['expected_data'] = [
[
'comment_type' => 'comment',
],
[
'comment_type' => 'comment_no_subject',
],
];
return $tests;
}
}
<?php
namespace Drupal\Tests\comment\Unit\Migrate\d6;
namespace Drupal\Tests\comment\Kernel\Plugin\migrate\source\d6;
use Drupal\comment\Plugin\migrate\source\d6\CommentVariable;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* @coversDefaultClass \Drupal\comment\Plugin\migrate\source\d6\CommentVariable
* Tests d6_comment_variable source plugin.
*
* @covers \Drupal\comment\Plugin\migrate\source\d6\CommentVariable
* @group comment
*/
class CommentVariableTest extends MigrateSqlSourceTestCase {
class CommentVariableTest extends MigrateSqlSourceTestBase {
const PLUGIN_CLASS = CommentVariable::class;
protected $migrationConfiguration = [
'id' => 'test',
'source' => [
'plugin' => 'd6_comment_variable',
],
];
protected $expectedResults = [
[
'comment' => '1',
'comment_default_mode' => '1',
'comment_default_order' => '1',
'comment_default_per_page' => '50',
'comment_controls' => '1',
'comment_anonymous' => '1',
'comment_subject_field' => '1',
'comment_preview' => '1',
'comment_form_location' => '1',
'node_type' => 'page',
'comment_type' => 'comment',
],
];
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->databaseContents['node_type'] = [
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['node_type'] = [
[
'type' => 'page',
],
];
$this->databaseContents['variable'] = [
$tests[0]['source_data']['variable'] = [
[
'name' => 'comment_page',
'value' => serialize(1),
......@@ -83,7 +68,25 @@ protected function setUp() {
'value' => serialize(1),
],
];
parent::setUp();
// The expected results.
$tests[0]['expected_data'] = [
[
'comment' => '1',
'comment_default_mode' => '1',
'comment_default_order' => '1',
'comment_default_per_page' => '50',
'comment_controls' => '1',
'comment_anonymous' => '1',
'comment_subject_field' => '1',
'comment_preview' => '1',
'comment_form_location' => '1',
'node_type' => 'page',
'comment_type' => 'comment',
],
];
return $tests;
}
}
<?php
namespace Drupal\Tests\comment\Unit\Migrate\d7;
namespace Drupal\Tests\comment\Kernel\Plugin\migrate\source\d7;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests D7 comment source plugin.
*
* @covers \Drupal\comment\Plugin\migrate\source\d7\Comment
* @group comment
*/
class CommentTest extends MigrateSqlSourceTestCase {
class CommentTest extends MigrateSqlSourceTestBase {
const PLUGIN_CLASS = 'Drupal\comment\Plugin\migrate\source\d7\Comment';
protected $migrationConfiguration = [
'id' => 'test',
'source' => [
'plugin' => 'd7_comment',
],
];
protected $expectedResults = [
[
'cid' => '1',
'pid' => '0',
'nid' => '1',
'uid' => '1',
'subject' => 'A comment',
'hostname' => '::1',
'created' => '1421727536',
'changed' => '1421727536',
'status' => '1',
'thread' => '01/',
'name' => 'admin',
'mail' => '',
'homepage' => '',
'language' => 'und',
'comment_body' => [
[
'value' => 'This is a comment',
'format' => 'filtered_html',
],
],
],
];
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->databaseContents['comment'] = $this->expectedResults;
unset($this->databaseContents['comment'][0]['comment_body']);
public function providerSource() {
$tests = [];
$this->databaseContents['node'] = [
// The source data.
$tests[0]['source_data']['comment'] = [
[
'cid' => '1',
'pid' => '0',
'nid' => '1',
'uid' => '1',
'subject' => 'A comment',
'hostname' => '::1',
'created' => '1421727536',
'changed' => '1421727536',
'status' => '1',
'thread' => '01/',
'name' => 'admin',
'mail' => '',
'homepage' => '',
'language' => 'und',
],
];
$tests[0]['source_data']['node'] = [
[
'nid' => '1',
'vid' => '1',
......@@ -70,7 +60,7 @@ protected function setUp() {
'translate' => '0',
],
];
$this->databaseContents['field_config_instance'] = [
$tests[0]['source_data']['field_config_instance'] = [
[
'id' => '14',
'field_id' => '1',
......@@ -81,7 +71,7 @@ protected function setUp() {
'deleted' => '0',
],
];
$this->databaseContents['field_data_comment_body'] = [
$tests[0]['source_data']['field_data_comment_body'] = [
[
'entity_type' => 'comment',
'bundle' => 'comment_node_test_content_type',
......@@ -94,7 +84,34 @@ protected function setUp() {
'comment_body_format' => 'filtered_html',
],
];
parent::setUp();
// The expected results.
$tests[0]['expected_data'] = [
[
'cid' => '1',
'pid' => '0',
'nid' => '1',
'uid' => '1',
'subject' => 'A comment',
'hostname' => '::1',
'created' => '1421727536',
'changed' => '1421727536',
'status' => '1',
'thread' => '01/',
'name' => 'admin',
'mail' => '',
'homepage' => '',
'language' => 'und',
'comment_body' => [
[
'value' => 'This is a comment',
'format' => 'filtered_html',
],
],
],
];
return $tests;
}
}
<?php
namespace Drupal\Tests\comment\Unit\Migrate\d7;
namespace Drupal\Tests\comment\Kernel\Plugin\migrate\source\d7;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests D7 comment type source plugin.
*
* @covers \Drupal\comment\Plugin\migrate\source\d7\CommentType
* @group comment
*/
class CommentTypeTest extends MigrateSqlSourceTestCase {
class CommentTypeTest extends MigrateSqlSourceTestBase {
const PLUGIN_CLASS = 'Drupal\comment\Plugin\migrate\source\d7\CommentType';
protected $migrationConfiguration = [
'id' => 'test',
'source' => [
'plugin' => 'd7_comment_type',
],
];
protected $expectedResults = [
[
'bundle' => 'comment_node_article',
'node_type' => 'article',
'default_mode' => '1',
'per_page' => '50',
'anonymous' => '0',
'form_location' => '1',
'preview' => '0',
'subject' => '1',
'label' => 'Article comment',
],
];
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->databaseContents['node_type'] = [
public function providerSource() {
$tests = [];
// The source data.
$tests[0]['source_data']['node_type'] = [
[
'type' => 'article',
'name' => 'Article',
......@@ -55,7 +41,7 @@ protected function setUp() {
'orig_type' => 'article',
],
];
$this->databaseContents['field_config_instance'] = [
$tests[0]['source_data']['field_config_instance'] = [
[
'id' => '14',
'field_id' => '1',
......@@ -66,7 +52,7 @@ protected function setUp() {
'deleted' => '0',
],
];
$this->databaseContents['variable'] = [
$tests[0]['source_data']['variable'] = [
[
'name' => 'comment_default_mode_article',
'value' => serialize(1),
......@@ -92,7 +78,22 @@ protected function setUp() {
'value' => serialize(1),
],
];
parent::setUp();
// The expected results.
$tests[0]['expected_data'] = [
[
'bundle' => 'comment_node_article',
'node_type' => 'article',
'default_mode' => '1',
'per_page' => '50',
'anonymous' => '0',
'form_location' => '1',
'preview' => '0',
'subject' => '1',
'label' => 'Article comment',
],
];
return $tests;
}
}
<?php
namespace Drupal\Tests\comment\Unit\Migrate\d6;
/**
* Tests the Drupal 6 comment source w/ high water handling.
*
* @group comment
*/
class CommentSourceWithHighWaterTest extends CommentTestBase {
const ORIGINAL_HIGH_WATER = 1382255613;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->migrationConfiguration['source']['high_water_property']['name'] = 'timestamp';
array_shift($this->expectedResults);
parent::setUp();
}
}
<?php
namespace Drupal\Tests\comment\Unit\Migrate\d6;
/**
* Tests D6 comment source plugin.
*
* @group comment
*/
class CommentTest extends CommentTestBase {
}
<?php
namespace Drupal\Tests\comment\Unit\Migrate\d6;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Base class for comment source unit tests.
*/
abstract class CommentTestBase extends MigrateSqlSourceTestCase {
// The plugin system is not working during unit testing so the source plugin
// class needs to be manually specified.
const PLUGIN_CLASS = 'Drupal\comment\Plugin\migrate\source\d6\Comment';