From 31f0ef676efcb0704a3af502c7141125f91ff4c4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Sun, 10 Feb 2019 05:46:39 +0100 Subject: [PATCH] Add basic tests Add README for tests --- tests/001.phpt | 28 ++++++++++---------- tests/002.phpt | 71 ++++++++++---------------------------------------- tests/003.phpt | 52 +++++------------------------------- tests/004.phpt | 13 +++++++++ tests/005.phpt | 12 +++++++++ tests/006.phpt | 16 ++++++++++++ tests/README | 20 ++++++++++++++ 7 files changed, 96 insertions(+), 116 deletions(-) create mode 100644 tests/004.phpt create mode 100644 tests/005.phpt create mode 100644 tests/006.phpt create mode 100644 tests/README diff --git a/tests/001.phpt b/tests/001.phpt index 1abb88f..15d1063 100644 --- a/tests/001.phpt +++ b/tests/001.phpt @@ -4,18 +4,18 @@ Check for bbcode presence --FILE-- +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 diff --git a/tests/002.phpt b/tests/002.phpt index b9d101a..f6414a3 100644 --- a/tests/002.phpt +++ b/tests/002.phpt @@ -1,63 +1,20 @@ --TEST-- -Check for bbcode functions +Check for missing tag in child --SKIPIF-- --FILE-- [ - ], - '' => [ - 'type' => BBCODE::TYPE_ROOT, - 'child' => ['ul','url','img','b','i'] - ], - 'i' => [ - 'type' => BBCODE::TYPE_MULTI - //TODO: by default open tag = and close tag = - ], - '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' => '', - 'close' => '', - 'arg' => 'href' - ], - ], - [ - ':)' => ':)', - ':(' => ':(', - ':D' => ':D', - ':p' => ':p', - ':|' => ':|', - ':6:' => ':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 diff --git a/tests/003.phpt b/tests/003.phpt index 36c3931..f9b0362 100644 --- a/tests/003.phpt +++ b/tests/003.phpt @@ -1,51 +1,13 @@ --TEST-- -Check for bbcode clone +Check for missing tag arg --SKIPIF-- --FILE-- [ - 'type' => BBCODE::TYPE_ROOT, - 'child' => ['ul','url','img','b','i'] - ], - 'i' => [ - 'type' => BBCODE::TYPE_MULTI - //TODO: by default open tag = and close tag = - ], - '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' => '', - 'close' => '', - 'default' => '{CONTENT}' - ] - ], - [ - ':)' => ':)', - ':(' => ':(', - ':D' => ':D', - ':p' => ':p', - ':|' => ':|', - ':6:' => ':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 diff --git a/tests/004.phpt b/tests/004.phpt new file mode 100644 index 0000000..04cee5d --- /dev/null +++ b/tests/004.phpt @@ -0,0 +1,13 @@ +--TEST-- +Check for empty tag arg +--SKIPIF-- + +--FILE-- +getMessage(); +} +--EXPECT-- +BBCode::__construct(): Tag array has 0 BBCODE::TYPE_ROOT entry instead of expected unique one diff --git a/tests/005.phpt b/tests/005.phpt new file mode 100644 index 0000000..2c694c2 --- /dev/null +++ b/tests/005.phpt @@ -0,0 +1,12 @@ +--TEST-- +Check for minimal call +--SKIPIF-- + +--FILE-- + [] + ] +); +--EXPECT-- diff --git a/tests/006.phpt b/tests/006.phpt new file mode 100644 index 0000000..2853e3f --- /dev/null +++ b/tests/006.phpt @@ -0,0 +1,16 @@ +--TEST-- +Check for object clone +--SKIPIF-- + +--FILE-- + [] + ] +); +$cln = clone $obj; +var_dump($cln); +--EXPECT-- +object(BBCode)#2 (0) { +} diff --git a/tests/README b/tests/README new file mode 100644 index 0000000..7e7d38c --- /dev/null +++ b/tests/README @@ -0,0 +1,20 @@ +--TEST-- +Success test +--SKIPIF-- + +--FILE-- +