improved php parser for keywords do-while, null, false, true...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / junit / sourceforge / phpeclipse / PHPParserTestCase.java
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 **********************************************************************/
9
10 import junit.framework.TestCase;
11
12 import net.sourceforge.phpeclipse.phpeditor.PHPParser;
13
14 /**
15  *  Tests the php parser
16  */
17 public class PHPParserTestCase extends TestCase {
18
19   PHPParser parser;
20
21   public PHPParserTestCase(String name) {
22     super(name);
23   }
24
25   /**
26    *  Test the PHP Parser with different PHP snippets
27    */
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);");
42     check("\"\\\"\";");
43     check("$v->read();");
44     check("$alttext = ereg_replace(\"\\\"\", \"\", $alttext);");
45     check("$message .= \"\"._THISISAUTOMATED.\"\\n\\n\";");
46     check("if (!empty($pass) AND $pass==$passwd) { }");
47     check("$AllowableHTML = array(\"b\"=>1,\n \"i\"=>1);");
48     check("if ($term{0}!=$firstChar) {}");
49     check("echo \"<center><b>\"._NOADMINYET.\"</b></center><br><br>\"\n"
50     + ".\"<form action=\\\"admin.php\\\" method=\\\"post\\\">\"\n"
51     + ".\"<tr><td><b>\"._NICKNAME.\":</b></td><td><input type=\\\"text\\\" name=\\\"name\\\" size=\\\"30\\\" maxlength=\\\"25\\\"></td></tr>\"\n"
52     +";");
53     check("/* \n overLib is from Eric Bosrup (http://www.bosrup.com/web/overlib/) \n */");
54     check("if ($arrAtchCookie[1]==0 && $IdAtchPostId!=null){  } ");
55     check("$arrAtchCookie[1] -= filesize(realpath($AtchTempDir).\"/\".$xattachlist)/ 1024; ");
56     check("if (!isset($message)){ \n"
57     + "$message = $myrow[post_text];\n"
58     + "$message = eregi_replace(\"\\[addsig]\", \"\\n-----------------\\n\" .    $myrow[user_sig], $message); \n"
59     +"$message = str_replace(\"<BR>\", \"\\n\", $message); \n"
60     +"$message = str_replace(\"<br>\", \"\\n\", $message); \n } ");
61     check("do {$array[] = array(\"$myrow[uid]\" => \"$myrow[uname]\"); } while($myrow = mysql_fetch_array($result));");
62     check("$ol = new Overlib();");
63   }
64
65   public void check(String strEval) {
66     parser.start(strEval, 1);
67   }
68
69   /**
70    *  The JUnit setup method
71    */
72   protected void setUp() {
73     parser = new PHPParser();
74   }
75
76 }