Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
denormalizer
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
denormalizer
Commits
e0efb879
Commit
e0efb879
authored
1 year ago
by
Nia Kathoni
Committed by
Daniel Cothran
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3353532
by nikathone: Implement basic test for the module
parent
3aefbe22
No related branches found
No related tags found
1 merge request
!7
Issue #3353532: Implement basic test for the module
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
config/schema/denormalizer.schema.yml
+12
-12
12 additions, 12 deletions
config/schema/denormalizer.schema.yml
tests/src/Kernel/EntitySourceDenormalizedTableTest.php
+199
-0
199 additions, 0 deletions
tests/src/Kernel/EntitySourceDenormalizedTableTest.php
with
211 additions
and
12 deletions
config/schema/denormalizer.schema.yml
+
12
−
12
View file @
e0efb879
denormalizer.table.*
:
denormalizer.
denormalizer_
table.*
:
type
:
config_entity
label
:
'
Denormalizer
table'
mapping
:
...
...
@@ -15,7 +15,7 @@ denormalizer.table.*:
type
:
string
label
:
'
Source'
configuration
:
type
:
denormalizer.table.source.[%parent.source]
type
:
denormalizer.
denormalizer_
table.source.[%parent.source]
sql_mode
:
type
:
string
label
:
'
SQL
mode'
...
...
@@ -23,10 +23,17 @@ denormalizer.table.*:
type
:
string
label
:
'
View
prefix'
denormalizer.table.soruce.*
:
denormalizer_table_configuration
:
type
:
mapping
mapping
:
changed_key
:
type
:
string
label
:
'
Changed
key'
denormalizer.denormalizer_table.source.*
:
type
:
denormalizer_table_configuration
denormalizer.table.source.entity
:
denormalizer.
denormalizer_
table.source.entity
:
type
:
denormalizer_table_configuration
mapping
:
entity_type
:
...
...
@@ -50,7 +57,7 @@ denormalizer.table.source.entity:
sequence
:
type
:
string
denormalizer.table.source.non_entity
:
denormalizer.
denormalizer_
table.source.non_entity
:
type
:
denormalizer_table_configuration
mapping
:
base_table
:
...
...
@@ -62,10 +69,3 @@ denormalizer.table.source.non_entity:
db_prefix
:
type
:
string
label
:
'
Database
prefix'
denormalizer_table_configuration
:
type
:
mapping
mapping
:
changed_key
:
type
:
string
label
:
'
Changed
key'
This diff is collapsed.
Click to expand it.
tests/src/Kernel/EntitySourceDenormalizedTableTest.php
0 → 100644
+
199
−
0
View file @
e0efb879
<?php
namespace
Drupal\Tests\denormalizer\Kernel
;
use
Drupal\Core\Database\Connection
;
use
Drupal\denormalizer\Entity\DenormalizerTable
;
use
Drupal\denormalizer\Entity\DenormalizerTableInterface
;
use
Drupal\KernelTests\KernelTestBase
;
use
Drupal\node\Entity\NodeType
;
use
Drupal\node\NodeTypeInterface
;
/**
* Test the denormalizer table when the source is an entity.
*
* @group denormalizer
*/
class
EntitySourceDenormalizedTableTest
extends
KernelTestBase
{
/**
* Modules to enable.
*
* @var array
*/
protected
static
$modules
=
[
'user'
,
'system'
,
'field'
,
'node'
,
'text'
,
'filter'
,
'denormalizer'
,
];
/**
* The node type to test with.
*
* @var \Drupal\node\Entity\NodeType
*/
protected
NodeTypeInterface
$nodeType
;
/**
* The initialized denormalized table.
*
* @var \Drupal\denormalizer\Entity\DenormalizerTableInterface
*/
protected
DenormalizerTableInterface
$denormalizedTable
;
/**
* The database connection used.
*
* @var \Drupal\Core\Database\Connection
*/
protected
Connection
$database
;
/**
* {@inheritdoc}
*/
protected
function
setUp
():
void
{
parent
::
setUp
();
$this
->
database
=
$this
->
container
->
get
(
'database'
);
$this
->
installSchema
(
'system'
,
'sequences'
);
$this
->
installEntitySchema
(
'node'
);
$this
->
installConfig
([
'field'
,
'node'
]);
$this
->
nodeType
=
$this
->
setUpPageNodeType
();
node_add_body_field
(
$this
->
nodeType
);
$this
->
denormalizedTable
=
$this
->
setDenormalizedTable
([
'label'
=>
$this
->
nodeType
->
label
(),
'status'
=>
TRUE
,
'source'
=>
'entity'
,
'configuration'
=>
[
'entity_type'
=>
'node'
,
'bundle'
=>
$this
->
nodeType
->
id
(),
'changed_key'
=>
'changed'
,
'fields'
=>
[
'base'
=>
[
'nid'
=>
'nid'
,
'uuid'
=>
'uuid'
,
'vid'
=>
'vid'
,
'langcode'
=>
'langcode'
,
'type'
=>
'type'
,
'status'
=>
'status'
,
'uid'
=>
'uid'
,
'title'
=>
'title'
,
],
'bundle'
=>
[
'body'
=>
'body'
,
],
],
],
]);
}
/**
* Test that the stored configurations matched the expected value.
*
* @param mixed $expected
* The expected value.
* @param string $expected_key
* The expected key to retrieve stored value.
*
* @dataProvider provideTestSet
*/
public
function
testConfigurations
(
$expected
,
string
$expected_key
)
{
$this
->
assertEquals
(
$expected
,
$this
->
getStoredValueBasedOnExpectedKey
(
$expected_key
));
}
/**
* Provides the test data set for the configurations test.
*
* @return array
* The test data set.
*/
public
function
provideTestSet
():
array
{
$expected_base_fields
=
[
'nid'
=>
'nid'
,
'uuid'
=>
'uuid'
,
'vid'
=>
'vid'
,
'langcode'
=>
'langcode'
,
'type'
=>
'type'
,
'status'
=>
'status'
,
'uid'
=>
'uid'
,
'title'
=>
'title'
,
];
$expected_bundle_fields
=
[
'body'
=>
'body'
];
return
[
'Configuration label'
=>
[
'Page'
,
'label'
],
'Table name'
=>
[
'denormalizer_page'
,
'table_name'
],
'Is enabled'
=>
[
TRUE
,
'status'
],
'Source configuration entity type id'
=>
[
'node'
,
'source_configuration_entity_type'
],
'Source configuration bundle'
=>
[
'page'
,
'source_configuration_bundle'
],
'Source configuration bundle fields'
=>
[
$expected_bundle_fields
,
'source_configuration_fields_bundle'
],
'Source configuration base fields'
=>
[
$expected_base_fields
,
'source_configuration_fields_base'
],
];
}
/**
* Sets up the page node type.
*
* @return \Drupal\node\NodeTypeInterface
* The node type.
*
* @throws \Drupal\Core\Entity\EntityStorageException
*/
protected
function
setUpPageNodeType
():
NodeTypeInterface
{
$node_type
=
NodeType
::
create
([
'type'
=>
'page'
,
'name'
=>
'Page'
,
]);
$node_type
->
save
();
return
$node_type
;
}
/**
* Sets the denormalized table.
*
* @param array $settings
* The settings.
*
* @return \Drupal\denormalizer\Entity\DenormalizerTableInterface
* The set denormalized table config entity.
*
* @throws \Drupal\Core\Entity\EntityStorageException
*/
protected
function
setDenormalizedTable
(
array
$settings
):
DenormalizerTableInterface
{
$denormalizer_table
=
DenormalizerTable
::
create
(
$settings
+
[
'id'
=>
$this
->
nodeType
->
id
(),
]);
$denormalizer_table
->
save
();
return
$denormalizer_table
;
}
/**
* Gets the stored value based on the expected key.
*
* @param string $expected_key
* The expected key use to retrieve the value.
*
* @return mixed
* The stored value.
*/
protected
function
getStoredValueBasedOnExpectedKey
(
string
$expected_key
)
{
$source_configurations
=
$this
->
denormalizedTable
->
getSourceConfiguration
();
return
match
(
$expected_key
)
{
'label'
=>
$this
->
denormalizedTable
->
label
(),
'table_name'
=>
$this
->
denormalizedTable
->
getDbTableName
(),
'status'
=>
$this
->
denormalizedTable
->
status
(),
'source_configuration_entity_type'
=>
$source_configurations
[
'entity_type'
],
'source_configuration_bundle'
=>
$source_configurations
[
'bundle'
],
'source_configuration_fields_bundle'
=>
$source_configurations
[
'fields'
][
'bundle'
],
'source_configuration_fields_base'
=>
$source_configurations
[
'fields'
][
'base'
],
default
=>
''
,
};
}
}
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