LinkFieldFormStatesTest.php

Same filename and directory in other branches
  1. 10 core/modules/link/tests/src/FunctionalJavascript/LinkFieldFormStatesTest.php
  2. 11.x core/modules/link/tests/src/FunctionalJavascript/LinkFieldFormStatesTest.php

Namespace

Drupal\Tests\link\FunctionalJavascript

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;

/**
 * Tests link field form states functionality.
 *
 * @group link
 */
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',
            ],
        ];
    }

}

Classes

Title Deprecated Summary
LinkFieldFormStatesTest Tests link field form states functionality.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.