/** * Verify moderation state methods based on entity properties. * * @covers ::isPublishedState * @covers ::isDefaultRevisionState * * @dataProvider moderationStateProvider */ public function testModerationStateProperties($published, $default_revision, $is_published, $is_default) { $moderation_state_id = $this->randomMachineName(); $moderation_state = ModerationState::create(['id' => $moderation_state_id, 'label' => $this->randomString(), 'published' => $published, 'default_revision' => $default_revision]); $moderation_state->save(); $moderation_state = ModerationState::load($moderation_state_id); $this->assertEquals($is_published, $moderation_state->isPublishedState()); $this->assertEquals($is_default, $moderation_state->isDefaultRevisionState()); }
/** * Verifies that an unpublished state may be made the default revision. */ public function testArchive() { $published_id = $this->randomMachineName(); $published_state = ModerationState::create(['id' => $published_id, 'label' => $this->randomString(), 'published' => TRUE, 'default_revision' => TRUE]); $published_state->save(); $archived_id = $this->randomMachineName(); $archived_state = ModerationState::create(['id' => $archived_id, 'label' => $this->randomString(), 'published' => FALSE, 'default_revision' => TRUE]); $archived_state->save(); $page = Node::create(['type' => 'page', 'title' => $this->randomString()]); $page->moderation_state->target_id = $published_id; $page->save(); $id = $page->id(); // The newly-created page should already be published. $page = Node::load($id); $this->assertTrue($page->isPublished()); // When the page is moderated to the archived state, then the latest // revision should be the default revision, and it should be unpublished. $page->moderation_state->target_id = $archived_id; $page->save(); $new_revision_id = $page->getRevisionId(); $storage = \Drupal::entityTypeManager()->getStorage('node'); $new_revision = $storage->loadRevision($new_revision_id); $this->assertFalse($new_revision->isPublished()); $this->assertTrue($new_revision->isDefaultRevision()); }