View source
<?php
namespace Drupal\Tests\scheduler\Functional;
class SchedulerPermissionsTest extends SchedulerBrowserTestBase {
public function testUserPermissionsAdd() {
$this->webUser = $this
->drupalCreateUser([
'access content',
'administer nodes',
'create ' . $this->type . ' content',
'edit own ' . $this->type . ' content',
'delete own ' . $this->type . ' content',
'view own unpublished content',
]);
$this
->drupalLogin($this->webUser);
$this
->drupalGet('node/add/' . $this->type);
$this
->assertSession()
->fieldNotExists('publish_on[0][value][date]');
$this
->assertSession()
->fieldNotExists('unpublish_on[0][value][date]');
$this->nodetype
->setThirdPartySetting('scheduler', 'publish_required', FALSE)
->setThirdPartySetting('scheduler', 'unpublish_required', FALSE)
->save();
$title = $this
->randomString(15);
$edit = [
'title[0][value]' => $title,
'status[value]' => TRUE,
];
$this
->drupalPostForm('node/add/' . $this->type, $edit, 'Save');
$this
->assertSession()
->pageTextContains(sprintf('%s %s has been created.', $this->typeName, $title));
$this
->assertTrue($this
->drupalGetNodeByTitle($title)
->isPublished(), 'The new node is published');
$title = $this
->randomString(15);
$edit = [
'title[0][value]' => $title,
'status[value]' => FALSE,
];
$this
->drupalPostForm('node/add/' . $this->type, $edit, 'Save');
$this
->assertSession()
->pageTextContains(sprintf('%s %s has been created.', $this->typeName, $title));
$this
->assertFalse($this
->drupalGetNodeByTitle($title)
->isPublished(), 'The new node is unpublished');
$this->nodetype
->setThirdPartySetting('scheduler', 'publish_required', TRUE)
->setThirdPartySetting('scheduler', 'unpublish_required', TRUE)
->save();
}
public function testUserPermissionsEdit() {
$this->webUser = $this
->drupalCreateUser([
'access content',
'administer nodes',
'create ' . $this->type . ' content',
'edit own ' . $this->type . ' content',
'delete own ' . $this->type . ' content',
'view own unpublished content',
]);
$this
->drupalLogin($this->webUser);
$publish_time = strtotime('+ 6 hours', $this->requestTime);
$unpublish_time = strtotime('+ 10 hours', $this->requestTime);
$unpublished_node = $this
->drupalCreateNode([
'type' => $this->type,
'status' => FALSE,
'publish_on' => $publish_time,
]);
$published_node = $this
->drupalCreateNode([
'type' => $this->type,
'status' => TRUE,
'unpublish_on' => $unpublish_time,
]);
$this
->assertEquals($publish_time, $unpublished_node->publish_on->value, 'The publish_on value is stored correctly before edit.');
$title = 'For Publishing ' . $this
->randomString(10);
$this
->drupalPostForm('node/' . $unpublished_node
->id() . '/edit', [
'title[0][value]' => $title,
], 'Save');
$unpublished_node = $this->nodeStorage
->load($unpublished_node
->id());
$this
->assertEquals($title, $unpublished_node->title->value, 'The unpublished node title has been updated correctly after edit.');
$this
->assertEquals($publish_time, $unpublished_node->publish_on->value, 'The node publish_on value is still stored correctly after edit.');
$this
->assertEquals($unpublish_time, $published_node->unpublish_on->value, 'The unpublish_on value is stored correctly before edit.');
$title = 'For Unpublishing ' . $this
->randomString(10);
$this
->drupalPostForm('node/' . $published_node
->id() . '/edit', [
'title[0][value]' => $title,
], 'Save');
$published_node = $this->nodeStorage
->load($published_node
->id());
$this
->assertEquals($title, $published_node->title->value, 'The published node title has been updated correctly after edit.');
$this
->assertEquals($unpublish_time, $published_node->unpublish_on->value, 'The node unpublish_on value is still stored correctly after edit.');
}
}