View source
<?php
namespace Drupal\Tests\workbench_moderation\Functional;
class ModerationFormTest extends ModerationStateTestBase {
protected function setUp() {
parent::setUp();
$this
->drupalLogin($this->adminUser);
$this
->createContentTypeFromUi('Moderated content', 'moderated_content', TRUE, [
'draft',
'needs_review',
'published',
], 'draft');
$this
->grantUserPermissionToCreateContentOfType($this->adminUser, 'moderated_content');
}
public function testModerationForm() {
$this
->drupalPostForm('node/add/moderated_content', [
'title[0][value]' => 'Some moderated content',
'body[0][value]' => 'First version of the content.',
], t('Save and Create New Draft'));
$node = $this
->drupalGetNodeByTitle('Some moderated content');
$canonical_path = sprintf('node/%d', $node
->id());
$edit_path = sprintf('node/%d/edit', $node
->id());
$latest_version_path = sprintf('node/%d/latest', $node
->id());
$this
->assertTrue($this->adminUser
->hasPermission('edit any moderated_content content'));
$this
->drupalGet($canonical_path);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertField('edit-new-state', 'The node view page has a moderation form.');
$this
->drupalGet($latest_version_path);
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalPostForm($edit_path, [
'body[0][value]' => 'Second version of the content.',
], t('Save and Request Review'));
$this
->drupalGet($canonical_path);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertField('edit-new-state', 'The node view page has a moderation form.');
$this
->drupalGet($latest_version_path);
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalPostForm($edit_path, [
'body[0][value]' => 'Third version of the content.',
], t('Save and Publish'));
$this
->drupalGet($canonical_path);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertNoField('edit-new-state', 'The node view page has no moderation form.');
$this
->drupalGet($latest_version_path);
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalPostForm($edit_path, [
'body[0][value]' => 'Fourth version of the content.',
], t('Save and Create New Draft'));
$this
->drupalGet($canonical_path);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertNoField('edit-new-state', 'The node view page has no moderation form.');
$this
->drupalGet($latest_version_path);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertField('edit-new-state', 'The latest-version page has a moderation form.');
$this
->assertSession()
->pageTextContains('Draft', 'Correct status found on the latest-version page.');
$this
->drupalPostForm($latest_version_path, [
'new_state' => 'needs_review',
], t('Apply'));
$this
->drupalGet($latest_version_path);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertField('edit-new-state', 'The latest-version page has a moderation form.');
$this
->assertSession()
->pageTextContains('Needs Review', 'Correct status found on the latest-version page.');
}
public function testModerationFormSetsRevisionAuthor() {
$node = $this
->createNode([
'type' => 'moderated_content',
'moderation_state' => 'published',
]);
$node->moderation_state->target_id = 'draft';
$node
->save();
$another_user = $this
->drupalCreateUser($this->permissions);
$this
->grantUserPermissionToCreateContentOfType($another_user, 'moderated_content');
$this
->drupalLogin($another_user);
$this
->drupalPostForm(sprintf('node/%d/latest', $node
->id()), [
'new_state' => 'needs_review',
], t('Apply'));
$this
->drupalGet(sprintf('node/%d/revisions', $node
->id()));
$this
->assertSession()
->pageTextContains('by ' . $another_user
->getAccountName());
}
}