You are here

public function PublishContentWebTestBase::testPublishUnpublish in Publish Content 7

Test the combination of both publish and unpublish.

File

tests/publishcontent.test, line 328
Unit tests for Publish Content module.

Class

PublishContentWebTestBase
We test to ensure we are not messing up with the default Drupal access for view node i.e. a owner of a node can view it even if unpublished.

Code

public function testPublishUnpublish() {
  $type = 'page';
  $this
    ->enablePublishContentForContentType($type);
  $web_user_1 = $this
    ->drupalCreateUser(array(
    'access content',
    'view own unpublished content',
    'edit any ' . $type . ' content',
    'publish any content',
  ));
  $node1 = $this
    ->drupalCreateNode(array(
    'type' => $type,
    'uid' => $web_user_1->uid,
    'status' => 1,
  ));
  $this
    ->drupalLogin($web_user_1);
  $this
    ->assertCurrentUserCanPublish($node1);
  $this
    ->assertCurrentUserCannotUnpublish($node1);
  $web_user_2 = $this
    ->drupalCreateUser(array(
    'access content',
    'view own unpublished content',
    'edit any ' . $type . ' content',
    'unpublish any content',
  ));
  $node2 = $this
    ->drupalCreateNode(array(
    'type' => $type,
    'uid' => $web_user_2->uid,
    'status' => 1,
  ));
  $this
    ->drupalLogin($web_user_2);
  $this
    ->assertCurrentUserCannotPublish($node2);
  $this
    ->assertCurrentUserCanUnpublish($node2);
  $web_user_3 = $this
    ->drupalCreateUser(array(
    'access content',
    'view own unpublished content',
    'edit any ' . $type . ' content',
    'publish any content',
    'unpublish any content',
  ));
  $node3 = $this
    ->drupalCreateNode(array(
    'type' => $type,
    'uid' => $web_user_3->uid,
    'status' => 1,
  ));
  $this
    ->drupalLogin($web_user_3);
  $this
    ->assertCurrentUserCanPublish($node3);
  $this
    ->assertCurrentUserCanUnpublish($node3);
}