function EntityOperationsTest::testPublishedCreation

Same name in other branches
  1. 9 core/modules/content_moderation/tests/src/Kernel/EntityOperationsTest.php \Drupal\Tests\content_moderation\Kernel\EntityOperationsTest::testPublishedCreation()
  2. 10 core/modules/content_moderation/tests/src/Kernel/EntityOperationsTest.php \Drupal\Tests\content_moderation\Kernel\EntityOperationsTest::testPublishedCreation()
  3. 11.x core/modules/content_moderation/tests/src/Kernel/EntityOperationsTest.php \Drupal\Tests\content_moderation\Kernel\EntityOperationsTest::testPublishedCreation()

Verifies that a newly-created node can go straight to published.

File

core/modules/content_moderation/tests/src/Kernel/EntityOperationsTest.php, line 135

Class

EntityOperationsTest
@coversDefaultClass \Drupal\content_moderation\EntityOperations

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testPublishedCreation() {
    // Create a new node in draft.
    $page = Node::create([
        'type' => 'page',
        'title' => 'A',
    ]);
    $page->moderation_state->value = 'published';
    $page->save();
    $id = $page->id();
    // Verify the entity saved correctly.
    
    /** @var \Drupal\node\Entity\Node $page */
    $page = Node::load($id);
    $this->assertEquals('A', $page->getTitle());
    $this->assertTrue($page->isDefaultRevision());
    $this->assertTrue($page->isPublished());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.