From 07155a084db111c0586ce7ed958c87eed6116704 Mon Sep 17 00:00:00 2001 From: marcus Date: Fri, 17 Apr 2009 15:41:16 +0000 Subject: Closes #833: Kses now built as module git-svn-id: https://code.elgg.org/elgg/trunk@3222 36083f99-b078-4883-b0ff-0f9b5a30f544 --- vendors/kses/oop/test.oop.kses.php | 507 ------------------------------------- 1 file changed, 507 deletions(-) delete mode 100644 vendors/kses/oop/test.oop.kses.php (limited to 'vendors/kses/oop/test.oop.kses.php') diff --git a/vendors/kses/oop/test.oop.kses.php b/vendors/kses/oop/test.oop.kses.php deleted file mode 100644 index 8c6e885d8..000000000 --- a/vendors/kses/oop/test.oop.kses.php +++ /dev/null @@ -1,507 +0,0 @@ -= 5) - { - define('KSESTEST_VER', 5); - } - else - { - define('KSESTEST_VER', 4); - } - - // See if we're in command line or web - if($_SERVER["DOCUMENT_ROOT"] == "") - { - define('KSESTEST_ENV', 'CLI'); - } - else - { - define('KSESTEST_ENV', 'WEB'); - } - - if(KSESTEST_VER == 0) - { - $message = array( - "Error: Not using a current version of PHP!", - "You are using PHP version " . phpversion() . ".", - "KSES Class version requires PHP4 or better.", - "KSES test program ending." - ); - - displayPage( - array("title" => "Error running KSES test", "message" => $message) - ); - - exit(); - } - - $include_file = "php" . KSESTEST_VER . ".class.kses.php"; - if(file_exists($include_file) && is_readable($include_file)) - { - include_once($include_file); - } - else - { - $message = array( - "Error: Unable to find '" . $include_file . "'.", - "Please check your include path and make sure the file is available.", - "Path: " . ini_get('include_path') - ); - - displayPage( - array('title' => 'Unable to include ' . $include_file, 'message' => $message) - ); - - exit(); - } - - $kses_type = "kses" . KSESTEST_VER; - $myKses = new $kses_type; - - $test_text = array(); - $test_text = test1_protocols($myKses); - $test_text = array_merge($test_text, test1_html($myKses)); - $test_text = array_merge($test_text, test1_kses($myKses)); - - displayPage( - array('title' => 'New Test', 'message' => $test_text) - ); - - function test1_kses(&$myKses) - { - $out = array(output_hr(), "Testing current configuration"); - - $test_tags = array( - 'www.chaos.org', - 'Short \'a name\' tag', - 'Foo', - 'Bar', - 'Very Long String running to 1000 characters...', - 'Very Long String with a blue background', - 'New protocol test', - '', - 'bleep', - 'Another new protocol', - 'Test of "proto9"', - 'Bar!', - 'Long Cell' - ); - - $out_li = array(); - // Keep only allowed HTML from the presumed 'form'. - foreach($test_tags as $tag) - { - $temp = $myKses->Parse($tag); - $check = ($temp == $tag) ? true : false; - $text = ($temp == $tag) ? 'pass' : 'fail'; - - $li_text = output_testresult($check, $text) . output_newline(); - $li_text .= "Input:  " . output_translate($tag) . output_newline(); - $li_text .= "Output: " . output_translate($temp); - if(KSESTEST_ENV == 'CLI') - { - $li_text .= output_newline(); - } - - array_push($out_li, output_code_wrap($li_text)); - } - - $out = array_merge($out, array(output_ul($out_li))); - array_push($out, output_hr()); - array_push($out, "Testing is now finished."); - return $out; - } - - function output_code_wrap($text) - { - if(KSESTEST_ENV == 'CLI') - { - return $text; - } - else - { - return "\n$text\n"; - } - } - - function output_translate($text) - { - if(KSESTEST_ENV == 'CLI') - { - return $text; - } - else - { - return htmlentities($text); - } - } - - function output_testresult($pass = false, $text = "") - { - if(KSESTEST_ENV == 'CLI') - { - return '[' . $text . ']'; - } - else - { - if($pass == true) - { - return '[' . $text . ']'; - } - else - { - return '[' . $text . ']'; - } - } - } - - function output_spaces() - { - if(KSESTEST_ENV == 'WEB') - { - $out = "   "; - } - else - { - $out = " "; - } - - return $out; - } - - function output_newline() - { - if(KSESTEST_ENV == 'WEB') - { - $out = "
\n"; - } - else - { - $out = "\n"; - } - - return $out; - } - - function displayPage($data = array()) - { - $title = ($data['title'] == '') ? 'No title' : $data['title']; - $message = ($data['message'] == '') ? array('No message') : $data['message']; - - $out = ""; - - foreach($message as $text) - { - if(KSESTEST_ENV == 'WEB') - { - $header = "\t\t

$title

\n\t\t
\n"; - $out .= "\t\t

\n"; - $out .= "\t\t\t$text\n"; - $out .= "\t\t

\n"; - } - else - { - $header = "$title\n" . str_repeat('-', 60) . "\n\n"; - $out .= "\t$text\n\n"; - } - } - - if(KSESTEST_ENV == 'WEB') - { - echo "\n"; - echo "\t\n"; - echo "\t\t$title\n"; - echo "\t\n"; - echo "\t\n"; - echo $header; - echo $out; - echo "\t\n"; - echo "\n"; - } - else - { - echo $header; - echo $out; - } - } - - function output_hr() - { - if(KSESTEST_ENV == 'WEB') - { - return "\t\t\t
\n"; - } - else - { - return str_repeat(60, '-') . "\n"; - } - } - - function output_ul($data = array(), $padding = "") - { - if(!is_array($data) || count($data) < 1) - { - return ""; - } - - $text = ""; - if(KSESTEST_ENV == 'WEB') - { - $text = "\t\t\t
    \n"; - foreach($data as $li) - { - $text .= "\t\t\t\t
  • $li
  • \n"; - } - $text .= "\t\t\t
\n"; - } - else - { - foreach($data as $li) - { - $text .= $padding . " * $li\n"; - } - } - - return $text; - } - - function test1_protocols(&$myKses) - { - $default_prots = $myKses->dumpProtocols(); - $out_text = array(); - if(count($default_prots) > 0) - { - array_push($out_text, "Initial protocols from KSES" . KSESTEST_VER . ":"); - array_push($out_text, output_ul($default_prots)); - array_push($out_text, output_hr()); - } - - $myKses->AddProtocols(array("proto1", "proto2:", "proto3")); // Add a list of protocols - $myKses->AddProtocols("proto4:"); // Add a single protocol (Note ':' is optional at end) - $myKses->AddProtocol("proto9", "mystery:", "anarchy"); - $myKses->AddProtocol("alpha", "beta", "gamma:"); - - $add_protocol = "\t\t\t
    \n"; - $add_protocol .= "\t\t\t\t" . '
  1. $myKses->AddProtocols(array("proto1", "proto2:", "proto3"));
  2. ' . "\n"; - $add_protocol .= "\t\t\t\t" . '
  3. $myKses->AddProtocols("proto4:");
  4. ' . "\n"; - $add_protocol .= "\t\t\t\t" . '
  5. $myKses->AddProtocols("proto4:");
  6. ' . "\n"; - $add_protocol .= "\t\t\t\t" . '
  7. $myKses->AddProtocol("proto9", "mystery:", "anarchy");
  8. ' . "\n"; - $add_protocol .= "\t\t\t\t" . '
  9. $myKses->AddProtocol("alpha", "beta", "gamma:");
  10. ' . "\n"; - $add_protocol .= "\t\t\t
