Skip to content

Commit

Permalink
HPC-9281: Fix the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
berliner committed Mar 15, 2024
1 parent 57c1eed commit 6306c7e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 78 deletions.
3 changes: 3 additions & 0 deletions html/modules/custom/ghi_content/src/Entity/ContentBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ public function getStructuralTags() {
* The content space term.
*/
public function getContentSpace() {
if (!$this->hasField('field_content_space')) {
return NULL;
}
return $this->get('field_content_space')?->entity ?? NULL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
namespace Drupal\Tests\ghi_content\Kernel;

use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\ghi_content\Entity\Article;
use Drupal\ghi_sections\Entity\Section;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\node\NodeInterface;
use Drupal\Tests\field\Traits\EntityReferenceFieldCreationTrait;
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;

Expand All @@ -23,6 +22,7 @@ class ArticleManagerTest extends KernelTestBase {

use TaxonomyTestTrait;
use UserCreationTrait;
use EntityReferenceFieldCreationTrait;

/**
* Modules to enable.
Expand Down Expand Up @@ -89,43 +89,13 @@ protected function setUp(): void {
$this->vocabulary = $this->createVocabulary();

// Setup the tags field on our node types.
$field_storage = FieldStorageConfig::create([
'field_name' => 'field_tags',
'entity_type' => 'node',
'type' => 'entity_reference',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => [
'target_type' => 'taxonomy_term',
$handler_settings = [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
],
]);
$field_storage->save();

FieldConfig::create([
'field_name' => 'field_tags',
'field_storage' => $field_storage,
'bundle' => self::SECTION_BUNDLE,
'settings' => [
'handler' => 'default',
'handler_settings' => [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
],
],
],
])->save();
FieldConfig::create([
'field_name' => 'field_tags',
'field_storage' => $field_storage,
'bundle' => self::ARTICLE_BUNDLE,
'settings' => [
'handler' => 'default',
'handler_settings' => [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
],
],
],
])->save();
];
$this->createEntityReferenceField('node', self::SECTION_BUNDLE, 'field_tags', 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
$this->createEntityReferenceField('node', self::ARTICLE_BUNDLE, 'field_tags', 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);

// $this->setUpCurrentUser([], ['access content']);
$this->setUpCurrentUser(['uid' => 1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
namespace Drupal\Tests\ghi_content\Kernel;

use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\ghi_sections\Entity\Section;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\taxonomy\TermInterface;
use Drupal\Tests\field\Traits\EntityReferenceFieldCreationTrait;
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;

Expand All @@ -22,6 +21,7 @@ class DocumentManagerTest extends KernelTestBase {

use TaxonomyTestTrait;
use UserCreationTrait;
use EntityReferenceFieldCreationTrait;

/**
* Modules to enable.
Expand Down Expand Up @@ -52,7 +52,7 @@ class DocumentManagerTest extends KernelTestBase {
const DOCUMENT_BUNDLE = 'document';

/**
* A vocabulary.
* A vocabulary for tags.
*
* @var \Drupal\taxonomy\VocabularyInterface
*/
Expand Down Expand Up @@ -87,45 +87,14 @@ protected function setUp(): void {
$this->vocabulary = $this->createVocabulary();

// Setup the tags field on our node types.
$field_storage = FieldStorageConfig::create([
'field_name' => 'field_tags',
'entity_type' => 'node',
'type' => 'entity_reference',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => [
'target_type' => 'taxonomy_term',
$handler_settings = [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
],
]);
$field_storage->save();

FieldConfig::create([
'field_name' => 'field_tags',
'field_storage' => $field_storage,
'bundle' => self::SECTION_BUNDLE,
'settings' => [
'handler' => 'default',
'handler_settings' => [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
],
],
],
])->save();
FieldConfig::create([
'field_name' => 'field_tags',
'field_storage' => $field_storage,
'bundle' => self::DOCUMENT_BUNDLE,
'settings' => [
'handler' => 'default',
'handler_settings' => [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
],
],
],
])->save();
];
$this->createEntityReferenceField('node', self::SECTION_BUNDLE, 'field_tags', 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
$this->createEntityReferenceField('node', self::DOCUMENT_BUNDLE, 'field_tags', 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);

// $this->setUpCurrentUser([], ['access content']);
$this->setUpCurrentUser(['uid' => 1]);
}

Expand Down

0 comments on commit 6306c7e

Please sign in to comment.