Commit e259a778 authored by catch's avatar catch

Issue #2898020 by amateescu, timmillwood: Simplify ContentModerationStateTest

parent d4165ff1
...@@ -7,9 +7,7 @@ ...@@ -7,9 +7,7 @@
use Drupal\Core\Entity\EntityPublishedInterface; use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\entity_test\Entity\EntityTestBundle;
use Drupal\entity_test\Entity\EntityTestRev; use Drupal\entity_test\Entity\EntityTestRev;
use Drupal\entity_test\Entity\EntityTestWithBundle;
use Drupal\KernelTests\KernelTestBase; use Drupal\KernelTests\KernelTestBase;
use Drupal\language\Entity\ConfigurableLanguage; use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
...@@ -59,7 +57,6 @@ protected function setUp() { ...@@ -59,7 +57,6 @@ protected function setUp() {
$this->installSchema('node', 'node_access'); $this->installSchema('node', 'node_access');
$this->installEntitySchema('node'); $this->installEntitySchema('node');
$this->installEntitySchema('user'); $this->installEntitySchema('user');
$this->installEntitySchema('entity_test_with_bundle');
$this->installEntitySchema('entity_test_rev'); $this->installEntitySchema('entity_test_rev');
$this->installEntitySchema('entity_test_no_bundle'); $this->installEntitySchema('entity_test_no_bundle');
$this->installEntitySchema('entity_test_mulrevpub'); $this->installEntitySchema('entity_test_mulrevpub');
...@@ -84,11 +81,6 @@ protected function setUp() { ...@@ -84,11 +81,6 @@ protected function setUp() {
* The bundle identifier. * The bundle identifier.
*/ */
protected function setupBundleEntityType($entity_type_id) { protected function setupBundleEntityType($entity_type_id) {
// Make the 'entity_test_with_bundle' entity type revisionable.
if ($entity_type_id == 'entity_test_with_bundle') {
$this->setEntityTestWithBundleKeys(['revision' => 'revision_id']);
}
$bundle_id = $entity_type_id; $bundle_id = $entity_type_id;
$bundle_entity_type_id = $this->entityTypeManager->getDefinition($entity_type_id)->getBundleEntityType(); $bundle_entity_type_id = $this->entityTypeManager->getDefinition($entity_type_id)->getBundleEntityType();
if ($bundle_entity_type_id) { if ($bundle_entity_type_id) {
...@@ -215,9 +207,6 @@ public function basicModerationTestCases() { ...@@ -215,9 +207,6 @@ public function basicModerationTestCases() {
'Media' => [ 'Media' => [
'media', 'media',
], ],
'Test Entity with Bundle' => [
'entity_test_with_bundle',
],
'Test entity - revisions, data table, and published interface' => [ 'Test entity - revisions, data table, and published interface' => [
'entity_test_mulrevpub', 'entity_test_mulrevpub',
], ],
...@@ -434,34 +423,23 @@ public function testModerationWithSpecialLanguages() { ...@@ -434,34 +423,23 @@ public function testModerationWithSpecialLanguages() {
* Tests that a non-translatable entity type with a langcode can be moderated. * Tests that a non-translatable entity type with a langcode can be moderated.
*/ */
public function testNonTranslatableEntityTypeModeration() { public function testNonTranslatableEntityTypeModeration() {
// Make the 'entity_test_with_bundle' entity type revisionable.
$this->setEntityTestWithBundleKeys(['revision' => 'revision_id']);
// Create a test bundle.
$entity_test_bundle = EntityTestBundle::create([
'id' => 'example',
]);
$entity_test_bundle->save();
$workflow = Workflow::load('editorial'); $workflow = Workflow::load('editorial');
$workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_with_bundle', 'example'); $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_rev', 'entity_test_rev');
$workflow->save(); $workflow->save();
// Check that the tested entity type is not translatable. // Check that the tested entity type is not translatable.
$entity_type = \Drupal::entityTypeManager()->getDefinition('entity_test_with_bundle'); $entity_type = \Drupal::entityTypeManager()->getDefinition('entity_test_rev');
$this->assertFalse($entity_type->isTranslatable(), 'The test entity type is not translatable.'); $this->assertFalse($entity_type->isTranslatable(), 'The test entity type is not translatable.');
// Create a test entity. // Create a test entity.
$entity_test_with_bundle = EntityTestWithBundle::create([ $entity = EntityTestRev::create();
'type' => 'example' $entity->save();
]); $this->assertEquals('draft', $entity->moderation_state->value);
$entity_test_with_bundle->save();
$this->assertEquals('draft', $entity_test_with_bundle->moderation_state->value);
$entity_test_with_bundle->moderation_state->value = 'published'; $entity->moderation_state->value = 'published';
$entity_test_with_bundle->save(); $entity->save();
$this->assertEquals('published', EntityTestWithBundle::load($entity_test_with_bundle->id())->moderation_state->value); $this->assertEquals('published', EntityTestRev::load($entity->id())->moderation_state->value);
} }
/** /**
...@@ -469,54 +447,35 @@ public function testNonTranslatableEntityTypeModeration() { ...@@ -469,54 +447,35 @@ public function testNonTranslatableEntityTypeModeration() {
* moderated. * moderated.
*/ */
public function testNonLangcodeEntityTypeModeration() { public function testNonLangcodeEntityTypeModeration() {
// Make the 'entity_test_with_bundle' entity type revisionable and unset // Unset the langcode entity key for 'entity_test_rev'.
// the langcode entity key. $entity_type = clone \Drupal::entityTypeManager()->getDefinition('entity_test_rev');
$this->setEntityTestWithBundleKeys(['revision' => 'revision_id'], ['langcode']); $keys = $entity_type->getKeys();
unset($keys['langcode']);
// Create a test bundle. $entity_type->set('entity_keys', $keys);
$entity_test_bundle = EntityTestBundle::create([ \Drupal::state()->set('entity_test_rev.entity_type', $entity_type);
'id' => 'example',
]); // Update the entity type in order to remove the 'langcode' field.
$entity_test_bundle->save(); \Drupal::entityDefinitionUpdateManager()->applyUpdates();
$workflow = Workflow::load('editorial'); $workflow = Workflow::load('editorial');
$workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_with_bundle', 'example'); $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_rev', 'entity_test_rev');
$workflow->save(); $workflow->save();
// Check that the tested entity type is not translatable. // Check that the tested entity type is not translatable and does not have a
$entity_type = \Drupal::entityTypeManager()->getDefinition('entity_test_with_bundle'); // 'langcode' entity key.
$entity_type = \Drupal::entityTypeManager()->getDefinition('entity_test_rev');
$this->assertFalse($entity_type->isTranslatable(), 'The test entity type is not translatable.'); $this->assertFalse($entity_type->isTranslatable(), 'The test entity type is not translatable.');
$this->assertFalse($entity_type->getKey('langcode'), "The test entity type does not have a 'langcode' entity key.");
// Create a test entity. // Create a test entity.
$entity_test_with_bundle = EntityTestWithBundle::create([ $entity = EntityTestRev::create();
'type' => 'example' $entity->save();
]); $this->assertEquals('draft', $entity->moderation_state->value);
$entity_test_with_bundle->save();
$this->assertEquals('draft', $entity_test_with_bundle->moderation_state->value);
$entity_test_with_bundle->moderation_state->value = 'published';
$entity_test_with_bundle->save();
$this->assertEquals('published', EntityTestWithBundle::load($entity_test_with_bundle->id())->moderation_state->value); $entity->moderation_state->value = 'published';
} $entity->save();
/** $this->assertEquals('published', EntityTestRev::load($entity->id())->moderation_state->value);
* Set the keys on the test entity type.
*
* @param array $keys
* The entity keys to override
* @param array $remove_keys
* Keys to remove.
*/
protected function setEntityTestWithBundleKeys($keys, $remove_keys = []) {
$entity_type = clone \Drupal::entityTypeManager()->getDefinition('entity_test_with_bundle');
$original_keys = $entity_type->getKeys();
foreach ($remove_keys as $remove_key) {
unset($original_keys[$remove_key]);
}
$entity_type->set('entity_keys', $keys + $original_keys);
\Drupal::state()->set('entity_test_with_bundle.entity_type', $entity_type);
\Drupal::entityDefinitionUpdateManager()->applyUpdates();
} }
/** /**
......
...@@ -94,8 +94,8 @@ function entity_test_entity_type_alter(array &$entity_types) { ...@@ -94,8 +94,8 @@ function entity_test_entity_type_alter(array &$entity_types) {
} }
} }
// Allow entity_test_with_bundle tests to override the entity type definition. // Allow entity_test_rev tests to override the entity type definition.
$entity_types['entity_test_with_bundle'] = $state->get('entity_test_with_bundle.entity_type', $entity_types['entity_test_with_bundle']); $entity_types['entity_test_rev'] = $state->get('entity_test_rev.entity_type', $entity_types['entity_test_rev']);
// Enable the entity_test_new only when needed. // Enable the entity_test_new only when needed.
if (!$state->get('entity_test_new')) { if (!$state->get('entity_test_new')) {
...@@ -103,17 +103,6 @@ function entity_test_entity_type_alter(array &$entity_types) { ...@@ -103,17 +103,6 @@ function entity_test_entity_type_alter(array &$entity_types) {
} }
} }
/**
* Implements hook_module_implements_alter().
*/
function entity_test_module_implements_alter(&$implementations, $hook) {
// Move our hook_entity_type_alter() implementation to the beginning of the
// list in order to run before content_moderation_entity_type_alter().
if ($hook === 'entity_type_alter') {
$implementations = ['entity_test' => $implementations['entity_test']] + $implementations;
}
}
/** /**
* Implements hook_entity_base_field_info(). * Implements hook_entity_base_field_info().
*/ */
......
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