View source
<?php
namespace Drupal\Tests\field\FunctionalJavascript\Boolean;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class BooleanFormatterSettingsTest extends WebDriverTestBase {
protected static $modules = [
'field',
'field_ui',
'text',
'node',
'user',
];
protected $defaultTheme = 'stark';
protected $bundle;
protected $fieldName;
protected function setUp() : void {
parent::setUp();
$type_name = mb_strtolower($this
->randomMachineName(8)) . '_test';
$type = $this
->drupalCreateContentType([
'name' => $type_name,
'type' => $type_name,
]);
$this->bundle = $type
->id();
$admin_user = $this
->drupalCreateUser([
'access content',
'administer content types',
'administer node fields',
'administer node display',
'bypass node access',
'administer nodes',
]);
$this
->drupalLogin($admin_user);
$this->fieldName = mb_strtolower($this
->randomMachineName(8));
$field_storage = FieldStorageConfig::create([
'field_name' => $this->fieldName,
'entity_type' => 'node',
'type' => 'boolean',
]);
$field_storage
->save();
$instance = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => $this->bundle,
'label' => $this
->randomMachineName(),
]);
$instance
->save();
$display = \Drupal::service('entity_display.repository')
->getViewDisplay('node', $this->bundle)
->setComponent($this->fieldName, [
'type' => 'boolean',
'settings' => [],
]);
$display
->save();
}
public function testBooleanFormatterSettings() {
$options = [
'Yes / No',
'True / False',
'On / Off',
'Enabled / Disabled',
'1 / 0',
'Custom',
];
$settings = [
[
'Yes',
'No',
],
[
'On',
'Off',
],
[
'TRUE',
'FALSE',
],
];
$assert_session = $this
->assertSession();
foreach ($settings as $values) {
$this
->drupalGet('admin/structure/types/manage/' . $this->bundle . '/fields/node.' . $this->bundle . '.' . $this->fieldName);
$this
->submitForm([
'settings[on_label]' => $values[0],
'settings[off_label]' => $values[1],
], 'Save settings');
$this
->drupalGet('admin/structure/types/manage/' . $this->bundle . '/display');
$this
->getSession()
->getPage()
->pressButton($this->fieldName . '_settings_edit');
$assert_session
->waitForElement('css', '.ajax-new-content');
foreach ($options as $string) {
$assert_session
->pageTextContains($string);
}
$assert_session
->pageTextContains("Field settings ({$values[0]} / {$values[1]})");
}
}
}