Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
426c9fd3
Commit
426c9fd3
authored
Jul 19, 2016
by
alexpott
Browse files
Issue
#2561049
by phenaproxima, quietone: Add proper unit tests for the Migration process plugin
parent
2d292cd1
Changes
2
Hide whitespace changes
Inline
Side-by-side
core/modules/migrate/src/Plugin/migrate/process/Migration.php
View file @
426c9fd3
...
...
@@ -93,7 +93,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
$source_id_values
[
$migration_id
]
=
$value
;
}
// 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
;
}
}
...
...
@@ -162,7 +162,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
*
* @throws \Drupal\migrate\MigrateSkipProcessException
*/
protected
function
skipOnEmpty
(
$value
)
{
protected
function
skipOnEmpty
(
array
$value
)
{
if
(
!
array_filter
(
$value
))
{
throw
new
MigrateSkipProcessException
();
}
...
...
core/modules/migrate/tests/src/Unit/process/MigrationTest.php
View file @
426c9fd3
...
...
@@ -2,6 +2,7 @@
namespace
Drupal\Tests\migrate\Unit\process
;
use
Drupal\Core\Entity\EntityStorageInterface
;
use
Drupal\migrate\Plugin\MigrationInterface
;
use
Drupal\migrate\Plugin\migrate\process\Migration
;
use
Drupal\migrate\Plugin\MigrateDestinationInterface
;
...
...
@@ -86,4 +87,51 @@ public function testTransformWithStubbing() {
$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'
));
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment