RemoveIdFieldTest.php in Acquia Content Hub 8.2
File
tests/src/Kernel/EventSubscriber/ExcludeContentField/RemoveIdFieldTest.php
View source
<?php
namespace Drupal\Tests\acquia_contenthub\Kernel\EventSubscriber\ExcludeContentField;
use Drupal\acquia_contenthub\Event\ExcludeEntityFieldEvent;
use Drupal\acquia_contenthub\EventSubscriber\ExcludeContentField\RemoveIdField;
use Drupal\entityqueue\Entity\EntityQueue;
use Drupal\entityqueue\Entity\EntitySubqueue;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\node\Traits\NodeCreationTrait;
class RemoveIdFieldTest extends KernelTestBase {
use NodeCreationTrait, ContentTypeCreationTrait;
public static $modules = [
'field',
'filter',
'depcalc',
'acquia_contenthub',
'entityqueue',
'node',
'text',
'user',
'system',
];
public function setUp() : void {
parent::setup();
$this
->installConfig('node');
$this
->installConfig('field');
$this
->installConfig('filter');
$this
->installEntitySchema('node');
$this
->installEntitySchema('user');
$this
->installEntitySchema('entity_subqueue');
}
public function testRemoveIdField() {
$this
->createContentType([
'type' => 'article',
'name' => 'article',
]);
$node = $this
->createNode([
'type' => 'article',
]);
$remove_id_and_revision_field = new RemoveIdField();
foreach ($node as $field_name => $field) {
$event = new ExcludeEntityFieldEvent($node, $field_name, $field);
$remove_id_and_revision_field
->excludeContentField($event);
if ($field_name === $event
->getEntity()
->getEntityType()
->getKey('id')) {
$this
->assertTrue($event
->isExcluded());
$this
->assertTrue($event
->isPropagationStopped());
}
else {
$this
->assertFalse($event
->isExcluded());
$this
->assertFalse($event
->isPropagationStopped());
}
}
}
public function testEntitySubqueueNotRemoveIdField() {
$entity_queue = EntityQueue::create([
'id' => $this
->randomMachineName(),
'label' => $this
->randomString(),
'handler' => 'simple',
'entity_settings' => [
'target_type' => 'node',
],
]);
$entity_queue
->save();
$entity_subqueue = EntitySubqueue::load($entity_queue
->id());
$remove_id_and_revision_field = new RemoveIdField();
foreach ($entity_subqueue as $field_name => $field) {
$event = new ExcludeEntityFieldEvent($entity_subqueue, $field_name, $field);
$this
->assertFalse($remove_id_and_revision_field
->shouldExclude($event));
}
}
}