Skip to content
Snippets Groups Projects
Commit 40ac9e18 authored by Eirik Morland's avatar Eirik Morland
Browse files

Issue #3414608: Add method for getting the team slack notification status

parent d5140e33
No related branches found
No related tags found
1 merge request!23Add the method
Pipeline #77029 passed
......@@ -15,6 +15,18 @@ class TeamNode extends Node {
const ADMIN_FIELD = 'field_team_admins';
const PLAN_FIELD = 'field_plan';
const PROJECT_LIMIT_FIELD = 'field_project_limit';
const SLACK_NOTIFICATION_ENABLED_FIELD = 'field_slack_notifications';
/**
* Are those slack notifications enabled, globally, for the team?
*/
public function isNotificationsEnabledForSlack() : bool {
if (!$this->hasField(self::SLACK_NOTIFICATION_ENABLED_FIELD) || $this->get(self::SLACK_NOTIFICATION_ENABLED_FIELD)->isEmpty()) {
// No way to see what sort of settings they have.
return FALSE;
}
return (bool) $this->get(self::SLACK_NOTIFICATION_ENABLED_FIELD)->first()->getString();
}
/**
* Get the emails from the field.
......
......@@ -103,6 +103,27 @@ abstract class KernelTestBase extends CoreKernelTestBase {
'required' => FALSE,
]);
$field->save();
// Slack notifications.
$fieldStorage = FieldStorageConfig::create([
'field_name' => 'field_slack_notifications',
'entity_type' => 'node',
'type' => 'boolean',
'cardinality' => 1,
]);
$fieldStorage->save();
$field = FieldConfig::create([
'field_storage' => $fieldStorage,
'bundle' => $this->nodeType->id(),
'field_type' => 'boolean',
'required' => FALSE,
'default_value' => [
[
'value' => 0,
],
],
]);
$field->save();
$this->installSchema('user', ['users_data']);
}
......
......@@ -73,6 +73,20 @@ class TeamNodeTest extends KernelTestBase {
self::assertEquals($expexted, $node->getNotificationEmails());
}
/**
* Test the notification variations.
*
* @dataProvider slackNotificationProvider
*/
public function testGetSlackNotifications($field_value, bool $expexted) {
/** @var \Drupal\violinist_teams\TeamNode $node */
$node = Node::create([
'type' => $this->nodeType->id(),
]);
$node->set('field_slack_notifications', $field_value);
self::assertEquals($expexted, $node->isNotificationsEnabledForSlack());
}
/**
* Data provider for mail notification thing.
*/
......@@ -93,4 +107,28 @@ class TeamNodeTest extends KernelTestBase {
];
}
/**
* Data provider for slack notification thing.
*/
public function slackNotificationProvider() {
return [
[
NULL,
FALSE,
],
[
FALSE,
FALSE,
],
[
TRUE,
TRUE,
],
[
1,
TRUE,
],
];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment