View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\scheduled_transitions\Functional;
use Drupal\scheduled_transitions\Routing\ScheduledTransitionsRouteProvider;
use Drupal\scheduled_transitions_test\Entity\ScheduledTransitionsTestEntity;
use Drupal\scheduled_transitions_test\Entity\ScheduledTransitionsTestNoRevisionTemplateEntity;
use Drupal\scheduled_transitions\ScheduledTransitionsPermissions as Permissions;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
use Drupal\Tests\scheduled_transitions\Traits\ScheduledTransitionTestTrait;
class ScheduledTransitionModalFormTest extends BrowserTestBase {
use ContentModerationTestTrait;
use ScheduledTransitionTestTrait;
protected static $modules = [
'entity_test_revlog',
'scheduled_transitions_target_revisions_test',
'scheduled_transitions_test',
'scheduled_transitions',
'content_moderation',
'workflows',
'dynamic_entity_reference',
'user',
'system',
];
protected $defaultTheme = 'classy';
public function testRevisionLogHtml() {
$this
->enabledBundles([
[
'st_entity_test',
'st_entity_test',
],
]);
$workflow = $this
->createEditorialWorkflow();
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('st_entity_test', 'st_entity_test');
$workflow
->save();
$currentUser = $this
->drupalCreateUser([
'administer st_entity_test entities',
'use editorial transition create_new_draft',
'use editorial transition publish',
'use editorial transition archive',
Permissions::addScheduledTransitionsPermission('st_entity_test', 'st_entity_test'),
]);
$this
->drupalLogin($currentUser);
$entity = ScheduledTransitionsTestEntity::create([
'type' => 'st_entity_test',
]);
$logMessage = '<strong>Hello world</strong>';
$entity
->setRevisionLogMessage($logMessage);
$entity
->save();
$this
->drupalGet($entity
->toUrl());
$this
->drupalGet($entity
->toUrl(ScheduledTransitionsRouteProvider::LINK_TEMPLATE_ADD));
$this
->assertSession()
->responseContains($logMessage);
}
public function testNoRevisionLinkTemplate() {
$this
->enabledBundles([
[
'st_entity_test_norevtemplate',
'st_entity_test_norevtemplate',
],
]);
$workflow = $this
->createEditorialWorkflow();
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('st_entity_test_norevtemplate', 'st_entity_test_norevtemplate');
$workflow
->save();
$currentUser = $this
->drupalCreateUser([
'administer st_entity_test_norevtemplate entities',
'use editorial transition create_new_draft',
'use editorial transition publish',
'use editorial transition archive',
'add scheduled transitions st_entity_test_norevtemplate st_entity_test_norevtemplate',
]);
$this
->drupalLogin($currentUser);
$entity = ScheduledTransitionsTestNoRevisionTemplateEntity::create([
'type' => 'st_entity_test_norevtemplate',
]);
$entity
->save();
$entity
->setNewRevision(TRUE);
$entity
->setRevisionLogMessage('test rev log msg');
$entity
->save();
$this
->assertFalse($entity
->getEntityType()
->hasLinkTemplate('revision'));
$this
->drupalGet($entity
->toUrl(ScheduledTransitionsRouteProvider::LINK_TEMPLATE_ADD));
$this
->assertSession()
->statusCodeEquals(200);
}
public function testLatestOptionPreselected() {
$this
->enabledBundles([
[
'st_entity_test',
'st_entity_test',
],
]);
$workflow = $this
->createEditorialWorkflow();
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('st_entity_test', 'st_entity_test');
$workflow
->save();
$currentUser = $this
->drupalCreateUser([
'administer st_entity_test entities',
'use editorial transition create_new_draft',
'use editorial transition publish',
'use editorial transition archive',
Permissions::addScheduledTransitionsPermission('st_entity_test', 'st_entity_test'),
]);
$this
->drupalLogin($currentUser);
$entity = ScheduledTransitionsTestEntity::create([
'type' => 'st_entity_test',
]);
$entity
->setNewRevision();
$entity
->save();
$revisionId = $entity
->getRevisionId();
$this
->drupalGet($entity
->toUrl());
$this
->drupalGet($entity
->toUrl(ScheduledTransitionsRouteProvider::LINK_TEMPLATE_ADD));
$this
->assertSession()
->checkboxNotChecked('edit-revision-' . $revisionId);
$this
->assertSession()
->checkboxChecked('edit-revision-latest-revision');
}
public function testAlterTargetRevisionIds() {
$this
->enabledBundles([
[
'st_entity_test',
'st_entity_test',
],
]);
$workflow = $this
->createEditorialWorkflow();
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('st_entity_test', 'st_entity_test');
$workflow
->save();
$currentUser = $this
->drupalCreateUser([
'administer st_entity_test entities',
'use editorial transition create_new_draft',
'use editorial transition publish',
'use editorial transition archive',
Permissions::addScheduledTransitionsPermission('st_entity_test', 'st_entity_test'),
]);
$this
->drupalLogin($currentUser);
$entity = ScheduledTransitionsTestEntity::create([
'type' => 'st_entity_test',
]);
$entity->name = 'rev 1';
$entity
->setNewRevision();
$entity
->setRevisionCreationTime((new \DateTime('1st June 2015'))
->getTimestamp());
$entity
->setRevisionLogMessage('June 2015 Revision');
$entity
->save();
$entity->name = 'rev 2';
$entity
->setNewRevision();
$entity
->setRevisionCreationTime((new \DateTime('1st August 2015'))
->getTimestamp());
$entity
->setRevisionLogMessage('August 2015 Revision');
$entity
->save();
$this
->drupalGet($entity
->toUrl(ScheduledTransitionsRouteProvider::LINK_TEMPLATE_ADD));
$this
->assertSession()
->pageTextNotContains('June 2015 Revision');
$this
->assertSession()
->pageTextContains('August 2015 Revision');
}
}