function LogMessageParserTest::providerTestParseMessagePlaceholders

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Logger/LogMessageParserTest.php \Drupal\Tests\Core\Logger\LogMessageParserTest::providerTestParseMessagePlaceholders()
  2. 10 core/tests/Drupal/Tests/Core/Logger/LogMessageParserTest.php \Drupal\Tests\Core\Logger\LogMessageParserTest::providerTestParseMessagePlaceholders()
  3. 11.x core/tests/Drupal/Tests/Core/Logger/LogMessageParserTest.php \Drupal\Tests\Core\Logger\LogMessageParserTest::providerTestParseMessagePlaceholders()

Data provider for testParseMessagePlaceholders().

File

core/tests/Drupal/Tests/Core/Logger/LogMessageParserTest.php, line 39

Class

LogMessageParserTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Logger%21LogMessageParser.php/class/LogMessageParser/9" title="Parses log messages and their placeholders." class="local">\Drupal\Core\Logger\LogMessageParser</a> @group Logger

Namespace

Drupal\Tests\Core\Logger

Code

public function providerTestParseMessagePlaceholders() {
    return [
        // PSR3 only message.
[
            [
                'message' => 'User {username} created',
                'context' => [
                    'username' => 'Dries',
                ],
            ],
            [
                'message' => 'User @username created',
                'context' => [
                    '@username' => 'Dries',
                ],
            ],
        ],
        // PSR3 style mixed in a format_string style message.
[
            [
                'message' => 'User {username} created @time',
                'context' => [
                    'username' => 'Dries',
                    '@time' => 'now',
                ],
            ],
            [
                'message' => 'User @username created @time',
                'context' => [
                    '@username' => 'Dries',
                    '@time' => 'now',
                ],
            ],
        ],
        // format_string style message only.
[
            [
                'message' => 'User @username created',
                'context' => [
                    '@username' => 'Dries',
                ],
            ],
            [
                'message' => 'User @username created',
                'context' => [
                    '@username' => 'Dries',
                ],
            ],
        ],
        // Message without placeholders but wildcard characters.
[
            [
                'message' => 'User W-\\};~{&! created @',
                'context' => [
                    '' => '',
                ],
            ],
            [
                'message' => 'User W-\\};~{&! created @',
                'context' => [],
            ],
        ],
        // Message with double PSR3 style messages.
[
            [
                'message' => 'Test {with} two {{encapsuled}} strings',
                'context' => [
                    'with' => 'together',
                    'encapsuled' => 'awesome',
                ],
            ],
            [
                'message' => 'Test @with two {@encapsuled} strings',
                'context' => [
                    '@with' => 'together',
                    '@encapsuled' => 'awesome',
                ],
            ],
        ],
        // Test removal of unexpected placeholders like ! while allowed
        // placeholders beginning with @, % and : are preserved.
[
            [
                'message' => 'Test placeholder with :url and old !bang parameter',
                'context' => [
                    ':url' => 'https://drupal.org',
                    '!bang' => 'foo bar',
                ],
            ],
            [
                'message' => 'Test placeholder with :url and old !bang parameter',
                'context' => [
                    ':url' => 'https://drupal.org',
                ],
            ],
        ],
    ];
}

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