-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
131 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Litlife\JsonToBBCode\Nodes; | ||
|
||
class Smile extends Node | ||
{ | ||
public function matching(): bool | ||
{ | ||
return $this->proseMirrorJson['type'] == 'smile'; | ||
} | ||
|
||
public function toBBCode($innerBBCode = null): string | ||
{ | ||
if (!empty($this->proseMirrorJson['attrs']['simple_form'])) | ||
return $this->proseMirrorJson['attrs']['simple_form']; | ||
else | ||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
use Litlife\JsonToBBCode\Nodes\Smile; | ||
use Litlife\JsonToBBCode\Renderer; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class SmileTest extends TestCase | ||
{ | ||
public function testAddSmile() | ||
{ | ||
$bb = 'Тест :died: :hoo:'; | ||
|
||
$jsonString = <<<EOF | ||
{ | ||
"type": "doc", | ||
"content": [ | ||
{ | ||
"type": "paragraph", | ||
"attrs": { | ||
"textAlign": "left" | ||
}, | ||
"content": [ | ||
{ | ||
"type": "text", | ||
"text": "Тест " | ||
}, | ||
{ | ||
"type": "hardBreak" | ||
}, | ||
{ | ||
"type": "smile", | ||
"attrs": { | ||
"src": "http://example.com/storage/smiles/80.gif", | ||
"width": 43, | ||
"height": 34, | ||
"simple_form": ":died:" | ||
} | ||
}, | ||
{ | ||
"type": "text", | ||
"text": " " | ||
}, | ||
{ | ||
"type": "smile", | ||
"attrs": { | ||
"src": "http://example.com/storage/smiles/72.gif", | ||
"width": 44, | ||
"height": 46, | ||
"simple_form": ":hoo:" | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
EOF; | ||
|
||
$jsonArray = json_decode($jsonString, true); | ||
|
||
$this->assertEquals($bb, (new Renderer()) | ||
->clearNodes() | ||
->addNode(Smile::class) | ||
->render($jsonArray)); | ||
} | ||
|
||
public function testAddSmileWithoutSimpleForm() | ||
{ | ||
$bb = 'Тест '; | ||
|
||
$jsonString = <<<EOF | ||
{ | ||
"type": "doc", | ||
"content": [ | ||
{ | ||
"type": "paragraph", | ||
"attrs": { | ||
"textAlign": "left" | ||
}, | ||
"content": [ | ||
{ | ||
"type": "text", | ||
"text": "Тест " | ||
}, | ||
{ | ||
"type": "smile", | ||
"attrs": { | ||
"src": "http://example.com/storage/smiles/72.gif", | ||
"width": 44, | ||
"height": 46 | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
EOF; | ||
|
||
$jsonArray = json_decode($jsonString, true); | ||
|
||
$this->assertEquals($bb, (new Renderer()) | ||
->clearNodes() | ||
->addNode(Smile::class) | ||
->render($jsonArray)); | ||
} | ||
} |