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:
@@ -89,6 +89,36 @@ class FormatterTest extends TestCase
|
||||
$this->assertEquals('<t>ReplacedText<a></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<a></t>'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function custom_formatter_unparsing_works_if_added_with_closure()
|
||||
{
|
||||
$this->extend((new Extend\Formatter)->unparse(function ($context, $xml) {
|
||||
return '<t>ReplacedText<a></t>';
|
||||
}));
|
||||
|
||||
$this->assertEquals('ReplacedText<a>', $this->getFormatter()->unparse('<t>Text<a></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<a></t>'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
@@ -136,6 +166,14 @@ class InvokableParsing
|
||||
}
|
||||
}
|
||||
|
||||
class InvokableUnparsing
|
||||
{
|
||||
public function __invoke($context, $xml)
|
||||
{
|
||||
return '<t>ReplacedText<a></t>';
|
||||
}
|
||||
}
|
||||
|
||||
class InvokableRendering
|
||||
{
|
||||
public function __invoke($renderer, $context, $xml, $request)
|
||||
|
Reference in New Issue
Block a user