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() {
}
/**
* Tests removal of content moderation state entity field data.
* Tests removal of content moderation state entity.
*
* @dataProvider basicModerationTestCases
*/
public function testContentModerationStateDataRemoval($entity_type_id) {
// Test content moderation state deletion.
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $this->createEntity($entity_type_id);
$entity->save();
......@@ -187,44 +186,80 @@ public function testContentModerationStateDataRemoval($entity_type_id) {
$entity->delete();
$content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity);
$this->assertFalse($content_moderation_state);
}
// Test content moderation state revision deletion.
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity2 */
$entity2 = $this->createEntity($entity_type_id);
$entity2->save();
$revision = clone $entity2;
/**
* Tests removal of content moderation state entity revisions.
*
* @dataProvider basicModerationTestCases
*/
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);
$content_moderation_state = ContentModerationState::loadFromModeratedEntity($revision);
$this->assertTrue($content_moderation_state);
$entity2 = $this->reloadEntity($entity2);
$entity2->setNewRevision(TRUE);
$entity2->save();
$entity = $this->reloadEntity($entity);
$entity->setNewRevision(TRUE);
$entity->save();
$entity_storage = $this->entityTypeManager->getStorage($entity_type_id);
$entity_storage->deleteRevision($revision->getRevisionId());
$content_moderation_state = ContentModerationState::loadFromModeratedEntity($revision);
$this->assertFalse($content_moderation_state);
$content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity2);
$content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity);
$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.
if ($this->entityTypeManager->getDefinition($entity_type_id)->isTranslatable()) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity3 */
$entity3 = $this->createEntity($entity_type_id);
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $this->createEntity($entity_type_id);
$langcode = 'it';
ConfigurableLanguage::createFromLangcode($langcode)
->save();
$entity3->save();
$translation = $entity3->addTranslation($langcode, ['title' => 'Titolo test']);
$entity->save();
$translation = $entity->addTranslation($langcode, ['title' => 'Titolo test']);
// Make sure we add values for all of the required fields.
if ($entity_type_id == 'block_content') {
$translation->info = $this->randomString();
}
$translation->save();
$content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity3);
$content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity);
$this->assertTrue($content_moderation_state->hasTranslation($langcode));
$entity3->removeTranslation($langcode);
$entity3->save();
$content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity3);
$entity->removeTranslation($langcode);
$entity->save();
$content_moderation_state = ContentModerationState::loadFromModeratedEntity($entity);
$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