You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.6 KiB

  1. <?php namespace Sensory5\Shortcode;
  2. use Sensory5\Shortcode\Classes\Shortcode;
  3. use Thunder\Shortcode\HandlerContainer\HandlerContainer;
  4. use Thunder\Shortcode\Parser\RegexParser;
  5. use Thunder\Shortcode\Processor\Processor;
  6. use Thunder\Shortcode\Shortcode\ShortcodeInterface;
  7. class ShortcodeTest extends \PHPUnit_Framework_TestCase
  8. {
  9. /**
  10. * @dataProvider provideTexts
  11. */
  12. public function testParse($text, $expect)
  13. {
  14. $this->assertSame($expect, $this->getShortcode()->parse($text));
  15. }
  16. public function provideTexts()
  17. {
  18. return [
  19. ['[name]', 'name'],
  20. ['[content]', ''],
  21. ['[content]thunder[/content]', 'thunder'],
  22. ['[content][name][/content]', 'name'],
  23. ['[nc][name][/nc]', 'nc: name'],
  24. ];
  25. }
  26. public function testCount()
  27. {
  28. $this->assertSame(3, $this->getShortcode()->count());
  29. }
  30. public function testAll()
  31. {
  32. $this->assertSame(['name', 'content', 'nc'], $this->getShortcode()->all());
  33. }
  34. public function testUnregister()
  35. {
  36. $this->assertSame('[name]', $this->getShortcode()->unregister('name')->parse('[name]'));
  37. }
  38. public function testDestroy()
  39. {
  40. $this->assertSame('[name]', $this->getShortcode()->destroy()->parse('[name]'));
  41. }
  42. public function testStrip()
  43. {
  44. $this->assertSame('', $this->getShortcode()->strip('[name]'));
  45. $this->assertSame('x y', $this->getShortcode()->strip('x [name]y'));
  46. $this->assertSame('x a a y', $this->getShortcode()->strip('x [name] a [content /] a [/name] y'));
  47. }
  48. public function testExists()
  49. {
  50. $shortcode = $this->getShortcode();
  51. $this->assertTrue($shortcode->exists('name'));
  52. $this->assertTrue($shortcode->exists('content'));
  53. $this->assertTrue($shortcode->exists('nc'));
  54. $this->assertFalse($shortcode->exists('invalid'));
  55. }
  56. public function testContains()
  57. {
  58. $shortcode = $this->getShortcode();
  59. $this->assertTrue($shortcode->contains('[name]', 'name'));
  60. $this->assertFalse($shortcode->contains('[x]', 'name'));
  61. }
  62. private function getShortcode()
  63. {
  64. $shortcode = new Shortcode();
  65. $shortcode->register('name', function(ShortcodeInterface $s) {
  66. return $s->getName();
  67. });
  68. $shortcode->register('content', function(ShortcodeInterface $s) {
  69. return $s->getContent();
  70. });
  71. $shortcode->register('nc', function(ShortcodeInterface $s) {
  72. return $s->getName().': '.$s->getContent();
  73. });
  74. return $shortcode;
  75. }
  76. }