View source
<?php
namespace Drupal\simplify\Tests;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\Tests\BrowserTestBase;
class PerBlockTypeSettingsTest extends BrowserTestBase {
public static $modules = [
'block_content',
'editor',
'simplify',
];
public static function getInfo() {
return [
'name' => 'Simplify per block-type settings test.',
'description' => 'Test the Simplify per block-type settings.',
'group' => 'Simplify',
];
}
protected function setUp() {
parent::setUp();
$admin_user = $this
->drupalCreateUser([], NULL, TRUE);
$this
->drupalLogin($admin_user);
$this
->createBlockContentType('testing_type', TRUE);
}
public function testSettingSaving() {
$this
->drupalGet('block/add');
$this
->assertRaw('About text formats', 'Text format option is defined.');
$this
->assertRaw('Revision information', 'Revision option is defined.');
$this
->drupalGet('admin/config/user-interface/simplify');
$options = [
'simplify_admin' => TRUE,
'simplify_blocks_global[format]' => 'format',
];
$this
->drupalPostForm(NULL, $options, $this
->t('Save configuration'));
$this
->assertFieldChecked('edit-simplify-admin', "Admin users can't see hidden fields too.");
$this
->drupalGet('admin/structure/block/block-content/manage/testing_type');
$this
->assertFieldChecked('edit-simplify-blocks-format', 'Block text format option is checked.');
$this
->assertNoFieldChecked('edit-simplify-blocks-revision-information', 'Block revision information option is not checked.');
$text_format = $this
->xpath('//input[@name="simplify_blocks[format]" and @disabled="disabled"]');
$this
->assertTrue(count($text_format) === 1, 'Block text format option is disabled.');
$revision_option = $this
->xpath('//input[@name="simplify_block[revision-information]" and @disabled="disabled"]');
$this
->assertTrue(count($revision_option) === 0, 'Block revision information option is not disabled.');
$options = [
'simplify_blocks[revision_information]' => 'format',
];
$this
->drupalPostForm(NULL, $options, $this
->t('Save'));
$this
->drupalGet('/admin/structure/block/block-content/manage/testing_type');
$this
->assertFieldChecked('edit-simplify-blocks-revision-information', 'Block revision information option is checked.');
$this
->drupalGet('block/add/testing_type');
$this
->assertNoRaw('About text formats', 'Text format option is not defined.');
$this
->assertNoRaw('Revision information', 'Revision option is not defined.');
}
protected function createBlockContentType($label, $create_body = FALSE) {
$bundle = BlockContentType::create([
'id' => $label,
'label' => $label,
'revision' => TRUE,
]);
$bundle
->save();
if ($create_body) {
block_content_add_body_field($bundle
->id());
}
return $bundle;
}
}