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
4c279d0f
Commit
4c279d0f
authored
1 year ago
by
Eirik Morland
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3345896
: Add method to create a team (with optional member)
parent
66791fa0
No related branches found
No related tags found
1 merge request
!7
Issue #3345896: Add method to create a team (with optional member)
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/TeamManager.php
+17
-0
17 additions, 0 deletions
src/TeamManager.php
tests/src/Kernel/TeamManagerTest.php
+20
-0
20 additions, 0 deletions
tests/src/Kernel/TeamManagerTest.php
with
37 additions
and
0 deletions
src/TeamManager.php
+
17
−
0
View file @
4c279d0f
...
...
@@ -45,6 +45,23 @@ class TeamManager {
return
$node_storage
->
loadMultiple
(
$nids
);
}
/**
* Create a team, optionally with the first member of the team.
*/
public
function
createTeam
(
string
$name
,
UserInterface
$user
=
NULL
)
:
TeamNode
{
/** @var \Drupal\violinist_teams\TeamNode $team */
$team
=
$this
->
entityTypeManager
->
getStorage
(
'node'
)
->
create
([
'type'
=>
TeamNode
::
NODE_TYPE
,
'title'
=>
$name
,
]);
if
(
$user
)
{
$team
->
appendMember
(
$user
);
}
$team
->
save
();
return
$team
;
}
/**
* Handles user deletions.
*/
...
...
This diff is collapsed.
Click to expand it.
tests/src/Kernel/TeamManagerTest.php
+
20
−
0
View file @
4c279d0f
...
...
@@ -4,6 +4,7 @@ namespace Drupal\Tests\violinist_teams\Kernel;
use
Drupal\node\Entity\Node
;
use
Drupal\user\Entity\User
;
use
Drupal\violinist_teams
\TeamNode
;
/**
* Tests for the team manager.
...
...
@@ -91,7 +92,26 @@ class TeamManagerTest extends KernelTestBase {
'type'
=>
$this
->
nodeType
->
id
(),
]);
self
::
assertCount
(
1
,
$nodes
);
}
/**
* Test the creation of teams with the manager.
*/
public
function
testCreateTeam
()
{
$user
=
User
::
create
([
'name'
=>
'test1'
,
'mail'
=>
'test1@example.com'
,
]);
$user
->
save
();
// Let's create a team from this user.
$team
=
$this
->
teamManager
->
createTeam
(
'my team'
,
$user
);
self
::
assertInstanceOf
(
TeamNode
::
class
,
$team
);
self
::
assertCount
(
1
,
$team
->
getMembers
());
self
::
assertEquals
([
$user
->
id
()],
$team
->
getMemberIds
());
// Also create a team with no user, that should totally be allowed.
$team
=
$this
->
teamManager
->
createTeam
(
'my team'
);
self
::
assertInstanceOf
(
TeamNode
::
class
,
$team
);
self
::
assertCount
(
0
,
$team
->
getMembers
());
}
}
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