From 4e2bfed23c17929795f2082d6e77937170caeaa9 Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Sun, 13 Sep 2020 21:35:16 +0200 Subject: Turn our functional tests into PhpUnit tests --- tests/functional/.gitignore | 1 + tests/functional/BaseTest.php | 55 ++++++++++++++++++++++ tests/functional/TestStorage.php | 32 +++++++++++++ tests/functional/test_array/Test.php | 27 +++++++++++ tests/functional/test_array/test.tpl | 1 + tests/functional/test_array/want | 1 + tests/functional/test_blocks/Test.php | 18 +++++++ tests/functional/test_blocks/main.tpl | 3 ++ tests/functional/test_blocks/test.tpl | 2 + tests/functional/test_blocks/want | 3 ++ tests/functional/test_closure/Test.php | 18 +++++++ tests/functional/test_closure/test.tpl | 10 ++++ tests/functional/test_closure/want | 2 + tests/functional/test_escapes/Test.php | 21 +++++++++ tests/functional/test_escapes/test.tpl | 7 +++ tests/functional/test_escapes/want | 7 +++ tests/functional/test_foreach/Test.php | 23 +++++++++ tests/functional/test_foreach/test.tpl | 8 ++++ tests/functional/test_foreach/want | 5 ++ tests/functional/test_getset/Test.php | 19 ++++++++ tests/functional/test_getset/test.tpl | 5 ++ tests/functional/test_getset/want | 4 ++ tests/functional/test_loop/Test.php | 18 +++++++ tests/functional/test_loop/test.tpl | 3 ++ tests/functional/test_loop/want | 11 +++++ tests/functional/test_mktag/Test.php | 18 +++++++ tests/functional/test_mktag/test.tpl | 11 +++++ tests/functional/test_mktag/want | 11 +++++ tests/functional/test_pseudotags/Test.php | 18 +++++++ tests/functional/test_pseudotags/test.tpl | 2 + tests/functional/test_pseudotags/want | 1 + tests/functional/test_recursive/Test.php | 19 ++++++++ tests/functional/test_recursive/test.tpl | 11 +++++ tests/functional/test_recursive/want | 1 + tests/functional/test_scoping/Test.php | 18 +++++++ tests/functional/test_scoping/test.tpl | 18 +++++++ tests/functional/test_scoping/want | 9 ++++ tests/functional/test_short/Test.php | 18 +++++++ tests/functional/test_short/test.tpl | 1 + tests/functional/test_short/want | 1 + .../test_short_for_additional_attribs/Test.php | 23 +++++++++ .../test_short_for_additional_attribs/test.tpl | 5 ++ .../test_short_for_additional_attribs/want | 5 ++ tests/functional/test_simple/Test.php | 19 ++++++++ tests/functional/test_simple/test.tpl | 1 + tests/functional/test_simple/want | 1 + .../test_static_numeric_array_access/Test.php | 23 +++++++++ .../test_static_numeric_array_access/test.tpl | 3 ++ .../test_static_numeric_array_access/want | 3 ++ tests/functional/test_tagname/Test.php | 33 +++++++++++++ tests/functional/test_tagname/test.tpl | 4 ++ tests/functional/test_tagname/want | 4 ++ .../test_trailing_closing_array_bracket/Test.php | 23 +++++++++ .../test_trailing_closing_array_bracket/test.tpl | 3 ++ .../test_trailing_closing_array_bracket/want | 3 ++ 55 files changed, 614 insertions(+) create mode 100644 tests/functional/.gitignore create mode 100644 tests/functional/BaseTest.php create mode 100644 tests/functional/TestStorage.php create mode 100644 tests/functional/test_array/Test.php create mode 100644 tests/functional/test_array/test.tpl create mode 100644 tests/functional/test_array/want create mode 100644 tests/functional/test_blocks/Test.php create mode 100644 tests/functional/test_blocks/main.tpl create mode 100644 tests/functional/test_blocks/test.tpl create mode 100644 tests/functional/test_blocks/want create mode 100644 tests/functional/test_closure/Test.php create mode 100644 tests/functional/test_closure/test.tpl create mode 100644 tests/functional/test_closure/want create mode 100644 tests/functional/test_escapes/Test.php create mode 100644 tests/functional/test_escapes/test.tpl create mode 100644 tests/functional/test_escapes/want create mode 100644 tests/functional/test_foreach/Test.php create mode 100644 tests/functional/test_foreach/test.tpl create mode 100644 tests/functional/test_foreach/want create mode 100644 tests/functional/test_getset/Test.php create mode 100644 tests/functional/test_getset/test.tpl create mode 100644 tests/functional/test_getset/want create mode 100644 tests/functional/test_loop/Test.php create mode 100644 tests/functional/test_loop/test.tpl create mode 100644 tests/functional/test_loop/want create mode 100644 tests/functional/test_mktag/Test.php create mode 100644 tests/functional/test_mktag/test.tpl create mode 100644 tests/functional/test_mktag/want create mode 100644 tests/functional/test_pseudotags/Test.php create mode 100644 tests/functional/test_pseudotags/test.tpl create mode 100644 tests/functional/test_pseudotags/want create mode 100644 tests/functional/test_recursive/Test.php create mode 100644 tests/functional/test_recursive/test.tpl create mode 100644 tests/functional/test_recursive/want create mode 100644 tests/functional/test_scoping/Test.php create mode 100644 tests/functional/test_scoping/test.tpl create mode 100644 tests/functional/test_scoping/want create mode 100644 tests/functional/test_short/Test.php create mode 100644 tests/functional/test_short/test.tpl create mode 100644 tests/functional/test_short/want create mode 100644 tests/functional/test_short_for_additional_attribs/Test.php create mode 100644 tests/functional/test_short_for_additional_attribs/test.tpl create mode 100644 tests/functional/test_short_for_additional_attribs/want create mode 100644 tests/functional/test_simple/Test.php create mode 100644 tests/functional/test_simple/test.tpl create mode 100644 tests/functional/test_simple/want create mode 100644 tests/functional/test_static_numeric_array_access/Test.php create mode 100644 tests/functional/test_static_numeric_array_access/test.tpl create mode 100644 tests/functional/test_static_numeric_array_access/want create mode 100644 tests/functional/test_tagname/Test.php create mode 100644 tests/functional/test_tagname/test.tpl create mode 100644 tests/functional/test_tagname/want create mode 100644 tests/functional/test_trailing_closing_array_bracket/Test.php create mode 100644 tests/functional/test_trailing_closing_array_bracket/test.tpl create mode 100644 tests/functional/test_trailing_closing_array_bracket/want (limited to 'tests/functional') diff --git a/tests/functional/.gitignore b/tests/functional/.gitignore new file mode 100644 index 0000000..448d02b --- /dev/null +++ b/tests/functional/.gitignore @@ -0,0 +1 @@ +*.transc.php \ No newline at end of file diff --git a/tests/functional/BaseTest.php b/tests/functional/BaseTest.php new file mode 100644 index 0000000..ce045fb --- /dev/null +++ b/tests/functional/BaseTest.php @@ -0,0 +1,55 @@ +ste = new STECore(new TestStorage($this->getDirectory())); + $this->ste->mute_runtime_errors = false; + + $this->setUpSte($this->ste); + } + + protected function setUpSte(STECore $ste): void + { + } + + public function testTemplate(): void + { + $have = $this->ste->exectemplate("test.tpl"); + $want = file_get_contents($this->getDirectory() . DIRECTORY_SEPARATOR . "want"); + + $normalizedHave = self::normalize($have); + $normalizedWant = self::normalize($want); + + self::assertSame($normalizedWant, $normalizedHave); + } + + /** + * Get the directory of the test. + * @return string + */ + abstract protected function getDirectory(): string; +} diff --git a/tests/functional/TestStorage.php b/tests/functional/TestStorage.php new file mode 100644 index 0000000..2403668 --- /dev/null +++ b/tests/functional/TestStorage.php @@ -0,0 +1,32 @@ +dir = $dir; + } + + public function load($tpl, &$mode) + { + $mode = StorageAccess::MODE_SOURCE; + return file_get_contents($this->dir . DIRECTORY_SEPARATOR . $tpl); + } + + public function save($tpl, $data, $mode) + { + if ($mode != StorageAccess::MODE_TRANSCOMPILED) { + return; + } + + file_put_contents($this->dir . DIRECTORY_SEPARATOR . "$tpl.transc.php", $data); + } +} diff --git a/tests/functional/test_array/Test.php b/tests/functional/test_array/Test.php new file mode 100644 index 0000000..58f0cb8 --- /dev/null +++ b/tests/functional/test_array/Test.php @@ -0,0 +1,27 @@ +vars["foo"] = array( + "a" => array( + "blabla" => "OK" + ), + "b" => "bla" + ); + $ste->vars["bar"] = array( + "baz" => "a" + ); + } +} diff --git a/tests/functional/test_array/test.tpl b/tests/functional/test_array/test.tpl new file mode 100644 index 0000000..050045d --- /dev/null +++ b/tests/functional/test_array/test.tpl @@ -0,0 +1 @@ +${foo[$bar[baz]][${foo[b]}bla]} \ No newline at end of file diff --git a/tests/functional/test_array/want b/tests/functional/test_array/want new file mode 100644 index 0000000..d86bac9 --- /dev/null +++ b/tests/functional/test_array/want @@ -0,0 +1 @@ +OK diff --git a/tests/functional/test_blocks/Test.php b/tests/functional/test_blocks/Test.php new file mode 100644 index 0000000..05e8e09 --- /dev/null +++ b/tests/functional/test_blocks/Test.php @@ -0,0 +1,18 @@ +Bar +Baz \ No newline at end of file diff --git a/tests/functional/test_blocks/test.tpl b/tests/functional/test_blocks/test.tpl new file mode 100644 index 0000000..3d14e46 --- /dev/null +++ b/tests/functional/test_blocks/test.tpl @@ -0,0 +1,2 @@ + +Replaced \ No newline at end of file diff --git a/tests/functional/test_blocks/want b/tests/functional/test_blocks/want new file mode 100644 index 0000000..640cfef --- /dev/null +++ b/tests/functional/test_blocks/want @@ -0,0 +1,3 @@ +Foo +Replaced +Baz diff --git a/tests/functional/test_closure/Test.php b/tests/functional/test_closure/Test.php new file mode 100644 index 0000000..012e4c6 --- /dev/null +++ b/tests/functional/test_closure/Test.php @@ -0,0 +1,18 @@ + + + + $x + + + +10 +20 +30 +40 \ No newline at end of file diff --git a/tests/functional/test_closure/want b/tests/functional/test_closure/want new file mode 100644 index 0000000..98d2f20 --- /dev/null +++ b/tests/functional/test_closure/want @@ -0,0 +1,2 @@ +40 +60 diff --git a/tests/functional/test_escapes/Test.php b/tests/functional/test_escapes/Test.php new file mode 100644 index 0000000..5c2a2ab --- /dev/null +++ b/tests/functional/test_escapes/Test.php @@ -0,0 +1,21 @@ +register_tag("my_echo", function ($ste, $params, $sub) { + return $params["text"]; + }); + } +} diff --git a/tests/functional/test_escapes/test.tpl b/tests/functional/test_escapes/test.tpl new file mode 100644 index 0000000..5458fde --- /dev/null +++ b/tests/functional/test_escapes/test.tpl @@ -0,0 +1,7 @@ +\\\\\\\$foo +\${bar} +\?{foo|bar|baz} +?{|Foo|Bar\|Baz} + + +\' \ No newline at end of file diff --git a/tests/functional/test_escapes/want b/tests/functional/test_escapes/want new file mode 100644 index 0000000..3278c4d --- /dev/null +++ b/tests/functional/test_escapes/want @@ -0,0 +1,7 @@ +\\\$foo +${bar} +?{foo|bar|baz} +Bar|Baz +foo\"bar$ +' +\' diff --git a/tests/functional/test_foreach/Test.php b/tests/functional/test_foreach/Test.php new file mode 100644 index 0000000..3f8cc73 --- /dev/null +++ b/tests/functional/test_foreach/Test.php @@ -0,0 +1,23 @@ +vars["foo"] = array( + "a" => array("a" => 100, "b" => 200), + "b" => array("a" => 1, "b" => 2), + "c" => array("a" => 42, "b" => 1337) + ); + } +} diff --git a/tests/functional/test_foreach/test.tpl b/tests/functional/test_foreach/test.tpl new file mode 100644 index 0000000..1aec8b4 --- /dev/null +++ b/tests/functional/test_foreach/test.tpl @@ -0,0 +1,8 @@ + + $i: $k -> $v[a], $v[b] + +--- + + $v + --empty-- + diff --git a/tests/functional/test_foreach/want b/tests/functional/test_foreach/want new file mode 100644 index 0000000..5710bf7 --- /dev/null +++ b/tests/functional/test_foreach/want @@ -0,0 +1,5 @@ +0: a -> 100, 200 +1: b -> 1, 2 +2: c -> 42, 1337 +--- +--empty-- diff --git a/tests/functional/test_getset/Test.php b/tests/functional/test_getset/Test.php new file mode 100644 index 0000000..6f34500 --- /dev/null +++ b/tests/functional/test_getset/Test.php @@ -0,0 +1,19 @@ +vars["foo"] = "bar"; + } +} diff --git a/tests/functional/test_getset/test.tpl b/tests/functional/test_getset/test.tpl new file mode 100644 index 0000000..06f865a --- /dev/null +++ b/tests/functional/test_getset/test.tpl @@ -0,0 +1,5 @@ +\$foo = $foo +\$foo = +baz +\$foo = $foo +\$foo = diff --git a/tests/functional/test_getset/want b/tests/functional/test_getset/want new file mode 100644 index 0000000..567c753 --- /dev/null +++ b/tests/functional/test_getset/want @@ -0,0 +1,4 @@ +$foo = bar +$foo = bar +$foo = baz +$foo = baz diff --git a/tests/functional/test_loop/Test.php b/tests/functional/test_loop/Test.php new file mode 100644 index 0000000..05a76d7 --- /dev/null +++ b/tests/functional/test_loop/Test.php @@ -0,0 +1,18 @@ + +$i + \ No newline at end of file diff --git a/tests/functional/test_loop/want b/tests/functional/test_loop/want new file mode 100644 index 0000000..30b148d --- /dev/null +++ b/tests/functional/test_loop/want @@ -0,0 +1,11 @@ +10 +9 +8 +7 +6 +5 +4 +3 +2 +1 +0 diff --git a/tests/functional/test_mktag/Test.php b/tests/functional/test_mktag/Test.php new file mode 100644 index 0000000..c850509 --- /dev/null +++ b/tests/functional/test_mktag/Test.php @@ -0,0 +1,18 @@ +2 * + + + + $i + $i + $_tag_parameters[b] + + + + \ No newline at end of file diff --git a/tests/functional/test_mktag/want b/tests/functional/test_mktag/want new file mode 100644 index 0000000..3e2351c --- /dev/null +++ b/tests/functional/test_mktag/want @@ -0,0 +1,11 @@ +0 +- +4 +- +8 +- +12 +- +16 +- +20 diff --git a/tests/functional/test_pseudotags/Test.php b/tests/functional/test_pseudotags/Test.php new file mode 100644 index 0000000..f64ff5f --- /dev/null +++ b/tests/functional/test_pseudotags/Test.php @@ -0,0 +1,18 @@ +Ignore $meFoo +$foo bar \ No newline at end of file diff --git a/tests/functional/test_pseudotags/want b/tests/functional/test_pseudotags/want new file mode 100644 index 0000000..3aaffdc --- /dev/null +++ b/tests/functional/test_pseudotags/want @@ -0,0 +1 @@ +$foo bar diff --git a/tests/functional/test_recursive/Test.php b/tests/functional/test_recursive/Test.php new file mode 100644 index 0000000..d393791 --- /dev/null +++ b/tests/functional/test_recursive/Test.php @@ -0,0 +1,19 @@ +mute_runtime_errors = false; + } +} diff --git a/tests/functional/test_recursive/test.tpl b/tests/functional/test_recursive/test.tpl new file mode 100644 index 0000000..bea3934 --- /dev/null +++ b/tests/functional/test_recursive/test.tpl @@ -0,0 +1,11 @@ + + + ~{$_tag_parameters[n]|eq|0} + 1 + + $_tag_parameters[n] - 1 + * $_tag_parameters[n] + + + + \ No newline at end of file diff --git a/tests/functional/test_recursive/want b/tests/functional/test_recursive/want new file mode 100644 index 0000000..3fbd4a8 --- /dev/null +++ b/tests/functional/test_recursive/want @@ -0,0 +1 @@ +3628800 diff --git a/tests/functional/test_scoping/Test.php b/tests/functional/test_scoping/Test.php new file mode 100644 index 0000000..b15f911 --- /dev/null +++ b/tests/functional/test_scoping/Test.php @@ -0,0 +1,18 @@ +A +B + + in foo: \$a = $a + in foo: \$b = $b + in foo: \$c = $c + X + Y + Z + in foo (after set): \$a = $a + in foo (after set): \$b = $b + in foo (after set): \$c = $c + + + +\$a = $a +\$b = $b +\$c = $c \ No newline at end of file diff --git a/tests/functional/test_scoping/want b/tests/functional/test_scoping/want new file mode 100644 index 0000000..6e7a154 --- /dev/null +++ b/tests/functional/test_scoping/want @@ -0,0 +1,9 @@ +in foo: $a = A +in foo: $b = B +in foo: $c = +in foo (after set): $a = X +in foo (after set): $b = Y +in foo (after set): $c = Z +$a = X +$b = B +$c = diff --git a/tests/functional/test_short/Test.php b/tests/functional/test_short/Test.php new file mode 100644 index 0000000..2b138f5 --- /dev/null +++ b/tests/functional/test_short/Test.php @@ -0,0 +1,18 @@ +set_var_by_name("data", array( + array('content' => 'foo', 'foo' => true), + array('content' => 'bar', 'foo' => false), + array('content' => 'baz', 'foo' => false), + )); + } +} diff --git a/tests/functional/test_short_for_additional_attribs/test.tpl b/tests/functional/test_short_for_additional_attribs/test.tpl new file mode 100644 index 0000000..e6b30e4 --- /dev/null +++ b/tests/functional/test_short_for_additional_attribs/test.tpl @@ -0,0 +1,5 @@ +
    + + $x[content] + +
