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 junit.framework.TestCase;
12 import net.sourceforge.phpeclipse.phpeditor.PHPParser;
15 * Tests the php parser
17 public class PHPParserTestCase extends TestCase {
21 public PHPParserTestCase(String name) {
26 * Test the PHP Parser with different PHP snippets
28 public void testPHPParser() {
29 check("if (isset($test)) { } elseif (isset($lang)) { }");
30 check("require_once(\"mainfile.php\"); ");
31 check("if (eregi(\"footer.php\",$PHP_SELF)) {\n" + "Header(\"Location: index.php\");\n" + "die();\n" + "}\n");
32 check("while (eregi(\"footer.php\",$PHP_SELF)) {\n" + "Header(\"Location: index.php\");\n" + "die();\n" + "}\n");
33 check("while (eregi(\"footer.php\",$PHP_SELF)) :\n" + "Header(\"Location: index.php\");\n" + "die();\n" + "endwhile;\n");
34 check("$tipath = \"images/topics/\";");
35 check("$reasons = array(\"1\", \"2\",\"test\");");
36 check("if ($home == 1) { message_box(); blocks(Center);}");
37 check("$bresult = sql_query(\"select * from \".$prefix.\"_banner WHERE type='0' AND active='1'\", $dbi);");
38 check("switch($func) {\n case \"f1\":\n f1();\n break; \n default: \n f0(); \n break;\n }");
39 check("list ($catid) = sql_fetch_row($result, $dbi);");
40 check("if (!$name) { \n }");
41 check("mt_srand((double)microtime()*1000000);");
43 check("$alttext = ereg_replace(\"\\\"\", \"\", $alttext);");
44 check("$message .= \"\"._THISISAUTOMATED.\"\\n\\n\";");
45 check("if (!empty($pass) AND $pass==$passwd) { }");
46 check("$AllowableHTML = array(\"b\"=>1,\n \"i\"=>1);");
47 check("if ($term{0}!=$firstChar) {}");
48 check("echo \"<center><b>\"._NOADMINYET.\"</b></center><br><br>\"\n"
49 + ".\"<form action=\\\"admin.php\\\" method=\\\"post\\\">\"\n"
50 + ".\"<tr><td><b>\"._NICKNAME.\":</b></td><td><input type=\\\"text\\\" name=\\\"name\\\" size=\\\"30\\\" maxlength=\\\"25\\\"></td></tr>\"\n"
54 public void check(String strEval) {
55 parser.start(strEval, 1);
59 * The JUnit setup method
61 protected void setUp() {
62 parser = new PHPParser();