You are here

class LinkFieldFormStatesTest in Drupal 10

Tests link field form states functionality.

@group link

Hierarchy

Expanded class hierarchy of LinkFieldFormStatesTest

File

core/modules/link/tests/src/FunctionalJavascript/LinkFieldFormStatesTest.php, line 14

Namespace

Drupal\Tests\link\FunctionalJavascript
View source
class LinkFieldFormStatesTest extends WebDriverTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'entity_test',
    'link',
    'node',
    'link_test_base_field',
  ];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'administer entity_test content',
    ]));
  }

  /**
   * @dataProvider linkFieldFormStatesData
   */
  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]');
    }
  }

  /**
   * Provides data for ::testLinkFieldJSFormStates.
   */
  public function linkFieldFormStatesData() {
    return [
      'Fill uri, keep title empty' => [
        'https://drupal.org',
        '',
      ],
      'Fill title, keep uri empty' => [
        '',
        'https://drupal.org',
      ],
    ];
  }

}

Members