function EntityOperationsTest::testPublishedCreation

Same name and namespace in other branches
  1. 8.9.x 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 <a href="/api/drupal/core%21modules%21content_moderation%21src%21EntityOperations.php/class/EntityOperations/9" title="Defines a class for reacting to entity events." class="local">\Drupal\content_moderation\EntityOperations</a>

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.