Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
426c9fd3
Commit
426c9fd3
authored
Jul 19, 2016
by
Alex Pott
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2561049
by phenaproxima, quietone: Add proper unit tests for the Migration process plugin
parent
2d292cd1
No related branches found
No related tags found
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/modules/migrate/src/Plugin/migrate/process/Migration.php
+2
-2
2 additions, 2 deletions
.../modules/migrate/src/Plugin/migrate/process/Migration.php
core/modules/migrate/tests/src/Unit/process/MigrationTest.php
+48
-0
48 additions, 0 deletions
.../modules/migrate/tests/src/Unit/process/MigrationTest.php
with
50 additions
and
2 deletions
core/modules/migrate/src/Plugin/migrate/process/Migration.php
+
2
−
2
View file @
426c9fd3
...
@@ -93,7 +93,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
...
@@ -93,7 +93,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
$source_id_values
[
$migration_id
]
=
$value
;
$source_id_values
[
$migration_id
]
=
$value
;
}
}
// Break out of the loop as soon as a destination ID is found.
// Break out of the loop as soon as a destination ID is found.
if
(
$destination_ids
=
$migration
->
getIdMap
()
->
lookupDestinationI
D
(
$source_id_values
[
$migration_id
]))
{
if
(
$destination_ids
=
$migration
->
getIdMap
()
->
lookupDestinationI
d
(
$source_id_values
[
$migration_id
]))
{
break
;
break
;
}
}
}
}
...
@@ -162,7 +162,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
...
@@ -162,7 +162,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
*
*
* @throws \Drupal\migrate\MigrateSkipProcessException
* @throws \Drupal\migrate\MigrateSkipProcessException
*/
*/
protected
function
skipOnEmpty
(
$value
)
{
protected
function
skipOnEmpty
(
array
$value
)
{
if
(
!
array_filter
(
$value
))
{
if
(
!
array_filter
(
$value
))
{
throw
new
MigrateSkipProcessException
();
throw
new
MigrateSkipProcessException
();
}
}
...
...
This diff is collapsed.
Click to expand it.
core/modules/migrate/tests/src/Unit/process/MigrationTest.php
+
48
−
0
View file @
426c9fd3
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
Drupal\Tests\migrate\Unit\process
;
namespace
Drupal\Tests\migrate\Unit\process
;
use
Drupal\Core\Entity\EntityStorageInterface
;
use
Drupal\migrate\Plugin\MigrationInterface
;
use
Drupal\migrate\Plugin\MigrationInterface
;
use
Drupal\migrate\Plugin\migrate\process\Migration
;
use
Drupal\migrate\Plugin\migrate\process\Migration
;
use
Drupal\migrate\Plugin\MigrateDestinationInterface
;
use
Drupal\migrate\Plugin\MigrateDestinationInterface
;
...
@@ -86,4 +87,51 @@ public function testTransformWithStubbing() {
...
@@ -86,4 +87,51 @@ public function testTransformWithStubbing() {
$this
->
assertEquals
(
2
,
$result
);
$this
->
assertEquals
(
2
,
$result
);
}
}
/**
* Tests that processing is skipped when the input value is empty.
*
* @expectedException \Drupal\migrate\MigrateSkipProcessException
*/
public
function
testSkipOnEmpty
()
{
$migration_plugin
=
$this
->
prophesize
(
MigrationInterface
::
class
);
$migration_plugin_manager
=
$this
->
prophesize
(
MigrationPluginManagerInterface
::
class
);
$process_plugin_manager
=
$this
->
prophesize
(
MigratePluginManager
::
class
);
$configuration
=
[
'migration'
=>
'foobaz'
,
];
$migration_plugin
->
id
()
->
willReturn
(
uniqid
());
$migration
=
new
Migration
(
$configuration
,
'migration'
,
[],
$migration_plugin
->
reveal
(),
$migration_plugin_manager
->
reveal
(),
$process_plugin_manager
->
reveal
());
$migration
->
transform
(
0
,
$this
->
migrateExecutable
,
$this
->
row
,
'foo'
);
}
/**
* Tests a successful lookup.
*/
public
function
testSuccessfulLookup
()
{
$migration_plugin
=
$this
->
prophesize
(
MigrationInterface
::
class
);
$migration_plugin_manager
=
$this
->
prophesize
(
MigrationPluginManagerInterface
::
class
);
$process_plugin_manager
=
$this
->
prophesize
(
MigratePluginManager
::
class
);
$configuration
=
[
'migration'
=>
'foobaz'
,
];
$migration_plugin
->
id
()
->
willReturn
(
uniqid
());
$id_map
=
$this
->
prophesize
(
MigrateIdMapInterface
::
class
);
$id_map
->
lookupDestinationId
([
1
])
->
willReturn
([
3
]);
$migration_plugin
->
getIdMap
()
->
willReturn
(
$id_map
->
reveal
());
$migration_plugin_manager
->
createInstances
([
'foobaz'
])
->
willReturn
([
'foobaz'
=>
$migration_plugin
->
reveal
()]);
$migrationStorage
=
$this
->
prophesize
(
EntityStorageInterface
::
class
);
$migrationStorage
->
loadMultiple
([
'foobaz'
])
->
willReturn
([
$migration_plugin
->
reveal
()]);
$migration
=
new
Migration
(
$configuration
,
'migration'
,
[],
$migration_plugin
->
reveal
(),
$migration_plugin_manager
->
reveal
(),
$process_plugin_manager
->
reveal
());
$this
->
assertSame
(
3
,
$migration
->
transform
(
1
,
$this
->
migrateExecutable
,
$this
->
row
,
'foo'
));
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment