]> Raphaël G. Git Repositories - bbcode/commitdiff
Add unit tests
authorRaphaël Gertz <git@rapsys.eu>
Sat, 15 Sep 2018 10:13:55 +0000 (12:13 +0200)
committerRaphaël Gertz <git@rapsys.eu>
Sat, 15 Sep 2018 10:13:55 +0000 (12:13 +0200)
tests/002.phpt [new file with mode: 0644]
tests/003.phpt [new file with mode: 0644]

diff --git a/tests/002.phpt b/tests/002.phpt
new file mode 100644 (file)
index 0000000..a1359a4
--- /dev/null
@@ -0,0 +1,61 @@
+--TEST--
+Check for bbcode functions
+--SKIPIF--
+<?php if (!extension_loaded("bbcode")) print "skip"; ?>
+--FILE--
+<?php
+$obj = new bbcode(
+       [
+               '' => [
+                       'type' => BBCODE::TYPE_ROOT,
+                       'childs' => ['ul','url','img','b','i']
+               ],
+               'i' => [
+                       'type' => BBCODE::TYPE_NOARG
+                       //TODO: by default open tag = <KEY> and close tag = </KEY>
+               ],
+               'b' => [
+                       'type' => BBCODE::TYPE_NOARG
+               ],
+               'ul' => [
+                       'type' => BBCODE::TYPE_NOARG,
+                       'childs' => [ 'li' ]
+               ],
+               'li' => [
+                       'type' => BBCODE::TYPE_NOARG,
+                       'parent' => 'ul',
+                       'childs' => ['url','img','b','i']
+               ],
+               'url' => [
+                       'type' => BBCODE::TYPE_OPTARG,
+                       'open_tag' => '<a href="{PARAM}">',
+                       'close_tag' => '</a>',
+                       'default_arg' => '{CONTENT}',
+                       'parent' => [ '', 'li', 'b', 'i' ]
+               ]
+       ],
+       [
+               ':)' => '<img src="smiley.gif" alt=":)" />',
+               ':(' => '<img src="sad.gif" alt=":(" />',
+               ':D' => '<img src="happy.gif" alt=":D" />',
+               ':p' => '<img src="tong.gif" alt=":p" />',
+               ':|' => '<img src="special.gif" alt=":|" />',
+               ':6:' => '<img src="six.gif" alt=":6:" />'
+       ],
+       BBCODE::REMOVE_EMPTY
+);
+echo $obj->parse('[ul][li][url=https://rapsys.eu]Rapsys[/url][/li][li][url=https://google.fr]Google[/url][/li][/ul]');
+/*
+       you can add regression tests for your extension here
+
+  the output of your test code has to be equal to the
+  text in the --EXPECT-- section below for the tests
+  to pass, differences between the output and the
+  expected text are interpreted as failure
+
+       see php7/README.TESTING for further information on
+  writing regression tests
+*/
+?>
+--EXPECT--
+[ul][li][url=https://rapsys.eu]Rapsys[/url][/li][li][url=https://google.fr]Google[/url][/li][/ul]
diff --git a/tests/003.phpt b/tests/003.phpt
new file mode 100644 (file)
index 0000000..0e30488
--- /dev/null
@@ -0,0 +1,51 @@
+--TEST--
+Check for bbcode clone
+--SKIPIF--
+<?php if (!extension_loaded("bbcode")) print "skip"; ?>
+--FILE--
+<?php
+$obj = new bbcode(
+       [
+               '' => [
+                       'type' => BBCODE::TYPE_ROOT,
+                       'childs' => ['ul','url','img','b','i']
+               ],
+               'i' => [
+                       'type' => BBCODE::TYPE_NOARG
+                       //TODO: by default open tag = <KEY> and close tag = </KEY>
+               ],
+               'b' => [
+                       'type' => BBCODE::TYPE_NOARG
+               ],
+               'ul' => [
+                       'type' => BBCODE::TYPE_NOARG,
+                       'childs' => [ 'li' ]
+               ],
+               'li' => [
+                       'type' => BBCODE::TYPE_NOARG,
+                       'parent' => 'ul',
+                       'childs' => ['url','img','b','i']
+               ],
+               'url' => [
+                       'type' => BBCODE::TYPE_OPTARG,
+                       'open_tag' => '<a href="{PARAM}">',
+                       'close_tag' => '</a>',
+                       'default_arg' => '{CONTENT}',
+                       'parent' => [ '', 'li', 'b', 'i' ]
+               ]
+       ],
+       [
+               ':)' => '<img src="smiley.gif" alt=":)" />',
+               ':(' => '<img src="sad.gif" alt=":(" />',
+               ':D' => '<img src="happy.gif" alt=":D" />',
+               ':p' => '<img src="tong.gif" alt=":p" />',
+               ':|' => '<img src="special.gif" alt=":|" />',
+               ':6:' => '<img src="six.gif" alt=":6:" />'
+       ],
+       BBCODE::REMOVE_EMPTY
+);
+$cln = clone $obj;
+echo $cln->parse('[ul][li][url=https://rapsys.eu]Rapsys[/url][/li][li][url=https://google.fr]Google[/url][/li][/ul]');
+?>
+--EXPECT--
+[ul][li][url=https://rapsys.eu]Rapsys[/url][/li][li][url=https://google.fr]Google[/url][/li][/ul]