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
b725d20e
Commit
b725d20e
authored
1 year ago
by
Eirik Morland
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3414657
by eiriksm: Add method for getting environment variables
parent
a48dd6cd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!26
Add method and tests
Pipeline
#77294
passed
1 year 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
+44
-0
44 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
+62
-0
62 additions, 0 deletions
tests/src/Kernel/TeamNodeTest.php
with
122 additions
and
0 deletions
src/TeamNode.php
+
44
−
0
View file @
b725d20e
...
...
@@ -19,6 +19,50 @@ class TeamNode extends Node {
const
BILLING_ENABLED_FIELD
=
'field_send_receipts'
;
const
BILLING_EMAIL_FIELD
=
'field_billing_email'
;
/**
* Get the env variables.
*
* Returns an array of env variables, with the key being the name of the
* variable, and the value being the value. This, despite the fact that it is
* stored as a single textfield, which in theory would make the user able to
* override their own variables within the same form. This would then be
* considered a feature.
*/
public
function
getEnvironmentVariables
()
:
array
{
$variables
=
[];
if
(
!
$this
->
hasField
(
'field_environment_variables'
)
||
$this
->
get
(
'field_environment_variables'
)
->
isEmpty
())
{
return
$variables
;
}
$variables_string
=
$this
->
get
(
'field_environment_variables'
)
->
first
()
->
getString
();
$variables_string
=
trim
(
$variables_string
);
if
(
!
$variables_string
)
{
return
$variables
;
}
$variables_array
=
preg_split
(
'/\r\n|\r|\n/'
,
$variables_string
);
foreach
(
$variables_array
as
$variable
)
{
$variable
=
trim
(
$variable
);
if
(
!
$variable
)
{
continue
;
}
$variable_parts
=
explode
(
'='
,
$variable
);
if
(
count
(
$variable_parts
)
<
2
)
{
// Not really looking like a good env var.
continue
;
}
$key
=
trim
(
$variable_parts
[
0
]);
$value
=
trim
(
$variable_parts
[
1
]);
if
(
count
(
$variable_parts
)
!==
2
)
{
// Join all the others so that the value can in fact contain an =.
array_shift
(
$variable_parts
);
$variable_parts
=
array_map
(
'trim'
,
$variable_parts
);
$value
=
implode
(
'='
,
$variable_parts
);
}
$variables
[
$key
]
=
$value
;
}
$variables
=
array_filter
(
$variables
);
return
$variables
;
}
/**
* Currently this is only one email, but we return an array for consistency.
*
...
...
This diff is collapsed.
Click to expand it.
tests/src/Kernel/KernelTestBase.php
+
16
−
0
View file @
b725d20e
...
...
@@ -104,6 +104,22 @@ abstract class KernelTestBase extends CoreKernelTestBase {
]);
$field
->
save
();
// The field we use for env vars.
$fieldStorage
=
FieldStorageConfig
::
create
([
'field_name'
=>
'field_environment_variables'
,
'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
();
// Slack notifications.
$fieldStorage
=
FieldStorageConfig
::
create
([
'field_name'
=>
'field_slack_notifications'
,
...
...
This diff is collapsed.
Click to expand it.
tests/src/Kernel/TeamNodeTest.php
+
62
−
0
View file @
b725d20e
...
...
@@ -102,6 +102,68 @@ class TeamNodeTest extends KernelTestBase {
self
::
assertEquals
(
$expected_result
,
$node
->
getBillingEmails
());
}
/**
* Test the environment variables.
*
* @dataProvider getEnvironmentVariables
*/
public
function
testGetEnvironmentVariables
(
$variable_value
,
$expected_result
)
{
/** @var \Drupal\violinist_teams\TeamNode $node */
$node
=
Node
::
create
([
'type'
=>
$this
->
nodeType
->
id
(),
]);
$node
->
set
(
'field_environment_variables'
,
$variable_value
);
self
::
assertEquals
(
$expected_result
,
$node
->
getEnvironmentVariables
());
}
/**
* Dataprovider for environment variables.
*/
public
function
getEnvironmentVariables
()
:
array
{
return
[
[
'FOO=bar'
,
[
'FOO'
=>
'bar'
],
],
[
'FOO=bar
FOO=baz'
,
[
'FOO'
=>
'baz'
],
],
[
'FOO=bar
FOO=baz
FOO='
,
[],
],
[
'FOO=
'
,
[],
],
[
NULL
,
[],
],
[
''
,
[],
],
[
'random_string = no value'
,
[
'random_string'
=>
'no value'
],
],
[
'something stupid'
,
[],
],
[
'TEST=maybe_some_key_containing_the_equals_sign6622¤¤==!'
,
[
'TEST'
=>
'maybe_some_key_containing_the_equals_sign6622¤¤==!'
],
],
];
}
/**
* Data provider for billing and billing email test.
*/
...
...
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