PrintableBlockTest.php in Printer and PDF versions for Drupal 8+ 8
File
src/Tests/PrintableBlockTest.php
View source
<?php
namespace Drupal\printable\Tests;
use Drupal\node\Tests\NodeTestBase;
use Drupal\block\Entity\Block;
class PrintableBlockTest extends NodeTestBase {
protected $adminUser;
public static $modules = [
'printable',
'block',
'views',
];
public function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'administer content types',
'administer nodes',
'administer blocks',
'access content overview',
]);
$this->webUser = $this
->drupalCreateUser([
'access content',
'create article content',
]);
}
public function testPrintableBlock() {
$this
->drupalLogin($this->adminUser);
$edit = [
'id' => strtolower($this
->randomMachineName()),
'settings[label]' => $this
->randomMachineName(8),
'region' => 'sidebar_first',
'visibility[node_type][bundles][article]' => 'article',
];
$theme = \Drupal::service('theme_handler')
->getDefault();
$this
->drupalPostForm("admin/structure/block/add/printable_links_block%3Anode/{$theme}", $edit, t('Save block'));
$block = Block::load($edit['id']);
$visibility = $block
->getVisibility();
$this
->assertTrue(isset($visibility['node_type']['bundles']['article']), 'Visibility settings were saved to configuration');
$this
->drupalGet('admin/structure/block/manage/' . $edit['id']);
$this
->clickLink(t('Delete'));
$this
->assertRaw(t('Are you sure you want to delete the block %name?', [
'%name' => $edit['settings[label]'],
]));
$this
->drupalPostForm(NULL, [], t('Delete'));
$this
->assertRaw(t('The block %name has been deleted.', [
'%name' => $edit['settings[label]'],
]));
}
}