View source
<?php
namespace Drupal\Tests\content_translation\Functional;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
abstract class ContentTranslationPendingRevisionTestBase extends ContentTranslationTestBase {
use ContentTypeCreationTrait;
use ContentModerationTestTrait;
protected static $modules = [
'language',
'content_translation',
'content_moderation',
'node',
];
protected $storage;
protected $commonPermissions;
protected $currentAccount;
protected function setUp() {
$this->entityTypeId = 'node';
$this->bundle = 'article';
$this->commonPermissions = [
'view any unpublished content',
"translate {$this->bundle} {$this->entityTypeId}",
"create content translations",
'use editorial transition create_new_draft',
'use editorial transition publish',
'use editorial transition archive',
'use editorial transition archived_draft',
'use editorial transition archived_published',
];
parent::setUp();
$entity_type_manager = $this->container
->get('entity_type.manager');
$this->storage = $entity_type_manager
->getStorage($this->entityTypeId);
$this
->config('node.settings')
->set('use_admin_theme', '1')
->save();
}
protected function enableContentModeration() {
$this
->drupalLogin($this->rootUser);
$workflow_id = 'editorial';
$this
->drupalGet('/admin/config/workflow/workflows');
$edit['bundles[' . $this->bundle . ']'] = TRUE;
$this
->drupalGet('admin/config/workflow/workflows/manage/' . $workflow_id . '/type/' . $this->entityTypeId);
$this
->submitForm($edit, 'Save');
\Drupal::service('entity_type.bundle.info')
->clearCachedBundles();
\Drupal::service('entity_field.manager')
->clearCachedFieldDefinitions();
$router_builder = $this->container
->get('router.builder');
$router_builder
->rebuildIfNeeded();
}
protected function getEditorPermissions() {
$editor_permissions = [
"edit any {$this->bundle} content",
"delete any {$this->bundle} content",
"view {$this->bundle} revisions",
"delete {$this->bundle} revisions",
];
return array_merge($editor_permissions, $this->commonPermissions);
}
protected function getTranslatorPermissions() {
return array_merge(parent::getTranslatorPermissions(), $this->commonPermissions);
}
protected function setupBundle() {
parent::setupBundle();
$this
->createContentType([
'type' => $this->bundle,
]);
$this
->createEditorialWorkflow();
}
protected function loadRevisionTranslation(ContentEntityInterface $entity, $langcode) {
$this->storage
->resetCache([
$entity
->id(),
]);
$revision_id = $this->storage
->getLatestTranslationAffectedRevisionId($entity
->id(), $langcode);
$revision = $revision_id ? $this->storage
->loadRevision($revision_id) : NULL;
return $revision && $revision
->hasTranslation($langcode) ? $revision
->getTranslation($langcode) : NULL;
}
protected function getEditUrl(ContentEntityInterface $entity) {
if ($entity
->access('update', $this->loggedInUser)) {
$url = $entity
->toUrl('edit-form');
}
else {
$url = $entity
->toUrl('drupal:content-translation-edit');
$url
->setRouteParameter('language', $entity
->language()
->getId());
}
return $url;
}
protected function getDeleteUrl(ContentEntityInterface $entity) {
if ($entity
->access('delete', $this->loggedInUser)) {
$url = $entity
->toUrl('delete-form');
}
else {
$url = $entity
->toUrl('drupal:content-translation-delete');
$url
->setRouteParameter('language', $entity
->language()
->getId());
}
return $url;
}
}