function DateFormatValidationTest::testPatternIsValidated

Same name in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Entity/DateFormatValidationTest.php \Drupal\KernelTests\Core\Entity\DateFormatValidationTest::testPatternIsValidated()

Tests that the pattern of a date format is validated.

@testWith ["q", true, "This is not a valid date format."] ["", true, "This value should not be blank."] ["q", false, "This is not a valid date format."] ["", false, "This value should not be blank."]

Parameters

string $pattern: The pattern to set.

bool $locked: Whether the date format entity is locked or not.

string $expected_error: The error message that should be flagged for the invalid pattern.

File

core/tests/Drupal/KernelTests/Core/Entity/DateFormatValidationTest.php, line 47

Class

DateFormatValidationTest
Tests validation of date_format entities.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testPatternIsValidated(string $pattern, bool $locked, string $expected_error) : void {
    $this->entity
        ->setPattern($pattern)
        ->set('locked', $locked);
    $this->assertValidationErrors([
        'pattern' => $expected_error,
    ]);
}

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