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
1e743c6c
Commit
1e743c6c
authored
1 month ago
by
Eirik Morland
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3497907
by eiriksm: Make it possible to add and retrieve licences
parent
aeaacfa3
No related branches found
No related tags found
1 merge request
!76
Initial
Pipeline
#388842
passed with warnings
1 month ago
Stage: build
Stage: validate
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/TeamNode.php
+20
-0
20 additions, 0 deletions
src/TeamNode.php
tests/src/Kernel/KernelTestBase.php
+16
-0
16 additions, 0 deletions
tests/src/Kernel/KernelTestBase.php
tests/src/Kernel/TeamNodeTest.php
+19
-0
19 additions, 0 deletions
tests/src/Kernel/TeamNodeTest.php
with
55 additions
and
0 deletions
src/TeamNode.php
+
20
−
0
View file @
1e743c6c
...
...
@@ -468,4 +468,24 @@ class TeamNode extends Node {
return
$this
;
}
/**
* Add a licence to the team.
*/
public
function
addLicence
(
string
$licence
)
{
$this
->
get
(
'field_licences'
)
->
appendItem
(
$licence
);
return
$this
;
}
/**
* Get the actual licences a team has saved.
*/
public
function
getLicences
()
:
array
{
if
(
!
$this
->
hasField
(
'field_licences'
)
||
$this
->
get
(
'field_licences'
)
->
isEmpty
())
{
return
[];
}
return
array_map
(
function
(
$item
)
{
return
$item
[
'value'
];
},
$this
->
get
(
'field_licences'
)
->
getValue
());
}
}
This diff is collapsed.
Click to expand it.
tests/src/Kernel/KernelTestBase.php
+
16
−
0
View file @
1e743c6c
...
...
@@ -67,6 +67,22 @@ abstract class KernelTestBase extends CoreKernelTestBase {
]);
$field
->
save
();
// Licences.
$fieldStorage
=
FieldStorageConfig
::
create
([
'field_name'
=>
'field_licences'
,
'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
();
// The field we use for env vars.
$fieldStorage
=
FieldStorageConfig
::
create
([
'field_name'
=>
'field_environment_variables'
,
...
...
This diff is collapsed.
Click to expand it.
tests/src/Kernel/TeamNodeTest.php
+
19
−
0
View file @
1e743c6c
...
...
@@ -262,6 +262,25 @@ class TeamNodeTest extends KernelTestBase {
self
::
assertEquals
(
3
,
$node
->
getPlan
()
->
getMaxPrivateRepos
());
}
/**
* Test the licence things.
*/
public
function
testLicences
()
{
/** @var \Drupal\violinist_teams\TeamNode $node */
$node
=
Node
::
create
([
'type'
=>
$this
->
nodeType
->
id
(),
]);
$node
->
addLicence
(
'test'
);
self
::
assertEquals
([
'test'
],
$node
->
getLicences
());
// Now add another one, and make sure its there.
$node
->
addLicence
(
'test2'
);
self
::
assertEquals
([
'test'
,
'test2'
],
$node
->
getLicences
());
// Now overwrite it.
$node
->
set
(
'field_licences'
,
[]);
$node
->
addLicence
(
'test3'
);
self
::
assertEquals
([
'test3'
],
$node
->
getLicences
());
}
/**
* Dataprovider for environment variables.
*/
...
...
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