View source
<?php
namespace Drupal\Tests\moderation_dashboard\Functional;
class ModerationDashboardPersonalizedComponentsTest extends ModerationDashboardTestBase {
protected $moderatorUser;
protected $regularUser;
protected $personalizedModerationElements = [
'.view-id-content_moderation_dashboard_in_review.view-display-id-block_3' => [
'contains' => [
'Draft node of %s',
],
'not_contains' => [
'Published node of %s',
],
'empty' => 'No draft content was found.',
],
'.view-id-moderation_dashboard_recent_changes.view-display-id-block_2' => [
'contains' => [
'Published node of %s',
'Draft node of %s',
],
'empty' => 'Activity log is empty.',
],
'.view-id-moderation_dashboard_recently_created.view-display-id-block_2' => [
'contains' => [
'Published node of %s',
'Draft node of %s',
],
'empty' => 'No content was found.',
],
];
protected function setUp() {
parent::setUp();
$this->moderatorUser = $this
->createUser($this->userPermissions, 'moderator user');
$this->regularUser = $this
->createUser([
'access content',
'use moderation dashboard',
], 'regular user');
foreach ([
$this->user,
$this->moderatorUser,
$this->regularUser,
] as $user) {
$this
->drupalCreateNode([
'title' => 'Draft node of ' . $user
->getDisplayName(),
'moderation_state' => 'draft',
'uid' => $user
->id(),
]);
$this
->drupalCreateNode([
'title' => 'Published node of ' . $user
->getDisplayName(),
'moderation_state' => 'published',
'uid' => $user
->id(),
]);
}
$this
->drupalLogin($this->user);
}
public function testModerationElement() {
$users = [
$this->user,
$this->moderatorUser,
$this->regularUser,
];
foreach ($users as $delta => $user) {
$this
->drupalGet('/user/' . $user
->id() . '/moderation/dashboard');
foreach ($this->personalizedModerationElements as $selector => $asserts) {
$moderation_element = $this
->assertSession()
->elementExists('css', $selector);
$moderation_element_text = $moderation_element
->getText();
if (!empty($asserts['empty'])) {
$this
->assertSame(FALSE, strpos($moderation_element_text, $asserts['empty']));
}
if (!empty($asserts['contains'])) {
foreach ($asserts['contains'] as $pattern_to_find) {
$this
->assertNotSame(FALSE, strpos($moderation_element_text, sprintf($pattern_to_find, $user
->getDisplayName())));
}
}
if (!empty($asserts['not_contains'])) {
foreach ($asserts['not_contains'] as $pattern_shoud_not_find) {
$this
->assertSame(FALSE, strpos($moderation_element_text, sprintf($pattern_shoud_not_find, $user
->getDisplayName())));
}
}
$other_users = $users;
unset($other_users[$delta]);
foreach ($other_users as $other_user) {
$this
->assertSame(FALSE, strpos($moderation_element
->getText(), sprintf('%s', $other_user
->getDisplayName())));
}
}
}
$user_without_content = $this
->createUser([
'access content',
'use moderation dashboard',
]);
$this
->drupalGet('/user/' . $user_without_content
->id() . '/moderation/dashboard');
foreach ($this->personalizedModerationElements as $selector => $asserts) {
$moderation_element = $this
->assertSession()
->elementExists('css', $selector);
if (!empty($asserts['empty'])) {
$this
->assertNotSame(FALSE, strpos($moderation_element
->getText(), $asserts['empty']));
}
}
}
}