Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / console / Tests / Formatter / OutputFormatterTest.php
index 866c31a4437545632e6a05fe2adf1b23079fc40e..4b11028be5e35e6203e34db37725103e4021f055 100644 (file)
@@ -153,6 +153,67 @@ class OutputFormatterTest extends TestCase
         $this->assertEquals("\033[34;41msome text\033[39;49m", $formatter->format('<fg=blue;bg=red>some text</fg=blue;bg=red>'));
     }
 
+    /**
+     * @param string      $tag
+     * @param string|null $expected
+     * @param string|null $input
+     *
+     * @dataProvider provideInlineStyleOptionsCases
+     */
+    public function testInlineStyleOptions($tag, $expected = null, $input = null)
+    {
+        $styleString = substr($tag, 1, -1);
+        $formatter = new OutputFormatter(true);
+        $method = new \ReflectionMethod($formatter, 'createStyleFromString');
+        $method->setAccessible(true);
+        $result = $method->invoke($formatter, $styleString);
+        if (null === $expected) {
+            $this->assertFalse($result);
+            $expected = $tag.$input.'</'.$styleString.'>';
+            $this->assertSame($expected, $formatter->format($expected));
+        } else {
+            /* @var OutputFormatterStyle $result */
+            $this->assertInstanceOf(OutputFormatterStyle::class, $result);
+            $this->assertSame($expected, $formatter->format($tag.$input.'</>'));
+            $this->assertSame($expected, $formatter->format($tag.$input.'</'.$styleString.'>'));
+        }
+    }
+
+    public function provideInlineStyleOptionsCases()
+    {
+        return array(
+            array('<unknown=_unknown_>'),
+            array('<unknown=_unknown_;a=1;b>'),
+            array('<fg=green;>', "\033[32m[test]\033[39m", '[test]'),
+            array('<fg=green;bg=blue;>', "\033[32;44ma\033[39;49m", 'a'),
+            array('<fg=green;options=bold>', "\033[32;1mb\033[39;22m", 'b'),
+            array('<fg=green;options=reverse;>', "\033[32;7m<a>\033[39;27m", '<a>'),
+            array('<fg=green;options=bold,underscore>', "\033[32;1;4mz\033[39;22;24m", 'z'),
+            array('<fg=green;options=bold,underscore,reverse;>', "\033[32;1;4;7md\033[39;22;24;27m", 'd'),
+        );
+    }
+
+    /**
+     * @group legacy
+     * @dataProvider provideInlineStyleTagsWithUnknownOptions
+     * @expectedDeprecation Unknown style options are deprecated since version 3.2 and will be removed in 4.0. Exception "Invalid option specified: "%s". Expected one of (bold, underscore, blink, reverse, conceal)".
+     */
+    public function testInlineStyleOptionsUnknownAreDeprecated($tag, $option)
+    {
+        $formatter = new OutputFormatter(true);
+        $formatter->format($tag);
+    }
+
+    public function provideInlineStyleTagsWithUnknownOptions()
+    {
+        return array(
+            array('<options=abc;>', 'abc'),
+            array('<options=abc,def;>', 'abc'),
+            array('<fg=green;options=xyz;>', 'xyz'),
+            array('<fg=green;options=efg,abc>', 'efg'),
+        );
+    }
+
     public function testNonStyleTag()
     {
         $formatter = new OutputFormatter(true);