LinkFieldFormStatesTest.php in Drupal 10
File
core/modules/link/tests/src/FunctionalJavascript/LinkFieldFormStatesTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\link\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class LinkFieldFormStatesTest extends WebDriverTestBase {
protected static $modules = [
'entity_test',
'link',
'node',
'link_test_base_field',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->drupalLogin($this
->drupalCreateUser([
'administer entity_test content',
]));
}
public function testLinkFieldFormStates(string $uri, string $title) {
$this
->drupalGet('entity_test/add');
$session = $this
->assertSession();
$session
->elementNotExists('css', '#edit-links-0-uri[required]');
$session
->elementNotExists('css', '#edit-links-0-title[required]');
$page = $this
->getSession()
->getPage();
if ($uri !== '') {
$page
->fillField('links[0][uri]', $uri);
$session
->elementNotExists('css', '#edit-links-0-uri[required]');
$session
->elementExists('css', '#edit-links-0-title[required]');
}
else {
$page
->fillField('links[0][title]', $title);
$session
->elementExists('css', '#edit-links-0-uri[required]');
$session
->elementNotExists('css', '#edit-links-0-title[required]');
}
}
public function linkFieldFormStatesData() {
return [
'Fill uri, keep title empty' => [
'https://drupal.org',
'',
],
'Fill title, keep uri empty' => [
'',
'https://drupal.org',
],
];
}
}