UiPatternsFieldGroupSettingsTest.php in UI Patterns 8
File
modules/ui_patterns_field_group/tests/src/FunctionalJavascript/UiPatternsFieldGroupSettingsTest.php
View source
<?php
namespace Drupal\Tests\ui_patterns_field_group\FunctionalJavascript;
use Behat\Mink\Element\DocumentElement;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class UiPatternsFieldGroupSettingsTest extends WebDriverTestBase {
protected $defaultTheme = 'stark';
protected $strictConfigSchema = FALSE;
protected static $modules = [
'node',
'field',
'field_group',
'field_ui',
'text',
'ui_patterns_field_group_test',
];
public function testWarningMessage() {
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$user = $this
->drupalCreateUser([], NULL, TRUE);
$this
->drupalLogin($user);
$this
->drupalGet('/admin/structure/types/manage/article/display/add-group');
$page
->selectFieldOption('Add a new group', 'Pattern');
$assert_session
->assertWaitOnAjaxRequest();
$page
->fillField('Label', 'Metadata');
$page
->waitFor(10, function (DocumentElement $page) {
return $page
->hasContent('Machine name: group_metadata');
});
$page
->pressButton('Save and continue');
$assert_session
->pageTextContains("Attention: you have to add fields to this field group and save the whole entity display before being able to to access the pattern display configuration.");
}
public function testUiPatternsFieldGroupSettings() {
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$user = $this
->drupalCreateUser([], NULL, TRUE);
$this
->drupalLogin($user);
$this
->drupalGet('/admin/structure/types/manage/article/display');
$page
->pressButton('group_pattern_group_group_settings_edit');
$assert_session
->assertWaitOnAjaxRequest();
$page
->selectFieldOption('Variant', 'Second');
$page
->selectFieldOption('Destination for Text', 'Field 2');
$assert_session
->assertWaitOnAjaxRequest();
$page
->pressButton('Update');
$assert_session
->assertWaitOnAjaxRequest();
$page
->pressButton('Save');
$display = EntityViewDisplay::load("node.article.default");
$settings = $display
->getThirdPartySetting('field_group', 'group_pattern_group');
$this
->assertEquals($settings['format_type'], 'pattern_formatter');
$this
->assertEquals($settings['format_settings']['pattern'], 'metadata');
$this
->assertEquals($settings['format_settings']['pattern_variant'], 'second');
$this
->assertNotEmpty($settings['format_settings']['pattern_mapping'], "Pattern mapping is empty.");
$mapping = $settings['format_settings']['pattern_mapping'];
$this
->assertArrayHasKey('fields:field_text', $mapping, 'Mapping not found.');
$this
->assertEquals($mapping['fields:field_text']['destination'], 'field_2', "Mapping not valid.");
}
}