diff --git a/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentSourceWithHighWaterTest.php b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentSourceWithHighWaterTest.php new file mode 100644 index 0000000..27fb068 --- /dev/null +++ b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentSourceWithHighWaterTest.php @@ -0,0 +1,105 @@ + 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; + } + +} diff --git a/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentTest.php b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentTest.php new file mode 100644 index 0000000..0372f0f --- /dev/null +++ b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentTest.php @@ -0,0 +1,116 @@ + 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; + } + +} diff --git a/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentVariablePerCommentTypeTest.php b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentVariablePerCommentTypeTest.php new file mode 100644 index 0000000..dd1b1fd --- /dev/null +++ b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentVariablePerCommentTypeTest.php @@ -0,0 +1,62 @@ + 'page', + ], + [ + 'type' => 'story', + ], + ]; + + $tests[0]['source_data']['variable'] = [ + [ + 'name' => 'comment_subject_field_page', + 'value' => serialize(1), + ], + [ + 'name' => 'comment_subject_field_story', + 'value' => serialize(0), + ], + ]; + + // 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; + } + +} diff --git a/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentVariableTest.php b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentVariableTest.php new file mode 100644 index 0000000..a84c776 --- /dev/null +++ b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentVariableTest.php @@ -0,0 +1,92 @@ + 'page', + ], + ]; + + $tests[0]['source_data']['variable'] = [ + [ + 'name' => 'comment_page', + 'value' => serialize(1), + ], + [ + 'name' => 'comment_default_mode_page', + 'value' => serialize(1), + ], + [ + 'name' => 'comment_default_order_page', + 'value' => serialize(1), + ], + [ + 'name' => 'comment_default_per_page_page', + 'value' => serialize(50), + ], + [ + 'name' => 'comment_controls_page', + 'value' => serialize(1), + ], + [ + 'name' => 'comment_anonymous_page', + 'value' => serialize(1), + ], + [ + 'name' => 'comment_subject_field_page', + 'value' => serialize(1), + ], + [ + 'name' => 'comment_preview_page', + 'value' => serialize(1), + ], + [ + 'name' => 'comment_form_location_page', + 'value' => serialize(1), + ], + ]; + + // 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; + } + +} diff --git a/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d7/CommentTest.php b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d7/CommentTest.php new file mode 100644 index 0000000..9d9760b --- /dev/null +++ b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d7/CommentTest.php @@ -0,0 +1,117 @@ + '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', + 'type' => 'test_content_type', + 'language' => 'en', + 'title' => 'A Node', + 'uid' => '1', + 'status' => '1', + 'created' => '1421727515', + 'changed' => '1421727515', + 'comment' => '2', + 'promote' => '1', + 'sticky' => '0', + 'tnid' => '0', + 'translate' => '0', + ], + ]; + $tests[0]['source_data']['field_config_instance'] = [ + [ + 'id' => '14', + 'field_id' => '1', + 'field_name' => 'comment_body', + 'entity_type' => 'comment', + 'bundle' => 'comment_node_test_content_type', + 'data' => 'a:0:{}', + 'deleted' => '0', + ], + ]; + $tests[0]['source_data']['field_data_comment_body'] = [ + [ + 'entity_type' => 'comment', + 'bundle' => 'comment_node_test_content_type', + 'deleted' => '0', + 'entity_id' => '1', + 'revision_id' => '1', + 'language' => 'und', + 'delta' => '0', + 'comment_body_value' => 'This is a comment', + 'comment_body_format' => 'filtered_html', + ], + ]; + + // 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; + } + +} diff --git a/core/modules/comment/tests/src/Unit/Migrate/d7/CommentTypeTest.php b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d7/CommentTypeTest.php similarity index 60% rename from core/modules/comment/tests/src/Unit/Migrate/d7/CommentTypeTest.php rename to core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d7/CommentTypeTest.php index 106716d..11f3db5 100644 --- a/core/modules/comment/tests/src/Unit/Migrate/d7/CommentTypeTest.php +++ b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d7/CommentTypeTest.php @@ -1,44 +1,30 @@ '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; } } diff --git a/core/modules/comment/tests/src/Unit/Migrate/d6/CommentSourceWithHighWaterTest.php b/core/modules/comment/tests/src/Unit/Migrate/d6/CommentSourceWithHighWaterTest.php deleted file mode 100644 index b2cbaa7..0000000 --- a/core/modules/comment/tests/src/Unit/Migrate/d6/CommentSourceWithHighWaterTest.php +++ /dev/null @@ -1,23 +0,0 @@ -migrationConfiguration['source']['high_water_property']['name'] = 'timestamp'; - array_shift($this->expectedResults); - parent::setUp(); - } - -} diff --git a/core/modules/comment/tests/src/Unit/Migrate/d6/CommentTest.php b/core/modules/comment/tests/src/Unit/Migrate/d6/CommentTest.php deleted file mode 100644 index 2056d24..0000000 --- a/core/modules/comment/tests/src/Unit/Migrate/d6/CommentTest.php +++ /dev/null @@ -1,12 +0,0 @@ - 'test', - // This needs to be the identifier of the actual key: cid for comment, nid - // for node and so on. - 'source' => [ - 'plugin' => 'd6_comment', - ], - ]; - - // We need to set up the database contents; it's easier to do that below. - - protected $expectedResults = [ - [ - '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', - ], - ]; - - /** - * {@inheritdoc} - */ - protected function setUp() { - foreach ($this->expectedResults as $k => $row) { - $this->databaseContents['comments'][$k] = $row; - $this->databaseContents['comments'][$k]['status'] = 1 - $this->databaseContents['comments'][$k]['status']; - } - // Add node table data. - $this->databaseContents['node'][] = ['nid' => 2, 'type' => 'story']; - $this->databaseContents['node'][] = ['nid' => 3, 'type' => 'page']; - parent::setUp(); - } - -} diff --git a/core/modules/comment/tests/src/Unit/Migrate/d6/CommentVariablePerCommentTypeTest.php b/core/modules/comment/tests/src/Unit/Migrate/d6/CommentVariablePerCommentTypeTest.php deleted file mode 100644 index 892319a..0000000 --- a/core/modules/comment/tests/src/Unit/Migrate/d6/CommentVariablePerCommentTypeTest.php +++ /dev/null @@ -1,59 +0,0 @@ - '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} - */ - protected function setUp() { - $this->databaseContents['node_type'] = [ - [ - 'type' => 'page', - ], - [ - 'type' => 'story', - ], - ]; - $this->databaseContents['variable'] = [ - [ - 'name' => 'comment_subject_field_page', - 'value' => serialize(1), - ], - [ - 'name' => 'comment_subject_field_story', - 'value' => serialize(0), - ], - ]; - parent::setUp(); - } - -} diff --git a/core/modules/comment/tests/src/Unit/Migrate/d6/CommentVariableTest.php b/core/modules/comment/tests/src/Unit/Migrate/d6/CommentVariableTest.php deleted file mode 100644 index 406cd11..0000000 --- a/core/modules/comment/tests/src/Unit/Migrate/d6/CommentVariableTest.php +++ /dev/null @@ -1,89 +0,0 @@ - '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} - */ - protected function setUp() { - $this->databaseContents['node_type'] = [ - [ - 'type' => 'page', - ], - ]; - $this->databaseContents['variable'] = [ - [ - 'name' => 'comment_page', - 'value' => serialize(1), - ], - [ - 'name' => 'comment_default_mode_page', - 'value' => serialize(1), - ], - [ - 'name' => 'comment_default_order_page', - 'value' => serialize(1), - ], - [ - 'name' => 'comment_default_per_page_page', - 'value' => serialize(50), - ], - [ - 'name' => 'comment_controls_page', - 'value' => serialize(1), - ], - [ - 'name' => 'comment_anonymous_page', - 'value' => serialize(1), - ], - [ - 'name' => 'comment_subject_field_page', - 'value' => serialize(1), - ], - [ - 'name' => 'comment_preview_page', - 'value' => serialize(1), - ], - [ - 'name' => 'comment_form_location_page', - 'value' => serialize(1), - ], - ]; - parent::setUp(); - } - -} diff --git a/core/modules/comment/tests/src/Unit/Migrate/d7/CommentTest.php b/core/modules/comment/tests/src/Unit/Migrate/d7/CommentTest.php deleted file mode 100644 index aed2f28..0000000 --- a/core/modules/comment/tests/src/Unit/Migrate/d7/CommentTest.php +++ /dev/null @@ -1,100 +0,0 @@ - '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} - */ - protected function setUp() { - $this->databaseContents['comment'] = $this->expectedResults; - unset($this->databaseContents['comment'][0]['comment_body']); - - $this->databaseContents['node'] = [ - [ - 'nid' => '1', - 'vid' => '1', - 'type' => 'test_content_type', - 'language' => 'en', - 'title' => 'A Node', - 'uid' => '1', - 'status' => '1', - 'created' => '1421727515', - 'changed' => '1421727515', - 'comment' => '2', - 'promote' => '1', - 'sticky' => '0', - 'tnid' => '0', - 'translate' => '0', - ], - ]; - $this->databaseContents['field_config_instance'] = [ - [ - 'id' => '14', - 'field_id' => '1', - 'field_name' => 'comment_body', - 'entity_type' => 'comment', - 'bundle' => 'comment_node_test_content_type', - 'data' => 'a:0:{}', - 'deleted' => '0', - ], - ]; - $this->databaseContents['field_data_comment_body'] = [ - [ - 'entity_type' => 'comment', - 'bundle' => 'comment_node_test_content_type', - 'deleted' => '0', - 'entity_id' => '1', - 'revision_id' => '1', - 'language' => 'und', - 'delta' => '0', - 'comment_body_value' => 'This is a comment', - 'comment_body_format' => 'filtered_html', - ], - ]; - parent::setUp(); - } - -} diff --git a/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php b/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php index 380814c..a8c66b2 100644 --- a/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php +++ b/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php @@ -274,6 +274,7 @@ protected function initializeIterator() { $high_water_field = $this->getHighWaterField(); $conditions->condition($high_water_field, $high_water, '>'); $this->query->orderBy($high_water_field); + $condition_added = TRUE; } if ($condition_added) { $this->query->condition($conditions); diff --git a/core/modules/migrate/tests/src/Kernel/MigrateSourceTestBase.php b/core/modules/migrate/tests/src/Kernel/MigrateSourceTestBase.php index e3b2f8c..7943e7c 100644 --- a/core/modules/migrate/tests/src/Kernel/MigrateSourceTestBase.php +++ b/core/modules/migrate/tests/src/Kernel/MigrateSourceTestBase.php @@ -135,21 +135,31 @@ protected function getPlugin(array $configuration) { * value (like FALSE or 'nope'), the source plugin will not be counted. * @param array $configuration * (optional) Configuration for the source plugin. + * @param mixed $high_water + * (optional) The value of the high water field. * * @dataProvider providerSource */ - public function testSource(array $source_data, array $expected_data, $expected_count = NULL, array $configuration = []) { + public function testSource(array $source_data, array $expected_data, $expected_count = NULL, array $configuration = [], $high_water = NULL) { $plugin = $this->getPlugin($configuration); // All source plugins must define IDs. $this->assertNotEmpty($plugin->getIds()); + // If there is a high water mark, set it in the high water storage. + if (isset($high_water)) { + $this->container + ->get('keyvalue') + ->get('migrate:high_water') + ->set($this->migration->reveal()->id(), $high_water); + } + if (is_null($expected_count)) { $expected_count = count($expected_data); } // If an expected count was given, assert it only if the plugin is - // countable. - if (is_numeric($expected_count)) { + // countable and there is no high water mark. + if (is_numeric($expected_count) && !isset($high_water)) { $this->assertInstanceOf('\Countable', $plugin); $this->assertCount($expected_count, $plugin); } @@ -175,6 +185,10 @@ public function testSource(array $source_data, array $expected_data, $expected_c } } } + + if (isset($high_water)) { + $this->assertSame($expected_count, $i); + } } } diff --git a/core/modules/migrate/tests/src/Kernel/MigrateSqlSourceTestBase.php b/core/modules/migrate/tests/src/Kernel/MigrateSqlSourceTestBase.php index f04183f..90187c9 100644 --- a/core/modules/migrate/tests/src/Kernel/MigrateSqlSourceTestBase.php +++ b/core/modules/migrate/tests/src/Kernel/MigrateSqlSourceTestBase.php @@ -63,12 +63,14 @@ protected function getDatabase(array $source_data) { * (optional) How many rows the source plugin is expected to return. * @param array $configuration * (optional) Configuration for the source plugin. + * @param mixed $high_water + * (optional) The value of the high water field. * * @dataProvider providerSource * * @requires extension pdo_sqlite */ - public function testSource(array $source_data, array $expected_data, $expected_count = NULL, array $configuration = []) { + public function testSource(array $source_data, array $expected_data, $expected_count = NULL, array $configuration = [], $high_water = NULL) { $plugin = $this->getPlugin($configuration); // Since we don't yet inject the database connection, we need to use a @@ -78,7 +80,7 @@ public function testSource(array $source_data, array $expected_data, $expected_c $property->setAccessible(TRUE); $property->setValue($plugin, $this->getDatabase($source_data)); - parent::testSource($source_data, $expected_data, $expected_count, $configuration); + parent::testSource($source_data, $expected_data, $expected_count, $configuration, $high_water); } }