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
d5140e33
Commit
d5140e33
authored
1 year ago
by
Eirik Morland
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3412567
by eiriksm: Add method for getting the team notification emails
parent
d17d5b53
No related branches found
No related tags found
1 merge request
!22
Resolve #3412567 "Add method for"
Pipeline
#72324
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
+21
-0
21 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
+34
-0
34 additions, 0 deletions
tests/src/Kernel/TeamNodeTest.php
with
71 additions
and
0 deletions
src/TeamNode.php
+
21
−
0
View file @
d5140e33
...
...
@@ -16,6 +16,27 @@ class TeamNode extends Node {
const
PLAN_FIELD
=
'field_plan'
;
const
PROJECT_LIMIT_FIELD
=
'field_project_limit'
;
/**
* Get the emails from the field.
*/
public
function
getNotificationEmails
()
{
$mails
=
[];
if
(
!
$this
->
hasField
(
'field_team_notification_emails'
)
||
$this
->
get
(
'field_team_notification_emails'
)
->
isEmpty
())
{
return
$mails
;
}
$mails_string
=
$this
->
get
(
'field_team_notification_emails'
)
->
first
()
->
getString
();
return
self
::
createMailArrayFromString
(
$mails_string
);
}
/**
* Helper to make sure we only get somehow valid strings at least.
*/
protected
static
function
createMailArrayFromString
(
string
$mails_string
)
:
array
{
$mails
=
explode
(
"
\n
"
,
$mails_string
);
$mails
=
array_map
(
'trim'
,
$mails
);
return
array_filter
(
$mails
);
}
/**
* Get the max private repos a team can have, based on the field value.
*/
...
...
This diff is collapsed.
Click to expand it.
tests/src/Kernel/KernelTestBase.php
+
16
−
0
View file @
d5140e33
...
...
@@ -87,6 +87,22 @@ abstract class KernelTestBase extends CoreKernelTestBase {
],
]);
$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
->
installSchema
(
'user'
,
[
'users_data'
]);
}
...
...
This diff is collapsed.
Click to expand it.
tests/src/Kernel/TeamNodeTest.php
+
34
−
0
View file @
d5140e33
...
...
@@ -59,4 +59,38 @@ class TeamNodeTest extends KernelTestBase {
self
::
assertEquals
([
$user
->
id
()],
$node
->
getAdministratorIds
());
}
/**
* Test the notification variations.
*
* @dataProvider notificationProvider
*/
public
function
testGetNotifications
(
string
$field_value
,
array
$expexted
)
{
/** @var \Drupal\violinist_teams\TeamNode $node */
$node
=
Node
::
create
([
'type'
=>
$this
->
nodeType
->
id
(),
]);
$node
->
set
(
'field_team_notification_emails'
,
$field_value
);
self
::
assertEquals
(
$expexted
,
$node
->
getNotificationEmails
());
}
/**
* Data provider for mail notification thing.
*/
public
function
notificationProvider
()
{
return
[
[
'test@test.com'
,
[
'test@test.com'
],
],
[
' test@test.com '
,
[
'test@test.com'
],
],
[
"test@test.com
\n
testtest@test.com "
,
[
'test@test.com'
,
'testtest@test.com'
],
],
];
}
}
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