app()->getContainer()->make(Formatter::class); $formatter->flush(); return $formatter; } /** * @test */ public function custom_formatter_config_doesnt_work_by_default() { $formatter = $this->getFormatter(); $this->assertEquals('[B]something[/B]', $formatter->parse('[B]something[/B]')); } /** * @test */ public function custom_formatter_config_works_if_added_with_closure() { $this->extend((new Extend\Formatter)->configure(function ($config) { $config->BBCodes->addFromRepository('B'); })); $formatter = $this->getFormatter(); $this->assertEquals('something', $formatter->render($formatter->parse('[B]something[/B]'))); } /** * @test */ public function custom_formatter_config_works_if_added_with_invokable_class() { $this->extend((new Extend\Formatter)->configure(InvokableConfig::class)); $formatter = $this->getFormatter(); $this->assertEquals('something', $formatter->render($formatter->parse('[B]something[/B]'))); } /** * @test */ public function custom_formatter_parsing_doesnt_work_by_default() { $this->assertEquals('Text<a>', $this->getFormatter()->parse('Text')); } /** * @test */ public function custom_formatter_parsing_works_if_added_with_closure() { $this->extend((new Extend\Formatter)->parse(function ($parser, $context, $text) { return 'ReplacedText'; })); $this->assertEquals('ReplacedText<a>', $this->getFormatter()->parse('Text')); } /** * @test */ public function custom_formatter_parsing_works_if_added_with_invokable_class() { $this->extend((new Extend\Formatter)->parse(InvokableParsing::class)); $this->assertEquals('ReplacedText<a>', $this->getFormatter()->parse('Text')); } /** * @test */ public function custom_formatter_unparsing_doesnt_work_by_default() { $this->assertEquals('Text', $this->getFormatter()->unparse('Text<a>')); } /** * @test */ public function custom_formatter_unparsing_works_if_added_with_closure() { $this->extend((new Extend\Formatter)->unparse(function ($context, $xml) { return 'ReplacedText<a>'; })); $this->assertEquals('ReplacedText', $this->getFormatter()->unparse('Text<a>')); } /** * @test */ public function custom_formatter_unparsing_works_if_added_with_invokable_class() { $this->extend((new Extend\Formatter)->unparse(InvokableUnparsing::class)); $this->assertEquals('ReplacedText', $this->getFormatter()->unparse('Text<a>')); } /** * @test */ public function custom_formatter_rendering_doesnt_work_by_default() { $this->assertEquals('Text', $this->getFormatter()->render('

Text

')); } /** * @test */ public function custom_formatter_rendering_works_if_added_with_closure() { $this->extend((new Extend\Formatter)->render(function ($renderer, $context, $xml, $request) { return 'ReplacedText'; })); $this->assertEquals('ReplacedText', $this->getFormatter()->render('Text')); } /** * @test */ public function custom_formatter_rendering_works_if_added_with_invokable_class() { $this->extend((new Extend\Formatter)->render(InvokableRendering::class)); $this->assertEquals('ReplacedText', $this->getFormatter()->render('Text')); } } class InvokableConfig { public function __invoke($config) { $config->BBCodes->addFromRepository('B'); } } class InvokableParsing { public function __invoke($parser, $context, $text) { return 'ReplacedText
'; } } class InvokableUnparsing { public function __invoke($context, $xml) { return 'ReplacedText<a>'; } } class InvokableRendering { public function __invoke($renderer, $context, $xml, $request) { return 'ReplacedText'; } }