public function ModerationStateNodeTest::testCreatingContent in Drupal 10
Same name and namespace in other branches
- 8 core/modules/content_moderation/tests/src/Functional/ModerationStateNodeTest.php \Drupal\Tests\content_moderation\Functional\ModerationStateNodeTest::testCreatingContent()
- 9 core/modules/content_moderation/tests/src/Functional/ModerationStateNodeTest.php \Drupal\Tests\content_moderation\Functional\ModerationStateNodeTest::testCreatingContent()
Tests creating and deleting content.
File
- core/
modules/ content_moderation/ tests/ src/ Functional/ ModerationStateNodeTest.php, line 33
Class
- ModerationStateNodeTest
- Tests general content moderation workflow for nodes.
Namespace
Drupal\Tests\content_moderation\FunctionalCode
public function testCreatingContent() {
$this
->drupalGet('node/add/moderated_content');
$this
->submitForm([
'title[0][value]' => 'moderated content',
'moderation_state[0][state]' => 'draft',
], 'Save');
$node = $this
->getNodeByTitle('moderated content');
if (!$node) {
$this
->fail('Test node was not saved correctly.');
}
$this
->assertEquals('draft', $node->moderation_state->value);
$path = 'node/' . $node
->id() . '/edit';
// Set up published revision.
$this
->drupalGet($path);
$this
->submitForm([
'moderation_state[0][state]' => 'published',
], 'Save');
\Drupal::entityTypeManager()
->getStorage('node')
->resetCache([
$node
->id(),
]);
/** @var \Drupal\node\NodeInterface $node */
$node = \Drupal::entityTypeManager()
->getStorage('node')
->load($node
->id());
$this
->assertTrue($node
->isPublished());
$this
->assertEquals('published', $node->moderation_state->value);
// Verify that the state field is not shown.
$this
->assertSession()
->pageTextNotContains('Published');
// Delete the node.
$this
->drupalGet('node/' . $node
->id() . '/delete');
$this
->submitForm([], 'Delete');
$this
->assertSession()
->pageTextContains('The Moderated content moderated content has been deleted.');
// Disable content moderation.
$edit['bundles[moderated_content]'] = FALSE;
$this
->drupalGet('admin/config/workflow/workflows/manage/editorial/type/node');
$this
->submitForm($edit, 'Save');
// Ensure the parent environment is up-to-date.
// @see content_moderation_workflow_insert()
\Drupal::service('entity_type.bundle.info')
->clearCachedBundles();
\Drupal::service('entity_field.manager')
->clearCachedFieldDefinitions();
// Create a new node.
$this
->drupalGet('node/add/moderated_content');
$this
->submitForm([
'title[0][value]' => 'non-moderated content',
], 'Save');
$node = $this
->getNodeByTitle('non-moderated content');
if (!$node) {
$this
->fail('Non-moderated test node was not saved correctly.');
}
$this
->assertFalse($node
->hasField('moderation_state'));
}