View source
<?php
namespace Drupal\Tests\content_moderation\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\Node;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
class ModeratedContentViewTest extends BrowserTestBase {
use ContentModerationTestTrait;
protected $adminUser;
public static $modules = [
'content_moderation',
'node',
'views',
'language',
'content_translation',
];
protected $defaultTheme = 'stark';
public function setUp() {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
])
->save();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
])
->save();
$this
->drupalCreateContentType([
'type' => 'unmoderated_type',
'name' => 'Unmoderated type',
])
->save();
$workflow = $this
->createEditorialWorkflow();
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('node', 'page');
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('node', 'article');
$workflow
->save();
$this->adminUser = $this
->drupalCreateUser([
'access administration pages',
'view any unpublished content',
'administer nodes',
'bypass node access',
]);
}
public function testModeratedContentPage() {
$assert_sesison = $this
->assertSession();
$this
->drupalLogin($this->adminUser);
$time = \Drupal::time()
->getRequestTime();
$excluded_nodes['published_page'] = $this
->drupalCreateNode([
'type' => 'page',
'changed' => $time--,
'moderation_state' => 'published',
]);
$excluded_nodes['published_article'] = $this
->drupalCreateNode([
'type' => 'article',
'changed' => $time--,
'moderation_state' => 'published',
]);
$excluded_nodes['unmoderated_type'] = $this
->drupalCreateNode([
'type' => 'unmoderated_type',
'changed' => $time--,
]);
$excluded_nodes['unmoderated_type']
->setNewRevision(TRUE);
$excluded_nodes['unmoderated_type']
->isDefaultRevision(FALSE);
$excluded_nodes['unmoderated_type']->changed->value = $time--;
$excluded_nodes['unmoderated_type']
->save();
$nodes['published_then_draft_article'] = $this
->drupalCreateNode([
'type' => 'article',
'changed' => $time--,
'moderation_state' => 'published',
'title' => 'first article - published',
]);
$nodes['published_then_draft_article']
->setNewRevision(TRUE);
$nodes['published_then_draft_article']
->setTitle('first article - draft');
$nodes['published_then_draft_article']->moderation_state->value = 'draft';
$nodes['published_then_draft_article']->changed->value = $time--;
$nodes['published_then_draft_article']
->save();
$nodes['published_then_archived_article'] = $this
->drupalCreateNode([
'type' => 'article',
'changed' => $time--,
'moderation_state' => 'published',
]);
$nodes['published_then_archived_article']
->setNewRevision(TRUE);
$nodes['published_then_archived_article']->moderation_state->value = 'archived';
$nodes['published_then_archived_article']->changed->value = $time--;
$nodes['published_then_archived_article']
->save();
$nodes['draft_article'] = $this
->drupalCreateNode([
'type' => 'article',
'changed' => $time--,
'moderation_state' => 'draft',
]);
$nodes['draft_page_1'] = $this
->drupalCreateNode([
'type' => 'page',
'changed' => $time--,
'moderation_state' => 'draft',
]);
$nodes['draft_page_2'] = $this
->drupalCreateNode([
'type' => 'page',
'changed' => $time,
'moderation_state' => 'draft',
]);
$this
->drupalGet('admin/content/moderated');
$assert_sesison
->statusCodeEquals(200);
$node_type_labels = $this
->xpath('//td[contains(@class, "views-field-type")]');
$delta = 0;
foreach ($nodes as $node) {
$assert_sesison
->linkByHrefExists('node/' . $node
->id());
$assert_sesison
->linkByHrefExists('node/' . $node
->id() . '/edit');
$assert_sesison
->linkByHrefExists('node/' . $node
->id() . '/delete');
$this
->assertEquals($node->type->entity
->label(), trim($node_type_labels[$delta]
->getText()));
$delta++;
}
foreach ($excluded_nodes as $node) {
$assert_sesison
->linkByHrefNotExists('node/' . $node
->id());
}
$assert_sesison
->pageTextContains('first article - draft');
$assert_sesison
->pageTextNotContains('first article - published');
$this
->drupalGet('admin/content/moderated', [
'query' => [
'moderation_state' => 'editorial-draft',
],
]);
$assert_sesison
->linkByHrefExists('node/' . $nodes['published_then_draft_article']
->id() . '/edit');
$assert_sesison
->linkByHrefExists('node/' . $nodes['draft_article']
->id() . '/edit');
$assert_sesison
->linkByHrefExists('node/' . $nodes['draft_page_1']
->id() . '/edit');
$assert_sesison
->linkByHrefExists('node/' . $nodes['draft_page_1']
->id() . '/edit');
$assert_sesison
->linkByHrefNotExists('node/' . $nodes['published_then_archived_article']
->id() . '/edit');
$this
->drupalGet('admin/content/moderated', [
'query' => [
'moderation_state' => 'editorial-draft',
'type' => 'page',
],
]);
$assert_sesison
->linkByHrefExists('node/' . $nodes['draft_page_1']
->id() . '/edit');
$assert_sesison
->linkByHrefExists('node/' . $nodes['draft_page_2']
->id() . '/edit');
$assert_sesison
->linkByHrefNotExists('node/' . $nodes['published_then_draft_article']
->id() . '/edit');
$assert_sesison
->linkByHrefNotExists('node/' . $nodes['published_then_archived_article']
->id() . '/edit');
$assert_sesison
->linkByHrefNotExists('node/' . $nodes['draft_article']
->id() . '/edit');
}
public function testModeratedContentPageMultilingual() {
ConfigurableLanguage::createFromLangcode('fr')
->save();
$node = $this
->drupalCreateNode([
'type' => 'article',
'moderation_state' => 'published',
'title' => 'en article published',
]);
$node->title = 'en draft revision';
$node->moderation_state = 'draft';
$node
->save();
$translation = Node::load($node
->id())
->addTranslation('fr');
$translation->title = 'fr draft revision';
$translation->moderation_state = 'draft';
$translation
->save();
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/content/moderated');
$this
->assertSession()
->linkExists('fr draft revision');
$this
->assertSession()
->linkExists('en draft revision');
}
}