Skip to content
Snippets Groups Projects
Commit e50c9634 authored by Mikael Meulle's avatar Mikael Meulle
Browse files

Issue #3472993 by just_like_good_vibes, christian.wiedemann: Remaining functional tests

parent 5fcc13e6
No related branches found
No related tags found
1 merge request!303"2.0.0 rc1 remaining functional"
Pipeline #373474 passed
uuid: 19aa8adc-ffbe-4c7d-9b5f-9b872c5e26ec
langcode: en
status: true
dependencies:
module:
- ui_patterns
- ui_patterns_blocks
- ui_patterns_test
theme:
- ui_patterns_test_theme
id: test_block
theme: ui_patterns_test_theme
region: content
weight: 0
provider: null
plugin: 'ui_patterns:ui_patterns_test:test-component'
settings:
id: 'ui_patterns:ui_patterns_test:test-component'
label: 'UI Patterns Test component'
label_display: visible
provider: ui_patterns_blocks
ui_patterns:
component_id: null
variant_id:
source_id: select
source:
value: ''
props:
attributes:
source_id: class_attribute
source:
value: ''
string:
source_id: textfield
source:
value: 'test input'
integer:
source_id: number
source:
value: ''
number:
source_id: number
source:
value: ''
url:
source_id: url
source:
value: ''
identifier:
source_id: textfield
source:
value: ''
boolean:
source_id: checkbox
links:
source_id: menu
source:
menu: ''
level: '1'
depth: '0'
enum_integer:
source_id: select
source:
value: ''
enum_string:
source_id: select
source:
value: ''
enum_list:
source_id: selects
source:
value:
- ''
enum_list_multiple:
source_id: selects
source:
value:
- ''
- ''
- ''
enum_set:
source_id: checkboxes
list_string:
source_id: list_textarea
source:
value: ''
list_integer:
source_id: list_textarea
source:
value: ''
list_mixed:
source_id: list_textarea
source:
value: ''
attributes_implicit:
source_id: class_attribute
source:
value: ''
attributes_ui_patterns:
source_id: class_attribute
source:
value: ''
attributes_class:
source_id: class_attribute
source:
value: ''
slots:
slots: { }
visibility: { }
---
test_prop_string:
component:
component_id: ui_patterns_test:test-component
props:
string:
source_id: textfield
source:
value: 'test input'
output:
props:
string:
normalized_value: 'test input'
assertSession:
elementTextEquals:
- [ 'css', '.ui-patterns-props-string', 'test input' ]
elementExists:
- [ 'css', '.ui-patterns-test-component' ]
- [ 'xpath', "//div[contains(@class, 'ui-patterns-test-component')]//div[contains(@class, 'ui-patterns-props-string') and contains(text(), 'test input')]" ]
<?php
namespace Drupal\Tests\ui_patterns_blocks\Functional;
use Drupal\Tests\ui_patterns\Functional\UiPatternsFunctionalTestBase;
use Drupal\Tests\ui_patterns\Traits\TestDataTrait;
/**
* Test component rendering with Layout Builder.
*
* @group ui_patterns_blocks
*/
class BlockLayoutTest extends UiPatternsFunctionalTestBase {
use TestDataTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'ui_patterns',
'ui_patterns_test',
'ui_patterns_blocks',
'block',
'user',
'contextual',
'block_test',
];
/**
* {@inheritdoc}
*/
protected $strictConfigSchema = FALSE;
/**
* The layout plugin manager.
*
* @var \Drupal\Core\Block\BlockManagerInterface
*/
protected $blockManager;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
\Drupal::service('theme_installer')->install(['ui_patterns_test_theme']);
\Drupal::configFactory()
->getEditable('system.theme')
->set('default', 'ui_patterns_test_theme')
->save();
if ($this->user) {
$this->drupalCreateRole(['administer blocks'], 'custom_role');
$this->user->addRole('custom_role');
$this->user->save();
}
$this->blockManager = $this->container->get('plugin.manager.block');
}
/**
* Test the form and the existence of the.
*/
public function testBlockLayout(): void {
$assert_session = $this->assertSession();
$test_data = self::loadTestDataFixture();
$test_blocks_no_context = self::loadTestDataFixture(__DIR__ . "/../../fixtures/tests.blocks.no_context.yml");
$tests = array_merge($test_data->getTestSets(), $test_blocks_no_context->getTestSets());
$config_import = $this->loadConfigFixture(__DIR__ . '/../../fixtures/config/block.block.test_block.yml');
$ui_patterns_config = &$config_import['settings']['ui_patterns'];
foreach ($tests as $test_set) {
if (isset($test_set['entity']) && is_array($test_set['entity']) && (count($test_set['entity']) > 0)) {
// We skip tests with an entity.
continue;
}
$ui_patterns_config = $this->buildUiPatternsConfig($test_set);
$this->importConfigFixture(
'block.block.test_block',
$config_import
);
$block_ids = \Drupal::entityQuery('block')
->condition('theme', 'ui_patterns_test_theme')
->condition('region', 'content')
->execute();
$this->assertArrayHasKey('test_block', $block_ids, print_r($block_ids, TRUE));
$this->drupalGet('/user');
$this->validateRenderedComponent($test_set);
if (isset($test_set["assertSession"])) {
$this->assertSessionObject($test_set["assertSession"]);
}
// We check that the form is appearing.
$this->drupalGet('/admin/structure/block/manage/test_block');
$this->assertSession()->statusCodeEquals(200);
if (isset($test_set['component'])) {
if (isset($test_set['component']['props']) && is_array($test_set['component']['props'])) {
foreach ($test_set['component']['props'] as $prop_key => $prop) {
if (!isset($prop["source"])) {
continue;
}
foreach ($prop["source"] as $source_key => $source_value) {
if (is_array($source_value) ||
str_starts_with($prop_key, "enum_list") ||
($prop_key === "enum_set")) {
continue;
}
$this->assertSession()->elementExists('css', '[name="settings[ui_patterns][props][' . $prop_key . '][source][' . $source_key . ']"]');
}
}
}
}
}
}
}
......@@ -271,7 +271,7 @@ class ComponentForm extends ComponentFormBase {
'#ajax_url' => $element['#ajax_url'] ?? NULL,
'#access' => $element['#render_slots'] ?? TRUE,
'#default_value' => [
'slots' => $element['#default_value']['slots'],
'slots' => $element['#default_value']['slots'] ?? [],
],
];
}
......
......@@ -38,9 +38,13 @@ class CheckboxesWidget extends SourcePluginPropValue {
*/
public function settingsForm(array $form, FormStateInterface $form_state): array {
$form = parent::settingsForm($form, $form_state);
$defaultValue = $this->getSetting('value') ?? [];
if (!is_array($defaultValue)) {
$defaultValue = [$defaultValue];
}
$form['value'] = [
'#type' => 'checkboxes',
'#default_value' => $this->getSetting('value') ?? [],
'#default_value' => $defaultValue,
"#options" => static::getEnumOptions($this->propDefinition['items']),
];
$this->addRequired($form['value']);
......
......@@ -93,6 +93,7 @@ select_integer:
enum_integer:
same: 2
entity: {}
textfield_slot:
component:
component_id: ui_patterns_test:test-component
......@@ -243,7 +244,9 @@ token_default:
source_id: token
source:
value: '[node:id]'
entity: {}
entity:
body:
value: 'value_text_token_1' # we just set a value to indicate the test requires an entity
output:
props:
string:
......@@ -279,7 +282,9 @@ context_exists_default:
props:
string:
value: 'entity exists: 1'
entity: {}
entity:
body:
value: 'value_something' # we just set a value to indicate the test requires an entity
assertSession:
elementExists:
- [ 'css', '.ui-patterns-test-component' ]
......@@ -400,7 +405,9 @@ entity_field_2:
'field:node:page:nid':
value:
source_id: 'field_property:node:nid:value'
entity: {}
entity:
body:
value: 'value_something' # we just set a value to indicate the test requires an entity
output:
props:
integer:
......@@ -475,7 +482,9 @@ entity_links_1:
source_id: entity_link
source:
template: edit-form
entity: { }
entity:
body:
value: 'value_something' # we just set a value to indicate the test requires an entity
output:
props:
string:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment