View source
<?php
namespace Drupal\Tests\workbench_moderation\Functional;
use Drupal\Core\Url;
use Drupal\node\Entity\Node;
class ModerationStateNodeTest 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 testCreatingContent() {
$this
->drupalPostForm('node/add/moderated_content', [
'title[0][value]' => 'moderated content',
], t('Save and Create New Draft'));
$nodes = \Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties([
'title' => 'moderated content',
]);
if (!$nodes) {
$this
->fail('Test node was not saved correctly.');
return;
}
$node = reset($nodes);
$path = 'node/' . $node
->id() . '/edit';
$this
->drupalPostForm($path, [], t('Save and Request Review'));
$this
->drupalPostForm($path, [], t('Save and Publish'));
\Drupal::entityTypeManager()
->getStorage('node')
->resetCache([
$node
->id(),
]);
$node = \Drupal::entityTypeManager()
->getStorage('node')
->load($node
->id());
$this
->assertTrue($node
->isPublished());
$this
->assertNoText('Published');
$this
->drupalPostForm('node/' . $node
->id() . '/delete', [], t('Delete'));
$this
->assertSession()
->pageTextContains(t('The Moderated content moderated content has been deleted.'));
}
public function testFormSaveDestination() {
$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');
$edit_path = sprintf('node/%d/edit', $node
->id());
$this
->assertUrl(Url::fromRoute('entity.node.canonical', [
'node' => $node
->id(),
]));
$this
->assertSession()
->pageTextContains('First version of the content.');
$this
->drupalPostForm($edit_path, [
'body[0][value]' => 'Second version of the content.',
], t('Save and Request Review'));
$this
->assertUrl(Url::fromRoute('entity.node.canonical', [
'node' => $node
->id(),
]));
$this
->assertSession()
->pageTextContains('Second version of the content.');
$this
->drupalPostForm($edit_path, [
'body[0][value]' => 'Third version of the content.',
], t('Save and Publish'));
$this
->assertUrl(Url::fromRoute('entity.node.canonical', [
'node' => $node
->id(),
]));
$this
->assertSession()
->pageTextContains('Third version of the content.');
$this
->drupalPostForm($edit_path, [
'body[0][value]' => 'Fourth version of the content.',
], t('Save and Create New Draft'));
$this
->assertUrl(Url::fromRoute('entity.node.latest_version', [
'node' => $node
->id(),
]));
$this
->assertSession()
->pageTextContains('Fourth version of the content.');
}
public function testPagers() {
foreach (range(1, 51) as $delta) {
Node::create([
'type' => 'moderated_content',
'uid' => $this->adminUser
->id(),
'title' => 'Node ' . $delta,
'status' => 1,
'moderation_state' => 'published',
])
->save();
}
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/content');
$element = $this
->cssSelect('nav.pager li.is-active a');
$url = $element[0]
->getAttribute('href');
$query = [];
parse_str(parse_url($url, PHP_URL_QUERY), $query);
$this
->assertEquals(0, $query['page']);
}
}