UnpublishedBlockTest.php in Drupal 10
File
core/modules/block_content/tests/src/Functional/UnpublishedBlockTest.php
View source
<?php
namespace Drupal\Tests\block_content\Functional;
use Drupal\block_content\Entity\BlockContent;
use Drupal\Tests\block\Traits\BlockCreationTrait;
use Drupal\Tests\BrowserTestBase;
class UnpublishedBlockTest extends BrowserTestBase {
use BlockCreationTrait;
protected static $modules = [
'block_content',
];
protected $defaultTheme = 'stark';
public function testViewShowsCorrectStates() {
$block_content = BlockContent::create([
'info' => 'Test block',
'type' => 'basic',
]);
$block_content
->save();
$block = $this
->placeBlock('block_content:' . $block_content
->uuid());
$this
->drupalGet('<front>');
$page = $this
->getSession()
->getPage();
$this
->assertTrue($page
->has('css', '#block-' . $block
->id()));
$block_content
->setUnpublished();
$block_content
->save();
$this
->drupalGet('<front>');
$page = $this
->getSession()
->getPage();
$this
->assertFalse($page
->has('css', '#block-' . $block
->id()));
}
}