Commit 445b7d05 authored by alexpott's avatar alexpott
Browse files

Issue #2933099 by Sam152, sathish.redcrackle, amaisano, Berdir: "Default...

Issue #2933099 by Sam152, sathish.redcrackle, amaisano, Berdir: "Default Revision cannot be deleted." But it's not the default revision
parent cb237504
...@@ -174,12 +174,11 @@ public function basicModerationTestCases() { ...@@ -174,12 +174,11 @@ public function basicModerationTestCases() {
} }
/** /**
* Tests removal of content moderation state entity field data. * Tests removal of content moderation state entity.
* *
* @dataProvider basicModerationTestCases * @dataProvider basicModerationTestCases
*/ */
public function testContentModerationStateDataRemoval($entity_type_id) { public function testContentModerationStateDataRemoval($entity_type_id) {
// Test content moderation state deletion.
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $this->createEntity($entity_type_id); $entity = $this->createEntity($entity_type_id);
$entity->save(); $entity->save();
...@@ -187,44 +186,80 @@ public function testContentModerationStateDataRemoval($entity_type_id) { ...@@ -187,44 +186,80 @@ public function testContentModerationStateDataRemoval($entity_type_id) {
$entity->delete(); $entity->delete();
$content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity); $content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity);
$this->assertFalse($content_moderation_state); $this->assertFalse($content_moderation_state);
}
// Test content moderation state revision deletion. /**
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity2 */ * Tests removal of content moderation state entity revisions.
$entity2 = $this->createEntity($entity_type_id); *
$entity2->save(); * @dataProvider basicModerationTestCases
$revision = clone $entity2; */
public function testContentModerationStateRevisionDataRemoval($entity_type_id) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $this->createEntity($entity_type_id);
$entity->save();
$revision = clone $entity;
$revision->isDefaultRevision(FALSE); $revision->isDefaultRevision(FALSE);
$content_moderation_state = ContentModerationState::loadFromModeratedEntity($revision); $content_moderation_state = ContentModerationState::loadFromModeratedEntity($revision);
$this->assertTrue($content_moderation_state); $this->assertTrue($content_moderation_state);
$entity2 = $this->reloadEntity($entity2); $entity = $this->reloadEntity($entity);
$entity2->setNewRevision(TRUE); $entity->setNewRevision(TRUE);
$entity2->save(); $entity->save();
$entity_storage = $this->entityTypeManager->getStorage($entity_type_id); $entity_storage = $this->entityTypeManager->getStorage($entity_type_id);
$entity_storage->deleteRevision($revision->getRevisionId()); $entity_storage->deleteRevision($revision->getRevisionId());
$content_moderation_state = ContentModerationState::loadFromModeratedEntity($revision); $content_moderation_state = ContentModerationState::loadFromModeratedEntity($revision);
$this->assertFalse($content_moderation_state); $this->assertFalse($content_moderation_state);
$content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity2); $content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity);
$this->assertTrue($content_moderation_state); $this->assertTrue($content_moderation_state);
}
/**
* Tests removal of content moderation state pending entity revisions.
*
* @dataProvider basicModerationTestCases
*/
public function testContentModerationStatePendingRevisionDataRemoval($entity_type_id) {
$entity = $this->createEntity($entity_type_id);
$entity->moderation_state = 'published';
$entity->save();
$entity->setNewRevision(TRUE);
$entity->moderation_state = 'draft';
$entity->save();
$content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity);
$this->assertTrue($content_moderation_state);
$entity_storage = $this->entityTypeManager->getStorage($entity_type_id);
$entity_storage->deleteRevision($entity->getRevisionId());
$content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity);
$this->assertFalse($content_moderation_state);
}
/**
* Tests removal of content moderation state translations.
*
* @dataProvider basicModerationTestCases
*/
public function testContentModerationStateTranslationDataRemoval($entity_type_id) {
// Test content moderation state translation deletion. // Test content moderation state translation deletion.
if ($this->entityTypeManager->getDefinition($entity_type_id)->isTranslatable()) { if ($this->entityTypeManager->getDefinition($entity_type_id)->isTranslatable()) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity3 */ /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity3 = $this->createEntity($entity_type_id); $entity = $this->createEntity($entity_type_id);
$langcode = 'it'; $langcode = 'it';
ConfigurableLanguage::createFromLangcode($langcode) ConfigurableLanguage::createFromLangcode($langcode)
->save(); ->save();
$entity3->save(); $entity->save();
$translation = $entity3->addTranslation($langcode, ['title' => 'Titolo test']); $translation = $entity->addTranslation($langcode, ['title' => 'Titolo test']);
// Make sure we add values for all of the required fields. // Make sure we add values for all of the required fields.
if ($entity_type_id == 'block_content') { if ($entity_type_id == 'block_content') {
$translation->info = $this->randomString(); $translation->info = $this->randomString();
} }
$translation->save(); $translation->save();
$content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity3); $content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity);
$this->assertTrue($content_moderation_state->hasTranslation($langcode)); $this->assertTrue($content_moderation_state->hasTranslation($langcode));
$entity3->removeTranslation($langcode); $entity->removeTranslation($langcode);
$entity3->save(); $entity->save();
$content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity3); $content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity);
$this->assertFalse($content_moderation_state->hasTranslation($langcode)); $this->assertFalse($content_moderation_state->hasTranslation($langcode));
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment