FormFieldsCreatedWithYamlTest.php in Block Style Plugins 8.2
File
tests/src/Functional/FormFieldsCreatedWithYamlTest.php
View source
<?php
namespace Drupal\Tests\block_style_plugins\Functional;
use Drupal\Tests\BrowserTestBase;
class FormFieldsCreatedWithYamlTest extends BrowserTestBase {
protected static $modules = [
'block_style_plugins',
'block_style_plugins_test',
];
protected $defaultTheme = 'stark';
protected $adminUser;
protected function setUp() : void {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'administer blocks',
'access administration pages',
]);
$this
->drupalLogin($this->adminUser);
$this
->drupalPlaceBlock('system_powered_by_block', [
'id' => 'poweredbytest',
'region' => 'content',
]);
$this
->drupalPlaceBlock('system_breadcrumb_block', [
'id' => 'breadcrumbtest',
'region' => 'content',
]);
}
public function testBreadcrumbBlockExcluded() {
$assert = $this
->assertSession();
$this
->drupalGet('admin/structure/block/manage/breadcrumbtest');
$assert
->pageTextContains('Block Styles');
$assert
->pageTextNotContains('Styles Created by Yaml');
$assert
->fieldNotExists('third_party_settings[block_style_plugins][form_fields_created_with_yaml][test_field]');
}
public function testPoweredByBlockCreatedByYaml() {
$assert = $this
->assertSession();
$this
->drupalGet('admin/structure/block/manage/poweredbytest');
$assert
->responseContains('Title Created by Yaml');
$assert
->fieldExists('third_party_settings[block_style_plugins][form_fields_created_with_yaml][test_field]');
$assert
->fieldValueEquals('third_party_settings[block_style_plugins][form_fields_created_with_yaml][test_field]', 'text goes here');
$assert
->responseContains('Choose a style');
$assert
->fieldExists('third_party_settings[block_style_plugins][form_fields_created_with_yaml][second_field]');
$this
->submitForm([
'third_party_settings[block_style_plugins][form_fields_created_with_yaml][test_field]' => 'custom-class',
'third_party_settings[block_style_plugins][form_fields_created_with_yaml][second_field]' => 'style-2',
], 'Save block');
$this
->drupalGet('<front>');
$assert
->responseContains('id="block-poweredbytest"');
$assert
->responseContains('custom-class');
$assert
->responseContains('style-2');
$this
->drupalGet('admin/structure/block/manage/poweredbytest');
$assert
->fieldValueEquals('third_party_settings[block_style_plugins][form_fields_created_with_yaml][test_field]', 'custom-class');
$assert
->fieldValueEquals('third_party_settings[block_style_plugins][form_fields_created_with_yaml][second_field]', 'style-2');
}
}