1
0
mirror of https://github.com/flarum/core.git synced 2025-07-31 21:50:50 +02:00

Add unparse to Formatter extender (#2780)

This commit is contained in:
Sami Mazouz
2021-04-14 11:34:49 +01:00
committed by GitHub
parent 9e3699ea47
commit 39a6106854
4 changed files with 79 additions and 2 deletions

View File

@@ -89,6 +89,36 @@ class FormatterTest extends TestCase
$this->assertEquals('<t>ReplacedText&lt;a&gt;</t>', $this->getFormatter()->parse('Text<a>'));
}
/**
* @test
*/
public function custom_formatter_unparsing_doesnt_work_by_default()
{
$this->assertEquals('Text<a>', $this->getFormatter()->unparse('<t>Text&lt;a&gt;</t>'));
}
/**
* @test
*/
public function custom_formatter_unparsing_works_if_added_with_closure()
{
$this->extend((new Extend\Formatter)->unparse(function ($context, $xml) {
return '<t>ReplacedText&lt;a&gt;</t>';
}));
$this->assertEquals('ReplacedText<a>', $this->getFormatter()->unparse('<t>Text&lt;a&gt;</t>'));
}
/**
* @test
*/
public function custom_formatter_unparsing_works_if_added_with_invokable_class()
{
$this->extend((new Extend\Formatter)->unparse(InvokableUnparsing::class));
$this->assertEquals('ReplacedText<a>', $this->getFormatter()->unparse('<t>Text&lt;a&gt;</t>'));
}
/**
* @test
*/
@@ -136,6 +166,14 @@ class InvokableParsing
}
}
class InvokableUnparsing
{
public function __invoke($context, $xml)
{
return '<t>ReplacedText&lt;a&gt;</t>';
}
}
class InvokableRendering
{
public function __invoke($renderer, $context, $xml, $request)