\n"; - - array_push($out_text, $add_protocol); - - $new_prots = $myKses->dumpProtocols(); - if(count($new_prots) > 0) - { - array_push($out_text, "New protocols from KSES" . KSESTEST_VER . " after using AddProtocol(s):"); - array_push($out_text, output_ul($new_prots)); - array_push($out_text, output_hr()); - } - - $myKses->RemoveProtocols(array("mystery", "anarchy:")); - $myKses->RemoveProtocols("alpha:"); - $myKses->RemoveProtocol("beta:"); - $myKses->RemoveProtocol("gamma"); - - $remove_protocol = "\t\t\t
    \n"; - $remove_protocol .= "\t\t\t\t" . '
  1. $myKses->RemoveProtocols(array("mystery", "anarchy:"));
  2. ' . "\n"; - $remove_protocol .= "\t\t\t\t" . '
  3. $myKses->RemoveProtocols("alpha:");
  4. ' . "\n"; - $remove_protocol .= "\t\t\t\t" . '
  5. $myKses->RemoveProtocol("beta:");
  6. ' . "\n"; - $remove_protocol .= "\t\t\t\t" . '
  7. $myKses->RemoveProtocol("gamma");
  8. ' . "\n"; - $remove_protocol .= "\t\t\t
\n"; - array_push($out_text, $remove_protocol); - - $new_prots = $myKses->dumpProtocols(); - if(count($new_prots) > 0) - { - array_push($out_text, "Resulting protocols from KSES" . KSESTEST_VER . " after using RemoveProtocol(s):"); - array_push($out_text, output_ul($new_prots)); - array_push($out_text, output_hr()); - } - - $myKses->SetProtocols(array("https", "gopher", "news")); - $set_protocol = "\t\t\t
    \n"; - $set_protocol .= "\t\t\t\t" . '
  1. $myKses->SetProtocols(array("https", "gopher", "news"));
  2. ' . "\n"; - $set_protocol .= "\t\t\t
\n"; - array_push($out_text, $set_protocol); - - $new_prots = $myKses->dumpProtocols(); - if(count($new_prots) > 0) - { - array_push($out_text, "Resulting protocols from KSES" . KSESTEST_VER . " after using SetProtocols:"); - array_push($out_text, output_ul($new_prots)); - array_push($out_text, output_hr()); - } - - // Invisible reset - $myKses->SetProtocols(array("http", "proto1", "proto2", "proto9")); - - return $out_text; - } - - function test1_html(&$myKses) - { - $out = array(); - - // Allows

|

tag - $myKses->AddHTML("p"); - - // Allows 'a' tag with href|name attributes, - // href has minlen of 10 chars, and maxlen of 25 chars - // name has minlen of 2 chars - $myKses->AddHTML( - "a", - array( - "href" => array('maxlen' => 25, 'minlen' => 10), - "name" => array('minlen' => 2) - ) - ); - - // Allows 'td' tag with colspan|rowspan|class|style|width|nowrap attributes, - // colspan has minval of 2 and maxval of 5 - // rowspan has minval of 3 and maxval of 6 - // class has minlen of 1 char and maxlen of 10 chars - // style has minlen of 10 chars and maxlen of 100 chars - // width has maxval of 100 - // nowrap is valueless - $myKses->AddHTML( - "td", - array( - "colspan" => array('minval' => 2, 'maxval' => 5), - "rowspan" => array('minval' => 3, 'maxval' => 6), - "class" => array("minlen" => 1, 'maxlen' => 10), - "width" => array("maxval" => 100), - "style" => array('minlen' => 10, 'maxlen' => 100), - "nowrap" => array('valueless' => 'y') - ) - ); - - array_push($out, "Modifying HTML Tests:"); - $code_text = "
\n";
-		$code_text .= "      //   Allows <p>|</p> tag\n";
-		$code_text .= "      \$myKses->AddHTML(\"p\");\n";
-		$code_text .= "\n";
-		$code_text .= "      //   Allows 'a' tag with href|name attributes,\n";
-		$code_text .= "      //   href has minlen of 10 chars, and maxlen of 25 chars\n";
-		$code_text .= "      //   name has minlen of  2 chars\n";
-		$code_text .= "      \$myKses->AddHTML(\n";
-		$code_text .= "         \"a\",\n";
-		$code_text .= "         array(\n";
-		$code_text .= "            \"href\" => array('maxlen' => 25, 'minlen' => 10),\n";
-		$code_text .= "            \"name\" => array('minlen' => 2)\n";
-		$code_text .= "         )\n";
-		$code_text .= "      );\n";
-		$code_text .= "\n";
-		$code_text .= "      //   Allows 'td' tag with colspan|rowspan|class|style|width|nowrap attributes,\n";
-		$code_text .= "      //      colspan has minval of   2       and maxval of 5\n";
-		$code_text .= "      //      rowspan has minval of   3       and maxval of 6\n";
-		$code_text .= "      //      class   has minlen of   1 char  and maxlen of   10 chars\n";
-		$code_text .= "      //      style   has minlen of  10 chars and maxlen of 100 chars\n";
-		$code_text .= "      //      width   has maxval of 100\n";
-		$code_text .= "      //      nowrap  is valueless\n";
-		$code_text .= "      \$myKses->AddHTML(\n";
-		$code_text .= "         \"td\",\n";
-		$code_text .= "         array(\n";
-		$code_text .= "            \"colspan\" => array('minval' =>   2, 'maxval' =>   5),\n";
-		$code_text .= "            \"rowspan\" => array('minval' =>   3, 'maxval' =>   6),\n";
-		$code_text .= "            \"class\"   => array(\"minlen\" =>   1, 'maxlen' =>  10),\n";
-		$code_text .= "            \"width\"   => array(\"maxval\" => 100),\n";
-		$code_text .= "            \"style\"   => array('minlen' =>  10, 'maxlen' => 100),\n";
-		$code_text .= "            \"nowrap\"  => array('valueless' => 'y')\n";
-		$code_text .= "         )\n";
-		$code_text .= "      );\n";
-		$code_text .= "
\n"; - - array_push($out, $code_text); - array_push($out, output_hr()); - array_push($out, "Net results:"); - - $out_elems = $myKses->DumpElements(); - if(count($out_elems) > 0) - { - //array_push($out, "\t\t\t
    \n"); - foreach($out_elems as $tag => $attr_data) - { - $out_li_elems = array(); - $elem_text = "(X)HTML element $tag"; - $allow = ""; - if(isset($attr_data) && is_array($attr_data) && count($attr_data) > 0) - { - $allow = " allows attribute"; - if(count($attr_data) > 1) - { - $allow .= "s"; - } - $allow .= ":\n"; - } - - array_push($out_li_elems, "$elem_text$allow"); - - $attr_test_li = array(); - if(isset($attr_data) && is_array($attr_data) && count($attr_data) > 0) - { - foreach($attr_data as $attr_name => $attr_tests) - { - $li_text = $attr_name; - if(isset($attr_tests) && count($attr_tests) > 0) - { - foreach($attr_tests as $test_name => $test_val) - { - switch($test_name) - { - case "maxlen": - $li_text .= " - maximum length of '" . $test_val . "' characters"; - break; - case "minlen": - $li_text .= " - minimum length of '" . $test_val . "' characters"; - break; - case "minval": - $li_text .= " - minimum value of '" . $test_val . "'"; - break; - case "maxval": - $li_text .= " - maximum value of '" . $test_val . "'"; - break; - case "valueless": - switch(strtolower($test_val)) - { - case 'n': - $li_text .= " - must not be valueless"; - break; - case 'y': - $li_text .= " - must be valueless"; - break; - default: - break; - } - break; - default: - break; - } - } - } - array_push($attr_test_li, $li_text); - } - if(count($attr_test_li) > 0) - { - $attr_test_li = output_ul($attr_test_li, " "); - $out_li_elems = array("$elem_text$allow$attr_test_li"); - } - } - $out = array_merge($out, $out_li_elems); - } - } - - return $out; - } - -?> \ No newline at end of file -- cgit v1.2.3