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

Issue #3414624 by eiriksm: Add method for finding team billing status and email

parent ea151ada
No related branches found
No related tags found
1 merge request!25Add method and tests
Pipeline #77075 passed
......@@ -16,6 +16,28 @@ class TeamNode extends Node {
const PLAN_FIELD = 'field_plan';
const PROJECT_LIMIT_FIELD = 'field_project_limit';
const SLACK_NOTIFICATION_ENABLED_FIELD = 'field_slack_notifications';
const BILLING_ENABLED_FIELD = 'field_send_receipts';
const BILLING_EMAIL_FIELD = 'field_billing_email';
/**
* Currently this is only one email, but we return an array for consistency.
*
* And I guess for future proofing.
*/
public function getBillingEmails() : array {
if (!$this->hasField(self::BILLING_ENABLED_FIELD) || $this->get(self::BILLING_ENABLED_FIELD)->isEmpty()) {
return [];
}
$enabled = (bool) $this->get(self::BILLING_ENABLED_FIELD)->first()->getString();
if (!$enabled) {
return [];
}
if (!$this->hasField(self::BILLING_EMAIL_FIELD) || $this->get(self::BILLING_EMAIL_FIELD)->isEmpty()) {
return [];
}
$email = $this->get(self::BILLING_EMAIL_FIELD)->first()->getString();
return [$email];
}
/**
* Are those slack notifications enabled, globally, for the team?
......
......@@ -124,6 +124,43 @@ abstract class KernelTestBase extends CoreKernelTestBase {
],
]);
$field->save();
// Billing enabled.
$fieldStorage = FieldStorageConfig::create([
'field_name' => 'field_send_receipts',
'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();
// Billing email.
$fieldStorage = FieldStorageConfig::create([
'field_name' => 'field_billing_email',
'entity_type' => 'node',
'type' => 'email',
'cardinality' => 1,
]);
$fieldStorage->save();
$field = FieldConfig::create([
'field_storage' => $fieldStorage,
'bundle' => $this->nodeType->id(),
'field_type' => 'email',
'required' => FALSE,
]);
$field->save();
$this->installSchema('user', ['users_data']);
}
......
......@@ -87,6 +87,49 @@ class TeamNodeTest extends KernelTestBase {
self::assertEquals($expexted, $node->isNotificationsEnabledForSlack());
}
/**
* Test migrating billing emails.
*
* @dataProvider getBillingEmailData
*/
public function testGetBillingEmails($billing_enabled_value, $billing_email_value, $expected_result) {
/** @var \Drupal\violinist_teams\TeamNode $node */
$node = Node::create([
'type' => $this->nodeType->id(),
]);
$node->set('field_send_receipts', $billing_enabled_value);
$node->set('field_billing_email', $billing_email_value);
self::assertEquals($expected_result, $node->getBillingEmails());
}
/**
* Data provider for billing and billing email test.
*/
public function getBillingEmailData() {
return [
[
NULL,
NULL,
[],
],
[
1,
NULL,
[],
],
[
0,
'email@emai.com',
[],
],
[
TRUE,
'fox@fbi.gov',
['fox@fbi.gov'],
],
];
}
/**
* Data provider for mail notification thing.
*/
......
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