Skip to content
Snippets Groups Projects
Verified Commit 7051d6a4 authored by dpi's avatar dpi
Browse files

Issue #3008840 by dpi, jibran: Added global scheduled collection route and optional view

parent 60dc2d0e
No related branches found
Tags 8.x-1.0-beta1
No related merge requests found
Showing
with 1174 additions and 6 deletions
status: true
dependencies:
module:
- dynamic_entity_reference
- scheduled_transitions
- user
id: scheduled_transitions
label: 'Scheduled Transitions'
module: views
description: ''
tag: ''
base_table: scheduled_transition
base_field: id
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'view all scheduled transitions'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: mini
options:
items_per_page: 50
offset: 0
id: 0
total_pages: null
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '5, 10, 25, 50'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
tags:
previous: ‹‹
next: ››
style:
type: table
options:
grouping: { }
row_class: ''
default_row_class: true
override: true
sticky: false
caption: ''
summary: ''
description: ''
columns:
entity__target_id: entity__target_id
state_from: state_from
moderation_state: moderation_state
transition_on: transition_on
author: author
operations: operations
info:
entity__target_id:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
state_from:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
moderation_state:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
transition_on:
sortable: true
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
author:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
operations:
align: ''
separator: ''
empty_column: false
responsive: ''
default: transition_on
empty_table: false
row:
type: fields
fields:
entity__target_id:
id: entity__target_id
table: scheduled_transition
field: entity__target_id
relationship: none
group_type: group
admin_label: ''
label: Entity
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: target_id
type: dynamic_entity_reference_label
settings:
link: true
group_column: ''
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
entity_type: scheduled_transition
entity_field: entity
plugin_id: field
entity_revision_link:
id: entity_revision_link
table: scheduled_transition
field: entity_revision_link
relationship: none
group_type: group
admin_label: ''
label: Revision
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
text: 'View revision'
entity_type: scheduled_transition
plugin_id: scheduled_transitions_revision_link
state_from:
id: state_from
table: scheduled_transition
field: state_from
relationship: none
group_type: group
admin_label: ''
label: 'From state'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
entity_type: scheduled_transition
plugin_id: scheduled_transitions_transition_from
moderation_state:
id: moderation_state
table: scheduled_transition
field: moderation_state
relationship: none
group_type: group
admin_label: ''
label: 'To state'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
entity_type: scheduled_transition
entity_field: moderation_state
plugin_id: scheduled_transitions_transition_to
transition_on:
id: transition_on
table: scheduled_transition
field: transition_on
relationship: none
group_type: group
admin_label: ''
label: 'On date'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: timestamp
settings:
date_format: long
custom_date_format: ''
timezone: ''
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
entity_type: scheduled_transition
entity_field: transition_on
plugin_id: field
author:
id: author
table: scheduled_transition
field: author
relationship: none
group_type: group
admin_label: ''
label: 'Scheduled by'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: target_id
type: entity_reference_label
settings:
link: true
group_column: target_id
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
entity_type: scheduled_transition
entity_field: author
plugin_id: field
operations:
id: operations
table: scheduled_transition
field: operations
relationship: none
group_type: group
admin_label: ''
label: Operations
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
destination: true
entity_type: null
entity_field: null
plugin_id: entity_operations
filters: { }
sorts: { }
title: 'Scheduled Transitions'
header: { }
footer: { }
empty:
area:
id: area
table: views
field: area
relationship: none
group_type: group
admin_label: ''
empty: true
tokenize: false
content:
value: 'There are no scheduled transitions yet.'
format: basic_html
plugin_id: text
relationships: { }
arguments: { }
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
- user.permissions
tags: { }
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 1
display_options:
display_extenders: { }
path: admin/content/scheduled-transitions
enabled: true
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
- user.permissions
tags: { }
# Schema for \Drupal\scheduled_transitions\Plugin\views\field\ScheduledTransitionRevisionLinkField plugin.
views.field.scheduled_transitions_revision_link:
type: views_field
label: 'Link to a entity revision'
mapping:
text:
type: label
label: 'Text to display'
entity.scheduled_transition.collection:
title: Scheduled transitions
route_name: entity.scheduled_transition.collection
parent: system.admin_content
description: 'List of all scheduled transitions.'
scheduled_transitions.tasks:
deriver: 'Drupal\scheduled_transitions\Plugin\Derivative\ScheduledTransitionsLocalTasks'
weight: 100
scheduled_transitions.tasks:
deriver: 'Drupal\scheduled_transitions\Plugin\Derivative\ScheduledTransitionsLocalTasks'
weight: 100
view all scheduled transitions:
title: 'View all scheduled transitions'
description: 'Allow viewing all scheduled transitions.'
......@@ -18,13 +18,14 @@ use Drupal\workflows\WorkflowInterface;
*
* @ContentEntityType(
* id = "scheduled_transition",
* label = @Translation("Scheduled transition"),
* label = @Translation("scheduled transition"),
* label_singular = @Translation("Scheduled transition"),
* label_plural = @Translation("Scheduled transitions"),
* label_plural = @Translation("scheduled transitions"),
* label_count = @PluralTranslation(
* singular = "@count scheduled transition",
* plural = "@count scheduled transitions"
* ),
* label_collection = @Translation("Scheduled transitions"),
* base_table = "scheduled_transition",
* data_table = "scheduled_transition_field_data",
* translatable = FALSE,
......@@ -34,9 +35,11 @@ use Drupal\workflows\WorkflowInterface;
* "uid" = "author",
* },
* internal = TRUE,
* admin_permission = "view all scheduled transitions",
* handlers = {
* "access" = "Drupal\scheduled_transitions\ScheduledTransitionsAccessControlHandler",
* "list_builder" = "Drupal\Core\Entity\EntityListBuilder",
* "list_builder" = "Drupal\scheduled_transitions\ScheduledTransitionsListBuilder",
* "views_data" = "Drupal\scheduled_transitions\ScheduledTransitionsViewsData",
* "form" = {
* "delete" = "Drupal\Core\Entity\ContentEntityDeleteForm",
* },
......@@ -45,6 +48,7 @@ use Drupal\workflows\WorkflowInterface;
* }
* },
* links = {
* "collection" = "/admin/content/scheduled-transitions",
* "delete-form" = "/admin/scheduled-transition/{scheduled_transition}/delete",
* },
* )
......
<?php
declare(strict_types = 1);
namespace Drupal\scheduled_transitions\Plugin\views\field;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Scheduled transition from state.
*
* @ViewsField("scheduled_transitions_transition_from")
*/
class ScheduledTransitionFromStateViewsField extends FieldPluginBase {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a \Drupal\comment\Plugin\views\field\NodeNewComments object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entityTypeManager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entityTypeManager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity_type.manager')
);
}
/**
* {@inheritdoc}
*/
public function query() {
// Do nothing.
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
/** @var \Drupal\scheduled_transitions\Entity\ScheduledTransitionInterface $scheduledTransition */
$scheduledTransition = $this->getEntity($values);
$entity = $scheduledTransition->getEntity();
$workflowPlugin = $scheduledTransition->getWorkflow()->getTypePlugin();
$workflowStates = $workflowPlugin ? $workflowPlugin->getStates() : [];
$entityStorage = $this->entityTypeManager->getStorage($entity->getEntityTypeId());
$entityRevisionId = $scheduledTransition->getEntityRevisionId();
$entityRevision = $entityStorage->loadRevision($entityRevisionId);
$revisionTArgs = ['@revision_id' => $entityRevisionId];
if ($entityRevision) {
$fromState = $workflowStates[$entityRevision->moderation_state->value] ?? NULL;
return $fromState ? $fromState->label() : $this->t('- Missing from workflow/state -');
}
else {
return $this->t('Deleted revision #@revision_id', $revisionTArgs);
}
}
}
<?php
declare(strict_types = 1);
namespace Drupal\scheduled_transitions\Plugin\views\field;
use Drupal\Core\Access\AccessManagerInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\views\Plugin\views\field\LinkBase;
use Drupal\views\ResultRow;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Link to the scheduled revision.
*
* @ViewsField("scheduled_transitions_revision_link")
*/
class ScheduledTransitionRevisionLinkField extends LinkBase {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a new ScheduledTransitionRevisionLinkField.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Access\AccessManagerInterface $access_manager
* The access manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccessManagerInterface $access_manager, EntityTypeManagerInterface $entityTypeManager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $access_manager);
$this->entityTypeManager = $entityTypeManager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('access_manager'),
$container->get('entity_type.manager')
);
}
/**
* {@inheritdoc}
*/
protected function checkUrlAccess(ResultRow $row) {
/** @var \Drupal\scheduled_transitions\Entity\ScheduledTransitionInterface $scheduledTransition */
$scheduledTransition = $this->getEntity($row);
$entity = $scheduledTransition->getEntity();
if (!$entity->getEntityType()->hasLinkTemplate('revision')) {
return AccessResult::neutral('Entity does not have a revision/canonical template.');
}
return parent::checkUrlAccess($row);
}
/**
* {@inheritdoc}
*/
protected function getUrlInfo(ResultRow $row) {
/** @var \Drupal\scheduled_transitions\Entity\ScheduledTransitionInterface $scheduledTransition */
$scheduledTransition = $this->getEntity($row);
$entity = $scheduledTransition->getEntity();
$entityRevisionId = $scheduledTransition->getEntityRevisionId();
$entityRevision = $this->entityTypeManager
->getStorage($entity->getEntityTypeId())
->loadRevision($entityRevisionId);
return $entityRevision->toUrl('revision');
}
/**
* {@inheritdoc}
*/
protected function renderLink(ResultRow $row) {
/** @var \Drupal\scheduled_transitions\Entity\ScheduledTransitionInterface $scheduledTransition */
$scheduledTransition = $this->getEntity($row);
$entity = $scheduledTransition->getEntity();
$entityRevisionId = $scheduledTransition->getEntityRevisionId();
$entityRevision = $this->entityTypeManager
->getStorage($entity->getEntityTypeId())
->loadRevision($entityRevisionId);
if (!$entityRevision) {
return '';
}
// if (!$entity->getEntityType()->hasLinkTemplate('revision')) {
// return '';
// }
$text = parent::renderLink($row);
$this->options['alter']['query'] = $this->getDestinationArray();
return $text;
}
/**
* {@inheritdoc}
*/
protected function getDefaultLabel() {
return $this->t('View revision');
}
}
<?php
declare(strict_types = 1);
namespace Drupal\scheduled_transitions\Plugin\views\field;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
/**
* Scheduled transition from state.
*
* @ViewsField("scheduled_transitions_transition_to")
*/
class ScheduledTransitionToStateViewsField extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
$value = $this->getValue($values);
/** @var \Drupal\scheduled_transitions\Entity\ScheduledTransitionInterface $scheduledTransition */
$scheduledTransition = $this->getEntity($values);
$workflowPlugin = $scheduledTransition->getWorkflow()->getTypePlugin();
$workflowStates = $workflowPlugin ? $workflowPlugin->getStates() : [];
$fromState = $workflowStates[$value] ?? NULL;
return $fromState ? $fromState->label() : $this->t('- Missing to workflow/state -');
}
}
<?php
declare(strict_types = 1);
namespace Drupal\scheduled_transitions;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Scheduled transition list builder.
*/
class ScheduledTransitionsListBuilder extends EntityListBuilder {
/**
* Various date related functionality.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;
/**
* Constructs a new ScheduledTransitionsListBuilder..
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
* @param \Drupal\Core\Datetime\DateFormatterInterface $dateFormatter
* Various date related functionality.
*/
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatterInterface $dateFormatter) {
parent::__construct($entity_type, $storage);
$this->dateFormatter = $dateFormatter;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static(
$entity_type,
$container->get('entity.manager')->getStorage($entity_type->id()),
$container->get('date.formatter')
);
}
/**
* {@inheritdoc}
*/
public function load() {
$query = $this->storage->getQuery();
$header = $this->buildHeader();
$query->tableSort($header);
$ids = $query->execute();
return $this->storage->loadMultiple($ids);
}
/**
* {@inheritdoc}
*/
public function buildHeader(): array {
$header = [
'entity' => $this->t('Entity'),
'date' => [
'data' => $this->t('On date'),
'field' => 'transition_on',
'specifier' => 'transition_on',
'sort' => 'asc',
],
] + parent::buildHeader();
return $header;
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity): array {
/** @var \Drupal\scheduled_transitions\Entity\ScheduledTransitionInterface $entity */
$row = [];
$hostEntity = $entity->getEntity();
try {
$row['host_entity'] = $hostEntity ? $hostEntity->toLink() : $this->t('- Missing entity -');
}
catch (UndefinedLinkTemplateException $exception) {
$row['host_entity'] = $hostEntity->label();
}
// Date.
$time = $entity->getTransitionTime();
$row['date'] = $this->dateFormatter->format($time);
return $row + parent::buildRow($entity);
}
}
<?php
declare(strict_types = 1);
namespace Drupal\scheduled_transitions;
use Drupal\views\EntityViewsData;
/**
* Provides views data for scheduled transitions.
*/
class ScheduledTransitionsViewsData extends EntityViewsData {
/**
* {@inheritdoc}
*/
public function getViewsData(): array {
$data = parent::getViewsData();
// Create a new revision link.
$data['scheduled_transition']['entity_revision_link'] = [
'field' => [
'id' => 'scheduled_transitions_revision_link',
],
'title' => $this->t('Revision link'),
'help' => $this->t('Link to the scheduled entity revision.'),
];
// Create a new FROM field.
$data['scheduled_transition']['state_from'] = [
'field' => [
'id' => 'scheduled_transitions_transition_from',
],
'title' => $this->t('Previous State'),
'help' => $this->t('The previous state of the content.'),
];
// Override the TO moderation state field.
$data['scheduled_transition']['moderation_state']['title'] = $this->t('New State');
$data['scheduled_transition']['moderation_state']['field']['id'] = 'scheduled_transitions_transition_to';
return $data;
}
}
<?php
declare(strict_types = 1);
namespace Drupal\Tests\scheduled_transitions\Functional;
use Drupal\Core\Url;
use Drupal\entity_test_revlog\Entity\EntityTestWithRevisionLog;
use Drupal\scheduled_transitions\Entity\ScheduledTransition;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
use Drupal\user\Entity\User;
/**
* Tests the non-views global list.
*
* @group scheduled_transitions
*/
class ScheduledTransitionListTest extends BrowserTestBase {
use ContentModerationTestTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'entity_test_revlog',
'scheduled_transitions',
'content_moderation',
'workflows',
'dynamic_entity_reference',
'user',
'system',
];
/**
* Tests list.
*/
public function testList() {
$currentUser = $this->drupalCreateUser(['view all scheduled transitions']);
$this->drupalLogin($currentUser);
$url = Url::fromRoute('entity.scheduled_transition.collection');
$this->drupalGet($url);
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('There are no scheduled transitions yet.');
$workflow = $this->createEditorialWorkflow();
$workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_revlog', 'entity_test_revlog');
$workflow->save();
$entityLabel = $this->randomMachineName();
$author = User::create([
'name' => $this->randomMachineName(),
]);
$author->save();
$entity = EntityTestWithRevisionLog::create(['type' => 'entity_test_revlog']);
$entity->name = $entityLabel;
$entity->moderation_state = 'draft';
$entity->save();
$this->assertEquals(1, $entity->getRevisionId());
$newState = 'published';
$date = new \DateTime('2 Feb 2018 11am');
$scheduledTransition = ScheduledTransition::create([
'entity' => $entity,
'entity_revision_id' => 1,
'author' => $author,
'workflow' => $workflow->id(),
'moderation_state' => $newState,
'transition_on' => $date->getTimestamp(),
]);
$scheduledTransition->save();
$this->drupalGet($url);
$this->assertSession()->statusCodeEquals(200);
$tableRows = $this->cssSelect('table tbody tr');
$this->assertCount(1, $tableRows);
$row1 = $this->cssSelect('table tbody tr:nth-child(1)');
$td1 = $row1[0]->find('css', 'td:nth-child(1)');
$this->assertEquals($entityLabel, $td1->getText());
$td2 = $row1[0]->find('css', 'td:nth-child(2)');
$this->assertEquals('Fri, 02/02/2018 - 11:00', $td2->getText());
}
}
<?php
declare(strict_types = 1);
namespace Drupal\Tests\scheduled_transitions\Functional;
use Drupal\Core\Url;
use Drupal\entity_test\Entity\EntityTestMulRev;
use Drupal\scheduled_transitions\Entity\ScheduledTransition;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
use Drupal\user\Entity\User;
/**
* Tests the views global list.
*
* The view is automatically enabled when all dependencies are met (views is
* installed)
*
* @group scheduled_transitions
*/
class ScheduledTransitionViewsListTest extends BrowserTestBase {
use ContentModerationTestTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'entity_test',
'scheduled_transitions',
'content_moderation',
'workflows',
'dynamic_entity_reference',
'user',
'system',
'filter',
// Enabling views installs the view.
'views',
];
/**
* Tests list.
*/
public function testList() {
$currentUser = $this->drupalCreateUser(['view all scheduled transitions']);
$this->drupalLogin($currentUser);
$url = Url::fromRoute('entity.scheduled_transition.collection');
$workflow = $this->createEditorialWorkflow();
$workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_mulrev', 'entity_test_mulrev');
$workflow->save();
$entityLabel = $this->randomMachineName();
$author = User::create([
'name' => $this->randomMachineName(),
]);
$author->save();
$entity = EntityTestMulRev::create();
$entity->name = $entityLabel;
$entity->moderation_state = 'draft';
$entity->save();
$this->assertEquals(1, $entity->getRevisionId());
$newState = 'published';
$date = new \DateTime('2 Feb 2018 11am');
$scheduledTransition = ScheduledTransition::create([
'entity' => $entity,
'entity_revision_id' => 1,
'author' => $author,
'workflow' => $workflow->id(),
'moderation_state' => $newState,
'transition_on' => $date->getTimestamp(),
]);
$scheduledTransition->save();
$this->drupalGet($url);
$this->assertSession()->statusCodeEquals(200);
$tableRows = $this->cssSelect('table tbody tr');
$this->assertCount(1, $tableRows);
$row1 = $this->cssSelect('table tbody tr:nth-child(1)');
$td3 = $row1[0]->find('css', 'td:nth-child(3)');
$this->assertEquals('Draft', $td3->getText());
$td4 = $row1[0]->find('css', 'td:nth-child(4)');
$this->assertEquals('Published', $td4->getText());
$td5 = $row1[0]->find('css', 'td:nth-child(5)');
$this->assertEquals('Friday, February 2, 2018 - 11:00', $td5->getText());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment