Permalink
Browse files

improving extract_template_parameter and creating tests for it

  • Loading branch information...
FlominatorTM committed Apr 6, 2016
1 parent 09f21c5 commit b993af382a1ae272d2c41e90c6fa81422f57a64d
Showing with 58 additions and 18 deletions.
  1. +57 −17 shared_inc/tests.php
  2. +1 −1 shared_inc/wiki_functions.inc.php
View
@@ -3,36 +3,76 @@
chdir("..");
include_once("shared_inc/wiki_functions.inc.php");
echo '<h1>extract_link_target</h2>';
test_it_link("[[User:Flominator]]", "User:Flominator", false);
test_it_link(" %nbsp; [[User:Flominator]] %nbsp; ", "User:Flominator", false);
test_it_link("[[User:Flominator|Flo]]", "User:Flominator", false);
test_it_link("[[Flominator|Flo]]", "Flominator", false);
test_it_link("[[Flo]]", "Flo", false);
test_it_link(" [[Flo]] ", "Flo", false);
test_it("[[User:Flominator]]", "User:Flominator", false);
test_it(" %nbsp; [[User:Flominator]] %nbsp; ", "User:Flominator", false);
test_it("[[User:Flominator|Flo]]", "User:Flominator", false);
test_it("[[Flominator|Flo]]", "Flominator", false);
test_it("[[Flo]]", "Flo", false);
test_it(" [[Flo]] ", "Flo", false);
test_it_link("[[User:Flominator]]", "Flominator", true);
test_it_link("[[User:Flominator|Flo]]", "Flominator", true);
test_it_link(" [[Flo]] ", "Flo", false);
test_it("[[User:Flominator]]", "Flominator", true);
test_it("[[User:Flominator|Flo]]", "Flominator", true);
test_it(" [[Flo]] ", "Flo", false);
test_it_link(" [[Flo ", false, false);
test_it_link("Flo ]] ", false, false);
test_it(" [[Flo ", false, false);
test_it("Flo ]] ", false, false);
test_it_link("there was [[User:Flominator|Flo]] and some other, which was called [[User:Lupo|]]", "User:Flominator", false);
test_it_link("there was [[User:Flominator]] and some other, which was called [[User:Lupo|]]", "User:Flominator", false);
test_it("there was [[User:Flominator|Flo]] and some other, which was called [[User:Lupo|]]", "User:Flominator", false);
test_it("there was [[User:Flominator]] and some other, which was called [[User:Lupo|]]", "User:Flominator", false);
echo '<h1>extract_template_parameter</h2>';
test_it_template("{{Bilderangebot|Benutzer=Flominator}}", "Benutzer", "Flominator");
test_it_template("{{Bilderangebot|Benutzer=Flominator|Param2=anderer}}", "Benutzer", "Flominator");
test_it_template("{{Bilderangebot|Benutzer=Flominator
|Param2=anderer}}", "Benutzer", "Flominator");
function test_it($in, $out_expected, $do_cut)
test_it_template("{{Bilderangebot|Benutzer=Flominator
|Param2=anderer}}", "Benutzer", "Flominator");
test_it_template("{{Bilderangebot|von=hier|Param2=und nicht von hier}}", "von", "hier");
test_it_template("{{Bilderangebot|Param2=und nicht von hier|von=hier}}", "von", "hier");
test_it_template("{{Bilderangebot|Param2=und nicht von hier| von = hier}}", "von", "hier");
test_it_template("{{Bilderangebot|Param2=und nicht von hier|von = hier}}", "von", "hier");
test_it_template("{{Bilderangebot|Param2=und nicht von hier| von = hier}}", "von", "hier");
test_it_template("{{Bilderangebot|Param2=und nicht von hier| von = hier}}", "von", "hier");
test_it_template("{{Bilderangebot|Param2=und nicht von hier|nach = hier}}", "von", "");
//$is_debug =true;
function test_it_link($in, $out_expected, $do_cut)
{
$out_actual = extract_link_target($in, $do_cut);
echo "Test case " . $in;
echo "Test case <pre>" . $in . '</pre>';
if($out_expected == $out_actual)
{
echo " <b>passed </b><br>";
echo " <b>passed </b>";
}
else
{
echo " failed. Result was $out_actual";
}
echo "<br><hr>";
}
function test_it_template($in_text, $in_parameter, $out_expected)
{
$out_actual = extract_template_parameter($in_text, $in_parameter);
echo "Test case <pre>" . $in_text . " => " . $in_parameter . '</pre>';
if($out_expected == $out_actual)
{
echo " <b>passed </b>";
}
else
{
echo " failed. Result was $out_actual<br>";
echo " failed. Result was $out_actual";
}
echo "<br><hr>";
}
Oops, something went wrong.

0 comments on commit b993af3

Please sign in to comment.