Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
single_content_sync
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
single_content_sync
Commits
3c385464
Commit
3c385464
authored
1 year ago
by
Vadym Abramchuk
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3400982
: Simple field processor plugin import test
parent
ccb31df4
No related branches found
No related tags found
1 merge request
!80
Resolve #3400982 "Field processor plugins"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/src/Kernel/FieldProcessor/FieldProcessorTestBase.php
+74
-6
74 additions, 6 deletions
tests/src/Kernel/FieldProcessor/FieldProcessorTestBase.php
tests/src/Kernel/FieldProcessor/SimpleFieldProcessorTest.php
+20
-0
20 additions, 0 deletions
tests/src/Kernel/FieldProcessor/SimpleFieldProcessorTest.php
with
94 additions
and
6 deletions
tests/src/Kernel/FieldProcessor/FieldProcessorTestBase.php
+
74
−
6
View file @
3c385464
...
...
@@ -44,7 +44,7 @@ abstract class FieldProcessorTestBase extends KernelTestBase {
}
/**
* Returns an array of test data.
* Returns an array of
export
test data.
*
* Each array row is a single test case; rows are keyed by a human-readable
* label.
...
...
@@ -64,7 +64,7 @@ abstract class FieldProcessorTestBase extends KernelTestBase {
public
function
testExportFieldValue
(
array
$fieldStorageDefinition
,
mixed
$fieldValue
,
mixed
$expectedExportOutput
,
array
$expectedExportOutput
):
void
{
$this
->
prepareNodeTypeWithField
(
$fieldStorageDefinition
);
...
...
@@ -76,10 +76,48 @@ abstract class FieldProcessorTestBase extends KernelTestBase {
$node
->
save
();
$this
->
assertEquals
(
$expectedExportOutput
,
$this
->
getFieldProcessor
()
->
exportFieldValue
(
$node
->
get
(
'field_test_field'
))
);
$this
->
assertExportedValueEquals
(
$expectedExportOutput
,
$this
->
getFieldProcessor
()
->
exportFieldValue
(
$node
->
get
(
'field_test_field'
)),
);
}
/**
* Returns an array of import test data.
*
* Each array row is a single test case; rows are keyed by a human-readable
* label.
*
* Each row is an array with the following elements: field storage definition,
* data to import, expected field value.
*
* @return array
* An array of test data.
*/
abstract
protected
function
importFieldValueDataProvider
():
array
;
/**
* @covers ::importFieldValue
* @dataProvider importFieldValueDataProvider
*/
public
function
testImportFieldValue
(
array
$fieldStorageDefinition
,
mixed
$dataToImport
,
mixed
$expectedFieldValue
,
):
void
{
$this
->
prepareNodeTypeWithField
(
$fieldStorageDefinition
);
$node
=
Node
::
create
([
'type'
=>
'article'
,
'title'
=>
'Test node'
,
]);
$this
->
getFieldProcessor
()
->
importFieldValue
(
$node
,
'field_test_field'
,
$dataToImport
);
$this
->
assertImportedValueEquals
(
$expectedFieldValue
,
$node
->
get
(
'field_test_field'
)
->
getValue
(),
);
}
/**
...
...
@@ -115,4 +153,34 @@ abstract class FieldProcessorTestBase extends KernelTestBase {
])
->
save
();
}
/**
* Asserts equality of exported value.
*
* This method could be overridden in child classes to provide custom
* comparison logic.
*
* @param mixed $expectedExportOutput
* The expected export output.
* @param array $actualExportOutput
* The actual export output.
*/
protected
function
assertExportedValueEquals
(
mixed
$expectedExportOutput
,
array
$actualExportOutput
)
{
$this
->
assertEquals
(
$expectedExportOutput
,
$actualExportOutput
);
}
/**
* Asserts equality of imported value.
*
* This method could be overridden in child classes to provide custom
* comparison logic.
*
* @param mixed $expectedFieldValue
* The expected field value.
* @param mixed $actualImportedFieldValue
* The actual imported field value.
*/
protected
function
assertImportedValueEquals
(
mixed
$expectedFieldValue
,
mixed
$actualImportedFieldValue
):
void
{
$this
->
assertEquals
(
$expectedFieldValue
,
$actualImportedFieldValue
);
}
}
This diff is collapsed.
Click to expand it.
tests/src/Kernel/FieldProcessor/SimpleFieldProcessorTest.php
+
20
−
0
View file @
3c385464
...
...
@@ -4,9 +4,29 @@ namespace Drupal\Tests\single_content_sync\Kernel\FieldProcessor;
/**
* @coversDefaultClass \Drupal\single_content_sync\Plugin\SingleContentSyncFieldProcessor\SimpleField
*
* @todo add test cases for all field types described in SimpleFieldDeriver.
*/
class
SimpleFieldProcessorTest
extends
FieldProcessorTestBase
{
/**
* {@inheritdoc}
*/
protected
function
importFieldValueDataProvider
():
array
{
return
[
'string'
=>
[
[
'type'
=>
'string'
,
'settings'
=>
[
'max_length'
=>
255
,
],
],
[
0
=>
[
'value'
=>
'hello'
]],
[
0
=>
[
'value'
=>
'hello'
]],
],
];
}
/**
* {@inheritdoc}
*/
...
...
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