More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Logger / LogMessageParserTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Logger;
4
5 use Drupal\Core\Logger\LogMessageParser;
6 use Drupal\Tests\UnitTestCase;
7
8 /**
9  * @coversDefaultClass \Drupal\Core\Logger\LogMessageParser
10  * @group Logger
11  */
12 class LogMessageParserTest extends UnitTestCase {
13
14   /**
15    * Test for LogMessageParserTrait::parseMessagePlaceholders()
16    *
17    * @param array $value
18    *   An array containing:
19    *    - message: A string that contains a message with placeholders.
20    *    - context: An array with placeholder values.
21    * @param array $expected
22    *   An array with the expected values after the test has run.
23    *    - message: The expected parsed message.
24    *    - context: The expected values of the placeholders.
25    *
26    * @dataProvider providerTestParseMessagePlaceholders
27    * @covers ::parseMessagePlaceholders
28    */
29   public function testParseMessagePlaceholders(array $value, array $expected) {
30     $parser = new LogMessageParser();
31     $message_placeholders = $parser->parseMessagePlaceholders($value['message'], $value['context']);
32     $this->assertEquals($expected['message'], $value['message']);
33     $this->assertEquals($expected['context'], $message_placeholders);
34   }
35
36   /**
37    * Data provider for testParseMessagePlaceholders().
38    */
39   public function providerTestParseMessagePlaceholders() {
40     return [
41       // PSR3 only message.
42       [
43         ['message' => 'User {username} created', 'context' => ['username' => 'Dries']],
44         ['message' => 'User @username created', 'context' => ['@username' => 'Dries']],
45       ],
46       // PSR3 style mixed in a format_string style message.
47       [
48         ['message' => 'User {username} created @time', 'context' => ['username' => 'Dries', '@time' => 'now']],
49         ['message' => 'User @username created @time', 'context' => ['@username' => 'Dries', '@time' => 'now']],
50       ],
51       // format_string style message only.
52       [
53         ['message' => 'User @username created', 'context' => ['@username' => 'Dries']],
54         ['message' => 'User @username created', 'context' => ['@username' => 'Dries']],
55       ],
56       // Message without placeholders but wildcard characters.
57       [
58         ['message' => 'User W-\\};~{&! created @', 'context' => ['' => '']],
59         ['message' => 'User W-\\};~{&! created @', 'context' => []],
60       ],
61       // Message with double PSR3 style messages.
62       [
63         ['message' => 'Test {with} two {encapsuled} strings', 'context' => ['with' => 'together', 'encapsuled' => 'awesome']],
64         ['message' => 'Test @with two @encapsuled strings', 'context' => ['@with' => 'together', '@encapsuled' => 'awesome']],
65       ],
66     ];
67   }
68
69 }