Same name in this branch
  1. 10 core/modules/jsonapi/tests/src/Functional/DateFormatTest.php \Drupal\Tests\jsonapi\Functional\DateFormatTest
  2. 10 core/modules/system/tests/src/FunctionalJavascript/System/DateFormatTest.php \Drupal\Tests\system\FunctionalJavascript\System\DateFormatTest
Same name and namespace in other branches
  1. 8.9.x core/modules/system/tests/src/FunctionalJavascript/System/DateFormatTest.php \Drupal\Tests\system\FunctionalJavascript\System\DateFormatTest
  2. 9 core/modules/system/tests/src/FunctionalJavascript/System/DateFormatTest.php \Drupal\Tests\system\FunctionalJavascript\System\DateFormatTest

Tests that date formats UI with JavaScript enabled.

@group system

Hierarchy

  • class \Drupal\FunctionalJavascriptTests\WebDriverTestBase extends \Drupal\Tests\BrowserTestBase
    • class \Drupal\Tests\system\FunctionalJavascript\System\DateFormatTest

Expanded class hierarchy of DateFormatTest

File

core/modules/system/tests/src/FunctionalJavascript/System/DateFormatTest.php, line 15

Namespace

Drupal\Tests\system\FunctionalJavascript\System
View source
class DateFormatTest extends WebDriverTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'block',
  ];

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

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();

    // Create admin user and log in admin user.
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'administer site configuration',
    ]));
    $this
      ->drupalPlaceBlock('local_actions_block');
  }

  /**
   * Tests XSS via date format configuration.
   */
  public function testDateFormatXss() {
    $page = $this
      ->getSession()
      ->getPage();
    $assert = $this
      ->assertSession();
    $date_format = DateFormat::create([
      'id' => 'xss_short',
      'label' => 'XSS format',
      'pattern' => '\\<\\s\\c\\r\\i\\p\\t\\>\\a\\l\\e\\r\\t\\(\\"\\X\\S\\S\\")\\;\\<\\/\\s\\c\\r\\i\\p\\t\\>',
    ]);
    $date_format
      ->save();
    $this
      ->drupalGet('admin/config/regional/date-time');
    $assert
      ->assertEscaped('<script>alert("XSS");</script>');
    $this
      ->drupalGet('admin/config/regional/date-time/formats/manage/xss_short');
    $assert
      ->assertEscaped('<script>alert("XSS");</script>');

    // Add a new date format with HTML in it.
    $this
      ->drupalGet('admin/config/regional/date-time/formats/add');
    $date_format = '& \\<\\e\\m\\>Y\\<\\/\\e\\m\\>';
    $page
      ->fillField('date_format_pattern', $date_format);
    $assert
      ->waitForText('Displayed as');
    $assert
      ->assertEscaped('<em>' . date("Y") . '</em>');
    $page
      ->fillField('label', 'date_html_pattern');

    // Wait for the machine name ID to be completed.
    $assert
      ->waitForLink('Edit');
    $page
      ->pressButton('Add format');
    $assert
      ->pageTextContains('Custom date format added.');
    $assert
      ->assertEscaped('<em>' . date("Y") . '</em>');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DateFormatTest::$defaultTheme protected property
DateFormatTest::$modules protected static property
DateFormatTest::setUp protected function
DateFormatTest::testDateFormatXss public function Tests XSS via date format configuration.
WebDriverTestBase::$disableCssAnimations protected property Disables CSS animations in tests for more reliable testing.
WebDriverTestBase::$failOnJavascriptConsoleErrors protected property Determines if a test should fail on JavaScript console errors. 2
WebDriverTestBase::$minkDefaultDriverClass protected property
WebDriverTestBase::assertJsCondition protected function Waits for the given time or until the given JS condition becomes TRUE.
WebDriverTestBase::assertSession public function
WebDriverTestBase::createScreenshot protected function Creates a screenshot.
WebDriverTestBase::failOnJavaScriptErrors protected function Triggers a test failure if a JavaScript error was encountered.
WebDriverTestBase::getDrupalSettings protected function Gets the current Drupal javascript settings and parses into an array.
WebDriverTestBase::getHtmlOutputHeaders protected function
WebDriverTestBase::getMinkDriverArgs protected function 1
WebDriverTestBase::initFrontPage protected function
WebDriverTestBase::initMink protected function
WebDriverTestBase::installModulesFromClassProperty protected function 1
WebDriverTestBase::tearDown protected function 1