View source
<?php
namespace Drupal\workbench_moderation\Tests;
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($latest_version_path);
$this
->assertResponse(403);
$this
->drupalPostForm($edit_path, [
'body[0][value]' => 'Second version of the content.',
], t('Save and Request Review'));
$this
->drupalGet($latest_version_path);
$this
->assertResponse(403);
$this
->drupalPostForm($edit_path, [
'body[0][value]' => 'Third version of the content.',
], t('Save and Publish'));
$this
->drupalGet($canonical_path);
$this
->assertResponse(200);
$this
->assertNoText('Status', 'The node view page has no moderation form.');
$this
->drupalGet($latest_version_path);
$this
->assertResponse(403);
$this
->drupalPostForm($edit_path, [
'body[0][value]' => 'Fourth version of the content.',
], t('Save and Create New Draft'));
$this
->drupalGet($canonical_path);
$this
->assertResponse(200);
$this
->assertNoText('Status', 'The node view page has no moderation form.');
$this
->drupalGet($latest_version_path);
$this
->assertResponse(200);
$this
->assertText('Status', 'Form text found on the latest-version page.');
$this
->assertText('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
->assertResponse(200);
$this
->assertText('Status', 'Form text found on the latest-version page.');
$this
->assertText('Needs Review', 'Correct status found on the latest-version page.');
}
}