single = $reflection->getConstant('SINGLE_EMPHASIS'); $this->double = $reflection->getConstant('DOUBLE_EMPHASIS'); } /** * @dataProvider upCases */ public function testTheUpwardRewrite(string $before, string $after): void { $this->assertSame($after, preg_replace($this->single, '**$1**', $before)); } /** * @return iterable */ public static function upCases(): iterable { yield 'one word' => ['Das ist *wichtig*', 'Das ist **wichtig**']; yield 'several words' => ['*Dein Einsatz wurde angenommen!*', '**Dein Einsatz wurde angenommen!**']; yield 'around a placeholder' => ['*{destination}*', '**{destination}**']; yield 'already bold' => ['Das ist **wichtig**', 'Das ist **wichtig**']; yield 'escaped asterisk' => ['Ein Sternchen: \*', 'Ein Sternchen: \*']; // Whitespace next to a marker means it is not emphasis - CommonMark's own rule, and // the reason arithmetic and stray asterisks come through untouched. yield 'multiplication' => ['5 * 3 = 15', '5 * 3 = 15']; yield 'spaced asterisks' => ['a * b * c', 'a * b * c']; yield 'bullet at line start' => ["* Ausweis\n* Bankverbindung", "* Ausweis\n* Bankverbindung"]; yield 'not across lines' => ["*offen\ngeblieben*", "*offen\ngeblieben*"]; } public function testTheRewriteIsReversible(): void { $before = 'Das ist *wichtig* und *{destination}* auch'; $up = preg_replace($this->single, '**$1**', $before); $this->assertSame($before, preg_replace($this->double, '*$1*', $up)); } /** * The delivered defaults were rewritten by hand in the same commit, so nothing should * be left in them for the migration to find. Read through the parser rather than off * the raw file: the header comment documents *kursiv* on purpose. */ public function testTheDeliveredDefaultsAreAlreadyMigrated(): void { $texts = Yaml::parseFile(__DIR__.'/../../config/email_texts.yaml')['texts']; foreach ($texts as $key => $text) { $body = (string) ($text['body'] ?? ''); $this->assertSame( $body, preg_replace($this->single, '**$1**', $body), sprintf('Default wording of "%s" still carries single-asterisk emphasis', $key) ); } } }