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

Issue #3497907 by eiriksm: Make it possible to add and retrieve licences

parent aeaacfa3
No related branches found
No related tags found
1 merge request!76Initial
Pipeline #388842 passed with warnings
......@@ -468,4 +468,24 @@ class TeamNode extends Node {
return $this;
}
/**
* Add a licence to the team.
*/
public function addLicence(string $licence) {
$this->get('field_licences')->appendItem($licence);
return $this;
}
/**
* Get the actual licences a team has saved.
*/
public function getLicences() : array {
if (!$this->hasField('field_licences') || $this->get('field_licences')->isEmpty()) {
return [];
}
return array_map(function ($item) {
return $item['value'];
}, $this->get('field_licences')->getValue());
}
}
......@@ -67,6 +67,22 @@ abstract class KernelTestBase extends CoreKernelTestBase {
]);
$field->save();
// Licences.
$fieldStorage = FieldStorageConfig::create([
'field_name' => 'field_licences',
'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();
// The field we use for env vars.
$fieldStorage = FieldStorageConfig::create([
'field_name' => 'field_environment_variables',
......
......@@ -262,6 +262,25 @@ class TeamNodeTest extends KernelTestBase {
self::assertEquals(3, $node->getPlan()->getMaxPrivateRepos());
}
/**
* Test the licence things.
*/
public function testLicences() {
/** @var \Drupal\violinist_teams\TeamNode $node */
$node = Node::create([
'type' => $this->nodeType->id(),
]);
$node->addLicence('test');
self::assertEquals(['test'], $node->getLicences());
// Now add another one, and make sure its there.
$node->addLicence('test2');
self::assertEquals(['test', 'test2'], $node->getLicences());
// Now overwrite it.
$node->set('field_licences', []);
$node->addLicence('test3');
self::assertEquals(['test3'], $node->getLicences());
}
/**
* Dataprovider for environment variables.
*/
......
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