StatusExtraTest.php in Drupal 9
File
core/modules/node/tests/src/Functional/Views/StatusExtraTest.php
View source
<?php
namespace Drupal\Tests\node\Functional\Views;
use Drupal\node\NodeInterface;
class StatusExtraTest extends NodeTestBase {
protected static $modules = [
'node_test_views',
'content_moderation',
];
protected $defaultTheme = 'stark';
public static $testViews = [
'test_status_extra',
];
public function testStatusExtra() {
$node_author = $this
->drupalCreateUser([
'view own unpublished content',
]);
$node_author_not_unpublished = $this
->drupalCreateUser();
$normal_user = $this
->drupalCreateUser();
$privileged_user = $this
->drupalCreateUser([
'view any unpublished content',
]);
$admin_user = $this
->drupalCreateUser([
'bypass node access',
]);
$node_published = $this
->drupalCreateNode([
'uid' => $admin_user
->id(),
]);
$node_unpublished = $this
->drupalCreateNode([
'uid' => $admin_user
->id(),
'status' => NodeInterface::NOT_PUBLISHED,
]);
$node_unpublished2 = $this
->drupalCreateNode([
'uid' => $node_author
->id(),
'status' => NodeInterface::NOT_PUBLISHED,
]);
$node_unpublished3 = $this
->drupalCreateNode([
'uid' => $node_author_not_unpublished
->id(),
'status' => NodeInterface::NOT_PUBLISHED,
]);
$this
->drupalLogin($admin_user);
$this
->drupalGet('test_status_extra');
$this
->assertSession()
->pageTextContains($node_published
->label());
$this
->assertSession()
->pageTextContains($node_unpublished
->label());
$this
->assertSession()
->pageTextContains($node_unpublished2
->label());
$this
->assertSession()
->pageTextContains($node_unpublished3
->label());
$this
->drupalLogin($privileged_user);
$this
->drupalGet('test_status_extra');
$this
->assertSession()
->pageTextContains($node_published
->label());
$this
->assertSession()
->pageTextContains($node_unpublished
->label());
$this
->assertSession()
->pageTextContains($node_unpublished2
->label());
$this
->assertSession()
->pageTextContains($node_unpublished3
->label());
$this
->drupalLogin($node_author);
$this
->drupalGet('test_status_extra');
$this
->assertSession()
->pageTextContains($node_published
->label());
$this
->assertSession()
->pageTextNotContains($node_unpublished
->label());
$this
->assertSession()
->pageTextContains($node_unpublished2
->label());
$this
->assertSession()
->pageTextNotContains($node_unpublished3
->label());
$this
->drupalLogin($normal_user);
$this
->drupalGet('test_status_extra');
$this
->assertSession()
->pageTextContains($node_published
->label());
$this
->assertSession()
->pageTextNotContains($node_unpublished
->label());
$this
->assertSession()
->pageTextNotContains($node_unpublished2
->label());
$this
->assertSession()
->pageTextNotContains($node_unpublished3
->label());
$this
->drupalLogin($node_author_not_unpublished);
$this
->drupalGet('test_status_extra');
$this
->assertSession()
->pageTextContains($node_published
->label());
$this
->assertSession()
->pageTextNotContains($node_unpublished
->label());
$this
->assertSession()
->pageTextNotContains($node_unpublished2
->label());
$this
->assertSession()
->pageTextNotContains($node_unpublished3
->label());
}
}