Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
violinist_teams
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
violinist_teams
Commits
d5877d47
Commit
d5877d47
authored
8 months ago
by
Eirik Morland
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3452117
by eiriksm: Use a trait for setting up fields for Kernel tests for easier reuse
parent
313338fb
No related branches found
No related tags found
1 merge request
!61
Add the trait and use it
Pipeline
#189566
passed with warnings
8 months ago
Stage: build
Stage: validate
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/src/Kernel/KernelTestBase.php
+3
-58
3 additions, 58 deletions
tests/src/Kernel/KernelTestBase.php
tests/src/Kernel/TeamFieldKernelSetupTrait.php
+100
-0
100 additions, 0 deletions
tests/src/Kernel/TeamFieldKernelSetupTrait.php
with
103 additions
and
58 deletions
tests/src/Kernel/KernelTestBase.php
+
3
−
58
View file @
d5877d47
...
...
@@ -13,6 +13,8 @@ use Drupal\violinist_teams\TeamNode;
*/
abstract
class
KernelTestBase
extends
CoreKernelTestBase
{
use
TeamFieldKernelSetupTrait
;
/**
* Node type.
*
...
...
@@ -46,65 +48,8 @@ abstract class KernelTestBase extends CoreKernelTestBase {
$this
->
installEntitySchema
(
'user'
);
$this
->
installEntitySchema
(
'node'
);
$this
->
installConfig
(
static
::
$modules
);
// Create the field for holding members.
$fieldStorage
=
FieldStorageConfig
::
create
([
'field_name'
=>
'field_team_members'
,
'entity_type'
=>
'node'
,
'type'
=>
'entity_reference'
,
'cardinality'
=>
-
1
,
'settings'
=>
[
'target_type'
=>
'user'
,
],
]);
$fieldStorage
->
save
();
$field
=
FieldConfig
::
create
([
'field_storage'
=>
$fieldStorage
,
'bundle'
=>
$this
->
nodeType
->
id
(),
'field_type'
=>
'entity_reference'
,
'required'
=>
FALSE
,
'settings'
=>
[
[
'handler'
=>
'default:user'
],
],
]);
$field
->
save
();
// Create the field for holding admins.
$fieldStorage
=
FieldStorageConfig
::
create
([
'field_name'
=>
'field_team_admins'
,
'entity_type'
=>
'node'
,
'type'
=>
'entity_reference'
,
'cardinality'
=>
-
1
,
'settings'
=>
[
'target_type'
=>
'user'
,
],
]);
$fieldStorage
->
save
();
$field
=
FieldConfig
::
create
([
'field_storage'
=>
$fieldStorage
,
'bundle'
=>
$this
->
nodeType
->
id
(),
'field_type'
=>
'entity_reference'
,
'required'
=>
FALSE
,
'settings'
=>
[
[
'handler'
=>
'default:user'
],
],
]);
$field
->
save
();
// The field we use for notifications.
$fieldStorage
=
FieldStorageConfig
::
create
([
'field_name'
=>
'field_team_notification_emails'
,
'entity_type'
=>
'node'
,
'type'
=>
'string_long'
,
'cardinality'
=>
1
,
]);
$fieldStorage
->
save
();
$field
=
FieldConfig
::
create
([
'field_storage'
=>
$fieldStorage
,
'bundle'
=>
$this
->
nodeType
->
id
(),
'field_type'
=>
'string_long'
,
'required'
=>
FALSE
,
]);
$field
->
save
();
$this
->
createTeamFields
();
// The field we use for max concurrent notifications.
$fieldStorage
=
FieldStorageConfig
::
create
([
...
...
This diff is collapsed.
Click to expand it.
tests/src/Kernel/TeamFieldKernelSetupTrait.php
0 → 100644
+
100
−
0
View file @
d5877d47
<?php
namespace
Drupal\Tests\violinist_teams\Kernel
;
use
Drupal\field\Entity\FieldConfig
;
use
Drupal\field\Entity\FieldStorageConfig
;
use
Drupal\violinist_teams
\TeamNode
;
/**
* A trait for setting up team fields.
*/
trait
TeamFieldKernelSetupTrait
{
/**
* Create fields we need on the team content type.
*/
public
function
createTeamFields
()
{
// The field we use for notifications.
$fieldStorage
=
FieldStorageConfig
::
create
([
'field_name'
=>
'field_team_notification_emails'
,
'entity_type'
=>
'node'
,
'type'
=>
'string_long'
,
'cardinality'
=>
1
,
]);
$fieldStorage
->
save
();
$field
=
FieldConfig
::
create
([
'field_storage'
=>
$fieldStorage
,
'bundle'
=>
TeamNode
::
NODE_TYPE
,
'field_type'
=>
'string_long'
,
'required'
=>
FALSE
,
]);
$field
->
save
();
// Create the field for holding members.
$fieldStorage
=
FieldStorageConfig
::
create
([
'field_name'
=>
'field_team_members'
,
'entity_type'
=>
'node'
,
'type'
=>
'entity_reference'
,
'cardinality'
=>
-
1
,
'settings'
=>
[
'target_type'
=>
'user'
,
],
]);
$fieldStorage
->
save
();
$field
=
FieldConfig
::
create
([
'field_storage'
=>
$fieldStorage
,
'bundle'
=>
TeamNode
::
NODE_TYPE
,
'field_type'
=>
'entity_reference'
,
'required'
=>
FALSE
,
'settings'
=>
[
[
'handler'
=>
'default:user'
],
],
]);
$field
->
save
();
// Create the field for holding admins.
$fieldStorage
=
FieldStorageConfig
::
create
([
'field_name'
=>
'field_team_admins'
,
'entity_type'
=>
'node'
,
'type'
=>
'entity_reference'
,
'cardinality'
=>
-
1
,
'settings'
=>
[
'target_type'
=>
'user'
,
],
]);
$fieldStorage
->
save
();
$field
=
FieldConfig
::
create
([
'field_storage'
=>
$fieldStorage
,
'bundle'
=>
TeamNode
::
NODE_TYPE
,
'field_type'
=>
'entity_reference'
,
'required'
=>
FALSE
,
'settings'
=>
[
[
'handler'
=>
'default:user'
],
],
]);
$field
->
save
();
// Slack notifications.
$fieldStorage
=
FieldStorageConfig
::
create
([
'field_name'
=>
TeamNode
::
NOTIFICATION_ENABLED_FIELD
,
'entity_type'
=>
'node'
,
'type'
=>
'boolean'
,
'cardinality'
=>
1
,
]);
$fieldStorage
->
save
();
$field
=
FieldConfig
::
create
([
'field_storage'
=>
$fieldStorage
,
'bundle'
=>
TeamNode
::
NODE_TYPE
,
'field_type'
=>
'boolean'
,
'required'
=>
FALSE
,
'default_value'
=>
[
[
'value'
=>
0
,
],
],
]);
$field
->
save
();
}
}
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