RemoveRevisionFieldTest.php in Acquia Content Hub 8.2
File
tests/src/Kernel/EventSubscriber/ExcludeContentField/RemoveRevisionFieldTest.php
View source
<?php
namespace Drupal\Tests\acquia_contenthub\Kernel\EventSubscriber\ExcludeContentField;
use Drupal\acquia_contenthub\Event\ExcludeEntityFieldEvent;
use Drupal\acquia_contenthub\EventSubscriber\ExcludeContentField\RemoveRevisionField;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\node\Traits\NodeCreationTrait;
class RemoveRevisionFieldTest extends KernelTestBase {
use NodeCreationTrait, ContentTypeCreationTrait;
public static $modules = [
'field',
'filter',
'depcalc',
'acquia_contenthub',
'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');
}
public function testRemoveRevisionField() {
$this
->createContentType([
'type' => 'article',
'name' => 'article',
]);
$node = $this
->createNode([
'type' => 'article',
]);
$remove_id_and_revision_field = new RemoveRevisionField();
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('revision')) {
$this
->assertTrue($event
->isExcluded());
$this
->assertTrue($event
->isPropagationStopped());
}
else {
$this
->assertFalse($event
->isExcluded());
$this
->assertFalse($event
->isPropagationStopped());
}
}
}
}