1 package junit.sourceforge.phpeclipse;
2 /**********************************************************************
3 Copyright (c) 2002 Klaus Hartlage - www.eclipseproject.de
4 All rights reserved. This program and the accompanying materials
5 are made available under the terms of the Common Public License v1.0
6 which accompanies this distribution, and is available at
7 http://www.eclipse.org/legal/cpl-v10.html
8 **********************************************************************/
10 import org.eclipse.core.runtime.CoreException;
12 import junit.framework.TestCase;
14 import net.sourceforge.phpeclipse.phpeditor.PHPParser;
17 * Tests the php parser
19 public class PHPParserTestCase extends TestCase {
23 public PHPParserTestCase(String name) {
28 * Test the PHP Parser with different PHP snippets
30 public void testPHPParser() {
31 checkHTML("<?php phpinfo(); ?>");
32 checkHTML("<?php phpinfo()?>");
33 checkHTML("<?php phpinfo(); ?> foo <?php phpinfo(); ?>");
34 checkPHP("if (isset($test)) { } elseif (isset($lang)) { }");
35 checkPHP("require_once(\"mainfile.php\"); ");
36 checkPHP("if (eregi(\"footer.php\",$PHP_SELF)) {\n" + "Header(\"Location: index.php\");\n" + "die();\n" + "}\n");
37 checkPHP("while (eregi(\"footer.php\",$PHP_SELF)) {\n" + "Header(\"Location: index.php\");\n" + "die();\n" + "}\n");
38 checkPHP("while (eregi(\"footer.php\",$PHP_SELF)) :\n" + "Header(\"Location: index.php\");\n" + "die();\n" + "endwhile;\n");
39 checkPHP("$tipath = \"images/topics/\";");
40 checkPHP("$reasons = array(\"1\", \"2\",\"test\");");
41 checkPHP("if ($home == 1) { message_box(); blocks(Center);}");
42 checkPHP("$bresult = sql_query(\"select * from \".$prefix.\"_banner WHERE type='0' AND active='1'\", $dbi);");
43 checkPHP("switch($func) {\n case \"f1\":\n f1();\n break; \n default: \n f0(); \n break;\n }");
44 checkPHP("list ($catid) = sql_fetch_row($result, $dbi);");
45 checkPHP("if (!$name) { \n }");
46 checkPHP("mt_srand((double)microtime()*1000000);");
47 checkPHP("\"\\\"\";");
48 checkPHP("$v->read();");
49 checkPHP("$alttext = ereg_replace(\"\\\"\", \"\", $alttext);");
50 checkPHP("$message .= \"\"._THISISAUTOMATED.\"\\n\\n\";");
51 checkPHP("if (!empty($pass) AND $pass==$passwd) { }");
52 checkPHP("$AllowableHTML = array(\"b\"=>1,\n \"i\"=>1);");
53 checkPHP("if ($term{0}!=$firstChar) {}");
55 "echo \"<center><b>\"._NOADMINYET.\"</b></center><br><br>\"\n"
56 + ".\"<form action=\\\"admin.php\\\" method=\\\"post\\\">\"\n"
57 + ".\"<tr><td><b>\"._NICKNAME.\":</b></td><td><input type=\\\"text\\\" name=\\\"name\\\" size=\\\"30\\\" maxlength=\\\"25\\\"></td></tr>\"\n"
59 checkPHP("/* \n overLib is from Eric Bosrup (http://www.bosrup.com/web/overlib/) \n */");
60 checkPHP("if ($arrAtchCookie[1]==0 && $IdAtchPostId!=null){ } ");
61 checkPHP("$arrAtchCookie[1] -= filesize(realpath($AtchTempDir).\"/\".$xattachlist)/ 1024; ");
63 "if (!isset($message)){ \n"
64 + "$message = $myrow[post_text];\n"
65 + "$message = eregi_replace(\"\\[addsig]\", \"\\n-----------------\\n\" . $myrow[user_sig], $message); \n"
66 + "$message = str_replace(\"<BR>\", \"\\n\", $message); \n"
67 + "$message = str_replace(\"<br>\", \"\\n\", $message); \n } ");
68 checkPHP("do {$array[] = array(\"$myrow[uid]\" => \"$myrow[uname]\"); } while($myrow = mysql_fetch_array($result));");
69 checkPHP("$ol = new Overlib();");
70 checkPHP("$risultato = mysql_query($sql) or\n die(mysql_error());");
73 private void checkPHP(String strEval) {
75 parser.phpParse(strEval, 1);
76 } catch (CoreException e) {
80 private void checkHTML(String strEval) {
81 parser.htmlParse(strEval);
85 * The JUnit setup method
87 protected void setUp() {
88 parser = new PHPParser(null);