function ModerationStateFieldTest::testFieldDefinitionBundles
Same name and namespace in other branches
- 11.x core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldTest.php \Drupal\Tests\content_moderation\Kernel\ModerationStateFieldTest::testFieldDefinitionBundles()
Tests that the moderation state field target bundle is always correct.
File
-
core/
modules/ content_moderation/ tests/ src/ Kernel/ ModerationStateFieldTest.php, line 49
Class
- ModerationStateFieldTest
- Tests the moderation state field.
Namespace
Drupal\Tests\content_moderation\KernelCode
public function testFieldDefinitionBundles() : void {
$workflow = $this->createEditorialWorkflow();
/** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModerationInterface $workflow_type */
$workflow_type = $workflow->getTypePlugin();
$node_types = [];
for ($i = 0; $i < 3; ++$i) {
$node_type = $this->createContentType(create_body: FALSE);
$workflow_type->addEntityTypeAndBundle('node', $node_type->id());
$node_types[] = $node_type;
}
$workflow->save();
/** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
$entity_field_manager = \Drupal::service('entity_field.manager');
$this->assertNotEmpty($node_types);
foreach ($node_types as $node_type) {
$field_definitions = $entity_field_manager->getFieldDefinitions('node', $node_type->id());
$this->assertSame($node_type->id(), $field_definitions['moderation_state']->getTargetBundle());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.