|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Drupal\Tests\qux\FunctionalJavascript; |
| 6 | + |
| 7 | +use Drupal\FunctionalJavascriptTests\WebDriverTestBase; |
| 8 | +use Drupal\Tests\node\Traits\NodeCreationTrait; |
| 9 | +use PHPUnit\Framework\Attributes\Group; |
| 10 | + |
| 11 | +/** |
| 12 | + * Tests the field plugins. |
| 13 | + */ |
| 14 | +#[Group('DCG')] |
| 15 | +abstract class FieldBase extends WebDriverTestBase { |
| 16 | + |
| 17 | + use NodeCreationTrait; |
| 18 | + |
| 19 | + /** |
| 20 | + * {@inheritdoc} |
| 21 | + */ |
| 22 | + protected $defaultTheme = 'claro'; |
| 23 | + |
| 24 | + /** |
| 25 | + * {@inheritdoc} |
| 26 | + */ |
| 27 | + protected static $modules = ['qux', 'node', 'field_ui', 'block']; |
| 28 | + |
| 29 | + /** |
| 30 | + * {@inheritdoc} |
| 31 | + */ |
| 32 | + protected function setUp(): void { |
| 33 | + parent::setUp(); |
| 34 | + |
| 35 | + $this->createContentType(['type' => 'test']); |
| 36 | + |
| 37 | + $permissions = [ |
| 38 | + 'administer node fields', |
| 39 | + 'administer node form display', |
| 40 | + 'administer node display', |
| 41 | + 'create test content', |
| 42 | + 'edit own test content', |
| 43 | + ]; |
| 44 | + $user = $this->createUser($permissions); |
| 45 | + $this->drupalLogin($user); |
| 46 | + |
| 47 | + // Create text field. |
| 48 | + $this->drupalGet('admin/structure/types/manage/test/fields/add-field'); |
| 49 | + |
| 50 | + $driver = $this->getSession()->getDriver(); |
| 51 | + $driver->click('//input[@name = "new_storage_type" and @value = "plain_text"]'); |
| 52 | + $driver->click('//input[@value = "Continue"]'); |
| 53 | + $driver->setValue('//input[@name = "label"]', 'Wine'); |
| 54 | + $driver->setValue('//input[@name = "group_field_options_wrapper"]', 'string'); |
| 55 | + $this->assertSession()->waitForElementVisible('css', '#edit-label-machine-name-suffix'); |
| 56 | + $driver->click('//input[@value = "Continue"]'); |
| 57 | + $driver->click('//input[@value = "Save settings"]'); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Waits for Ajax request to be finished. |
| 62 | + */ |
| 63 | + protected function waitForAjax(): void { |
| 64 | + $page = $this->getSession()->getPage(); |
| 65 | + $page->waitFor(10, static function () use ($page): bool { |
| 66 | + $element = $page->find('css', '.throbber'); |
| 67 | + return $element === NULL || \count($element) === 0; |
| 68 | + }); |
| 69 | + } |
| 70 | + |
| 71 | +} |
0 commit comments