PublishedStateConstraintTest.php in Scheduler content moderation integration 8
File
tests/src/Kernel/PublishedStateConstraintTest.php
View source
<?php
namespace Drupal\Tests\scheduler_content_moderation_integration\Kernel;
use Drupal\node\Entity\Node;
class PublishedStateConstraintTest extends SchedulerContentModerationTestBase {
protected function setUp() {
parent::setUp();
$user = $this
->createMock('Drupal\\Core\\Session\\AccountInterface');
$user
->method('hasPermission')
->willReturn(TRUE);
$this->container
->set('current_user', $user);
}
public function testValidPublishStateTransition() {
$node = Node::create([
'type' => 'example',
'title' => 'Test title',
'moderation_state' => 'draft',
'publish_on' => strtotime('tomorrow'),
'publish_state' => 'published',
]);
$violations = $node
->validate();
$this
->assertCount(0, $violations);
}
public function testInvalidPublishStateTransition() {
$node = Node::create([
'type' => 'example',
'title' => 'Test title',
'moderation_state' => 'draft',
'publish_on' => strtotime('tomorrow'),
'publish_state' => 'archived',
]);
$violations = $node
->validate();
$this
->assertEquals('The scheduled publishing state of <em class="placeholder">archived</em> is not a valid transition from the current moderation state of <em class="placeholder">draft</em> for this content.', $violations
->get(0)
->getMessage());
}
}