Skip to content

Commit 56aac6d

Browse files
committed
Revert "remove more JS tests"
This reverts commit d154016.
1 parent 0291479 commit 56aac6d

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 formatter.
11+
*/
12+
#[Group('DCG')]
13+
final class FieldFormatterTest extends FieldBase {
14+
15+
/**
16+
* Test callback.
17+
*/
18+
public function testFieldFormatter(): void {
19+
20+
$this->drupalGet('admin/structure/types/manage/test/display');
21+
22+
$assert_session = $this->assertSession();
23+
$page = $this->getSession()->getPage();
24+
25+
// Change default formatter.
26+
$page->selectFieldOption('fields[field_wine][type]', 'qux_example');
27+
$this->waitForAjax();
28+
$page->pressButton('Save');
29+
30+
// Change formatter settings.
31+
$this->click('#field-wine input[name="field_wine_settings_edit"]');
32+
$this->waitForAjax();
33+
// Some issue in the latest Chrome. Sleep is required to proceed.
34+
\sleep(1);
35+
$xpath = '//tr[@id = "field-wine"]//input[@name = "fields[field_wine][settings_edit_form][settings][foo]" and @value = "bar"]';
36+
$assert_session->elementExists('xpath', $xpath);
37+
$page->fillField('fields[field_wine][settings_edit_form][settings][foo]', 'example');
38+
$page->pressButton('Update');
39+
$this->waitForAjax();
40+
$page->pressButton('Save');
41+
42+
// Check formatter summary.
43+
$xpath = '//tr[@id = "field-wine"]/td/div[@class = "field-plugin-summary" and text() = "Foo: example"]';
44+
$assert_session->elementExists('xpath', $xpath);
45+
46+
// Make sure field data is displayed correctly.
47+
$this->drupalGet('node/add/test');
48+
$edit = [
49+
'title[0][value]' => 'Test #1',
50+
'field_wine[0][value]' => 'foo',
51+
];
52+
$this->submitForm($edit, 'Save');
53+
$xpath = '//div[contains(@class, "field--name-field-wine")]/div[@class="field__item" and normalize-space(text()) = "foo"]';
54+
$assert_session->elementExists('xpath', $xpath);
55+
}
56+
57+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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

Comments
 (0)