\ No newline at end of file diff --git a/tests/functional/test_short_for_additional_attribs/want b/tests/functional/test_short_for_additional_attribs/want new file mode 100644 index 0000000..c46d63f --- /dev/null +++ b/tests/functional/test_short_for_additional_attribs/want @@ -0,0 +1,5 @@ +
    +
  • foo
  • +
  • bar
  • +
  • baz
  • +
diff --git a/tests/functional/test_simple/Test.php b/tests/functional/test_simple/Test.php new file mode 100644 index 0000000..e2b58d9 --- /dev/null +++ b/tests/functional/test_simple/Test.php @@ -0,0 +1,19 @@ +vars["foo"] = "World"; + } +} diff --git a/tests/functional/test_simple/test.tpl b/tests/functional/test_simple/test.tpl new file mode 100644 index 0000000..30a4f22 --- /dev/null +++ b/tests/functional/test_simple/test.tpl @@ -0,0 +1 @@ +Hello $foo! \ No newline at end of file diff --git a/tests/functional/test_simple/want b/tests/functional/test_simple/want new file mode 100644 index 0000000..980a0d5 --- /dev/null +++ b/tests/functional/test_simple/want @@ -0,0 +1 @@ +Hello World! diff --git a/tests/functional/test_static_numeric_array_access/Test.php b/tests/functional/test_static_numeric_array_access/Test.php new file mode 100644 index 0000000..0c6a853 --- /dev/null +++ b/tests/functional/test_static_numeric_array_access/Test.php @@ -0,0 +1,23 @@ +set_var_by_name("foo", array( + "foo", + "bar", + "baz", + )); + } +} diff --git a/tests/functional/test_static_numeric_array_access/test.tpl b/tests/functional/test_static_numeric_array_access/test.tpl new file mode 100644 index 0000000..a313c6b --- /dev/null +++ b/tests/functional/test_static_numeric_array_access/test.tpl @@ -0,0 +1,3 @@ +$foo[0] +$foo[1] +$foo[2] diff --git a/tests/functional/test_static_numeric_array_access/want b/tests/functional/test_static_numeric_array_access/want new file mode 100644 index 0000000..86e041d --- /dev/null +++ b/tests/functional/test_static_numeric_array_access/want @@ -0,0 +1,3 @@ +foo +bar +baz diff --git a/tests/functional/test_tagname/Test.php b/tests/functional/test_tagname/Test.php new file mode 100644 index 0000000..8e3d8f6 --- /dev/null +++ b/tests/functional/test_tagname/Test.php @@ -0,0 +1,33 @@ +register_tag( + $name, + function ($ste, $params, $sub) use ($name) { + return $name; + } + ); + } + } +} diff --git a/tests/functional/test_tagname/test.tpl b/tests/functional/test_tagname/test.tpl new file mode 100644 index 0000000..30ca889 --- /dev/null +++ b/tests/functional/test_tagname/test.tpl @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/tests/functional/test_tagname/want b/tests/functional/test_tagname/want new file mode 100644 index 0000000..3233294 --- /dev/null +++ b/tests/functional/test_tagname/want @@ -0,0 +1,4 @@ +foo +ab_cd +foo123baz +x0123 diff --git a/tests/functional/test_trailing_closing_array_bracket/Test.php b/tests/functional/test_trailing_closing_array_bracket/Test.php new file mode 100644 index 0000000..9e6ff2c --- /dev/null +++ b/tests/functional/test_trailing_closing_array_bracket/Test.php @@ -0,0 +1,23 @@ +set_var_by_name("foo", array( + "foo", + "bar", + "baz", + )); + } +} diff --git a/tests/functional/test_trailing_closing_array_bracket/test.tpl b/tests/functional/test_trailing_closing_array_bracket/test.tpl new file mode 100644 index 0000000..68f6caa --- /dev/null +++ b/tests/functional/test_trailing_closing_array_bracket/test.tpl @@ -0,0 +1,3 @@ +$foo[0] +$foo[1] +$foo[2] \ No newline at end of file diff --git a/tests/functional/test_trailing_closing_array_bracket/want b/tests/functional/test_trailing_closing_array_bracket/want new file mode 100644 index 0000000..86e041d --- /dev/null +++ b/tests/functional/test_trailing_closing_array_bracket/want @@ -0,0 +1,3 @@ +foo +bar +baz -- cgit v1.2.3-54-g00ecf