<?php if (!extension_loaded("bbcode")) print "skip"; ?>
--FILE--
<?php
-echo "bbcode extension is available";
-/*
- 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
-*/
-?>
+if (class_exists('BBCode')) {
+ echo 'bbcode class is available'."\n";
+}
+if ($methods = get_class_methods('BBCode')) {
+ echo 'bbcode class methods are available'."\n";
+}
+foreach($methods as $method) {
+ echo 'bbcode class method '.$method.' is available'."\n";
+}
--EXPECT--
-bbcode extension is available
+bbcode class is available
+bbcode class methods are available
+bbcode class method __construct is available
+bbcode class method __destruct is available
+bbcode class method parse is available
--TEST--
-Check for bbcode functions
+Check for missing tag in child
--SKIPIF--
<?php if (!extension_loaded("bbcode")) print "skip"; ?>
--FILE--
<?php
-$obj = new bbcode(
- [
- 'img' => [
- ],
- '' => [
- 'type' => BBCODE::TYPE_ROOT,
- 'child' => ['ul','url','img','b','i']
- ],
- 'i' => [
- 'type' => BBCODE::TYPE_MULTI
- //TODO: by default open tag = <KEY> and close tag = </KEY>
- ],
- 'b' => [
- 'type' => BBCODE::TYPE_MULTI
- ],
- 'ul' => [
- 'type' => BBCODE::TYPE_MULTI,
- 'child' => ['li']
- ],
- 'li' => [
- 'type' => BBCODE::TYPE_MULTI,
- 'parent' => ['ul'],
- 'child' => ['url','img','b','i']
- ],
- 'url' => [
- 'type' => BBCODE::TYPE_MULTI,
- 'parent' => ['','li','b','i'],
- 'open' => '<a%s>',
- 'close' => '</a>',
- 'arg' => 'href'
- ],
- ],
- [
- ':)' => '<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
-*/
-?>
+try {
+ $obj = new bbcode(
+ [
+ '' => [
+ 'type' => BBCODE::TYPE_ROOT,
+ 'child' => ['missing']
+ ]
+ ]
+ );
+} catch (Exception $e) {
+ echo $e->getMessage();
+}
--EXPECT--
-[ul][li][url=https://rapsys.eu]Rapsys[/url][/li][li][url=https://google.fr]Google[/url][/li][/ul]
+BBCode::__construct(): Child value missing for key [0]/child[1] is not present in tag keys
--TEST--
-Check for bbcode clone
+Check for missing tag arg
--SKIPIF--
<?php if (!extension_loaded("bbcode")) print "skip"; ?>
--FILE--
<?php
-$obj = new bbcode(
- [
- '' => [
- 'type' => BBCODE::TYPE_ROOT,
- 'child' => ['ul','url','img','b','i']
- ],
- 'i' => [
- 'type' => BBCODE::TYPE_MULTI
- //TODO: by default open tag = <KEY> and close tag = </KEY>
- ],
- 'b' => [
- 'type' => BBCODE::TYPE_MULTI
- ],
- 'ul' => [
- 'type' => BBCODE::TYPE_MULTI,
- 'child' => [ 'li' ]
- ],
- 'li' => [
- 'type' => BBCODE::TYPE_MULTI,
- 'parent' => 'ul',
- 'child' => ['url','img','b','i']
- ],
- 'url' => [
- 'type' => BBCODE::TYPE_MULTI,
- 'parent' => [ '', 'li', 'b', 'i', null, 'toto', 0, 42 ],
- 'open' => '<a href="{PARAM}">',
- 'close' => '</a>',
- 'default' => '{CONTENT}'
- ]
- ],
- [
- ':)' => '<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]');
-?>
+try {
+ $obj = new bbcode();
+} catch (Exception $e) {
+ echo $e->getMessage();
+}
--EXPECT--
-[ul][li][url=https://rapsys.eu]Rapsys[/url][/li][li][url=https://google.fr]Google[/url][/li][/ul]
+BBCode::__construct() expects at least 1 parameter, 0 given
--- /dev/null
+--TEST--
+Check for empty tag arg
+--SKIPIF--
+<?php if (!extension_loaded("bbcode")) print "skip"; ?>
+--FILE--
+<?php
+try {
+ $obj = new bbcode([]);
+} catch (Exception $e) {
+ echo $e->getMessage();
+}
+--EXPECT--
+BBCode::__construct(): Tag array has 0 BBCODE::TYPE_ROOT entry instead of expected unique one
--- /dev/null
+--TEST--
+Check for minimal call
+--SKIPIF--
+<?php if (!extension_loaded("bbcode")) print "skip"; ?>
+--FILE--
+<?php
+$obj = new bbcode(
+ [
+ '' => []
+ ]
+);
+--EXPECT--
--- /dev/null
+--TEST--
+Check for object clone
+--SKIPIF--
+<?php if (!extension_loaded("bbcode")) print "skip"; ?>
+--FILE--
+<?php
+$obj = new bbcode(
+ [
+ '' => []
+ ]
+);
+$cln = clone $obj;
+var_dump($cln);
+--EXPECT--
+object(BBCode)#2 (0) {
+}
--- /dev/null
+--TEST--
+Success test
+--SKIPIF--
+<?php if (!extension_loaded("bbcode")) print "skip"; ?>
+--FILE--
+<?php
+/*
+ * 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
+ */
+echo "Success";
+--EXPECT--
+Success