|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Drupal\Tests\qux\FunctionalJavascript; |
| 6 | + |
| 7 | +use PHPUnit\Framework\Attributes\Group; |
| 8 | + |
| 9 | +/** |
| 10 | + * Tests the field widget. |
| 11 | + */ |
| 12 | +#[Group('DCG')] |
| 13 | +final class FieldWidgetTest extends FieldBase { |
| 14 | + |
| 15 | + /** |
| 16 | + * Test callback. |
| 17 | + */ |
| 18 | + public function testFieldWidget(): void { |
| 19 | + |
| 20 | + $this->drupalGet('admin/structure/types/manage/test/form-display'); |
| 21 | + |
| 22 | + $assert_session = $this->assertSession(); |
| 23 | + $page = $this->getSession()->getPage(); |
| 24 | + |
| 25 | + // Change default widget. |
| 26 | + $page->selectFieldOption('fields[field_wine][type]', 'qux_example'); |
| 27 | + $this->waitForAjax(); |
| 28 | + $page->pressButton('Save'); |
| 29 | + |
| 30 | + // Check widget summary. |
| 31 | + $xpath = '//tr[@id = "field-wine"]/td/div[@class = "field-plugin-summary" and text() = "Foo: bar"]'; |
| 32 | + $assert_session->elementExists('xpath', $xpath); |
| 33 | + |
| 34 | + // Change widget settings. |
| 35 | + $this->click('#field-wine input[name="field_wine_settings_edit"]'); |
| 36 | + $this->waitForAjax(); |
| 37 | + // Some issue in the latest Chrome. Sleep is required to proceed. |
| 38 | + \sleep(1); |
| 39 | + $xpath = '//tr[@id = "field-wine"]//input[@name = "fields[field_wine][settings_edit_form][settings][foo]" and @value = "bar"]'; |
| 40 | + $assert_session->elementExists('xpath', $xpath); |
| 41 | + $page->fillField('fields[field_wine][settings_edit_form][settings][foo]', 'example'); |
| 42 | + $page->pressButton('Update'); |
| 43 | + $this->waitForAjax(); |
| 44 | + $page->pressButton('Save'); |
| 45 | + |
| 46 | + // Check updated widget summary. |
| 47 | + $xpath = '//tr[@id = "field-wine"]/td/div[@class = "field-plugin-summary" and text() = "Foo: example"]'; |
| 48 | + $assert_session->elementExists('xpath', $xpath); |
| 49 | + |
| 50 | + // Make sure field data is saved correctly. |
| 51 | + $this->drupalGet('node/add/test'); |
| 52 | + $edit = [ |
| 53 | + 'title[0][value]' => 'Test #1', |
| 54 | + 'field_wine[0][value]' => 'foo', |
| 55 | + ]; |
| 56 | + $this->submitForm($edit, 'Save'); |
| 57 | + $xpath = '//div[contains(@class, "field--name-field-wine")]/div[@class="field__item" and text() = "foo"]'; |
| 58 | + $assert_session->elementExists('xpath', $xpath); |
| 59 | + |
| 60 | + // Check default form values. |
| 61 | + $this->drupalGet('node/1/edit'); |
| 62 | + $xpath = '//div[contains(@class, "form-item-field-wine-0-value")]/label[text() = "Wine"]/following-sibling::input[@value = "foo"]'; |
| 63 | + $assert_session->elementExists('xpath', $xpath); |
| 64 | + } |
| 65 | + |
| 66 | +} |
0 commit comments