View source
<?php
namespace Drupal\Tests\scheduler\Functional;
class SchedulerScheduledContentListAccessTest extends SchedulerBrowserTestBase {
protected static $modules = [
'views',
];
protected function setUp() : void {
parent::setUp();
$base_permissions = [
'access content',
'create ' . $this->type . ' content',
'view own unpublished content',
];
$this->editorUser = $this
->drupalCreateUser(array_merge($base_permissions, [
'access content overview',
]));
$this->schedulerUser = $this
->drupalCreateUser(array_merge($base_permissions, [
'schedule publishing of nodes',
]));
$this->schedulerManager = $this
->drupalCreateUser(array_merge($base_permissions, [
'view scheduled content',
]));
$this->node1 = $this
->drupalCreateNode([
'title' => 'Node created by Scheduler User for publishing',
'uid' => $this->schedulerUser
->id(),
'status' => FALSE,
'type' => $this->type,
'publish_on' => strtotime('+1 week'),
]);
$this->node2 = $this
->drupalCreateNode([
'title' => 'Node created by Scheduler User for unpublishing',
'uid' => $this->schedulerUser
->id(),
'status' => TRUE,
'type' => $this->type,
'unpublish_on' => strtotime('+1 week'),
]);
$this->node3 = $this
->drupalCreateNode([
'title' => 'Node created by Scheduler Manager for publishing',
'uid' => $this->schedulerManager
->id(),
'status' => FALSE,
'type' => $this->type,
'publish_on' => strtotime('+1 week'),
]);
$this->node4 = $this
->drupalCreateNode([
'title' => 'Node created by Scheduler Manager for unpublishing',
'uid' => $this->schedulerManager
->id(),
'status' => TRUE,
'type' => $this->type,
'unpublish_on' => strtotime('+1 week'),
]);
}
public function testViewScheduledContentUser() {
$assert = $this
->assertSession();
$this
->drupalGet("user/{$this->schedulerUser->id()}/scheduled");
$assert
->statusCodeEquals(403);
$this
->drupalLogin($this->editorUser);
$this
->drupalGet("user/{$this->editorUser->id()}/scheduled");
$assert
->statusCodeEquals(403);
$this
->drupalLogin($this->schedulerUser);
$this
->drupalGet("user/{$this->schedulerUser->id()}/scheduled");
$assert
->statusCodeEquals(200);
$assert
->pageTextContains('Node created by Scheduler User for publishing');
$assert
->pageTextContains('Node created by Scheduler User for unpublishing');
$assert
->pageTextNotContains('Node created by Scheduler Manager for unpublishing');
$this
->drupalGet("user/{$this->schedulerManager->id()}/scheduled");
$assert
->statusCodeEquals(403);
$this
->drupalLogin($this->schedulerManager);
$this
->drupalGet("user/{$this->schedulerManager->id()}/scheduled");
$assert
->statusCodeEquals(200);
$assert
->pageTextContains('Node created by Scheduler Manager for publishing');
$assert
->pageTextContains('Node created by Scheduler Manager for unpublishing');
$assert
->pageTextNotContains('Node created by Scheduler User for unpublishing');
$this
->drupalGet("user/{$this->schedulerUser->id()}/scheduled");
$assert
->statusCodeEquals(200);
$assert
->pageTextContains('Node created by Scheduler User for publishing');
$assert
->pageTextContains('Node created by Scheduler User for unpublishing');
}
public function testViewScheduledContentOverview() {
$assert = $this
->assertSession();
$this
->drupalGet('admin/content/scheduled');
$assert
->statusCodeEquals(403);
$this
->drupalLogin($this->editorUser);
$this
->drupalGet('admin/content/scheduled');
$assert
->statusCodeEquals(403);
$this
->drupalLogin($this->schedulerUser);
$this
->drupalGet('admin/content/scheduled');
$assert
->statusCodeEquals(403);
$this
->drupalLogin($this->schedulerManager);
$this
->drupalGet('admin/content/scheduled');
$assert
->statusCodeEquals(200);
$assert
->pageTextContains('Node created by Scheduler User for publishing');
$assert
->pageTextContains('Node created by Scheduler User for unpublishing');
$assert
->pageTextContains('Node created by Scheduler Manager for publishing');
$assert
->pageTextContains('Node created by Scheduler Manager for unpublishing');
}
}