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 **********************************************************************/
11 import org.eclipse.core.runtime.CoreException;
12 import junit.framework.TestCase;
14 import java.io.CharArrayReader;
18 * Tests the php parser
20 public class PHPParserTestCase2 extends TestCase {
24 public PHPParserTestCase2(String name) {
29 * Test the PHP Parser with different PHP snippets
31 public void testPHPParser() {
32 checkHTML("<?php $a = &$b; ?>");
33 checkHTML("<?php ec ho 'coucou'; ?>" +
42 checkHTML("<?php echo 'coucou'; ?>" +
50 "\n//if (!isset($AtreidesLanguage)) $AtreidesLanguage='french';" +
51 "\n$AtreidesLanguage='french';" +
53 "\n\ninclude_once('php/template.inc');" +
54 "\ninclude ' php/class.PHPLIBTemplateAdaptor.php';" +
55 "\ninclude 'php/class.CachedTemplate.php';" +
56 "\n$_PHPLIB['libdir']='php/';" +
57 "\ninclude 'php/oohforms.inc';" +
58 "\n include 'objet/outil.php';" +
59 "\ninclude 'objet/metier.php';" +
60 "\ninclude 'php/db_mysql.inc';" +
61 "\ninclude 'objet/db5.php';" +
62 "\ninclude 'objet/gui.php';" +
63 "\ninclude 'objet/application.php';" +
64 "\n//----------------------------------------------------" +
65 "\n// Objets du site" +
66 "\n//----------------------------------------------------" +
67 "\n// Objets de base de donnée" +
68 "\ninclude 'atreides/db_soft.php';" +
69 "\n// Objets metier" +
70 "\ninclude 'atreides/soft.php';" +
71 "\n// Objets application" +
72 "\ninclude 'atreides/atreides.php';" +
73 "\n$AtreidesTheme='normal/$AtreidesLanguage';" +
74 "\nif(Vide($oCentral)) $oCentral='Soft';" +
75 "\nif (vide($oModeCentral)) $oModeCentral = 'recherche';" +
76 "\nif (Vide($theme)) $theme='normal';" +
77 "\nif (Vide($mode)) $mode='visu';" +
78 "\n$Atreides=new Atreides($mode,$ini);" +
79 "\n$Atreides->tabAffich['oModeCentral']=$oModeCentral;" +
80 "\nob_start('ob_gzhandler');" +
81 "\necho $Atreides->vueMetier('visu',$AtreidesTheme);" +
83 checkHTML("<html>sdfsdf <?php phpinfo(); ?>");
84 checkHTML("\n\n\n\n <?php print \"Hello world\"?> ");
85 checkHTML("<?php phpinfo()?>");
86 checkHTML("<?php phpinfo(); ?> foo <?php phpinfo(); ?>");
87 checkHTML(" <?php //this is a line comment ?>");
89 checkPHP("if $cac a) echo 'coucou';");
90 checkPHP("$oka dd = 'a'.$i;$val = $$add;");
91 checkPHP("($a==\"b\") || (c($this->x)==\"d\");");
92 checkPHP("(substr($this->file, 0, 2) == \"MM\");");
93 checkPHP("(substr($this->file, 0, 2) == \"MM\") || substr($this->file, 0, 2) == \"II\";");
94 checkPHP("return (substr($this->file, 0, 2) == \"MM\") || substr($this->file, 0, 2) == \"II\";");
95 checkPHP("$this->highlightfile->linkscripts{$category};");
96 checkPHP("$code = call_user_method($this->highlightfile->linkscripts{$category}, $this->highlightfile, $oldword, $this->output_module);");
97 checkPHP("$this->startmap[$startcurrtag]();");
98 checkPHP("new $this->startmap[$startcurrtag]();");
99 checkPHP("$this->highlightfile = new $this->startmap[$startcurrtag]();");
100 checkPHP("echo \"Test\", \"me\";");
101 checkPHP("print (\"Test me\");");
102 // checkPHP("$s = <<<HEREDOC \n dskjfhskj\n \n\nHEREDOC;");
103 // checkPHP("$a == 0 ? print \"true\" : print \"false\";");
104 checkPHP("if(!$result = mysql_query($sql)) return(array());");
105 checkPHP("class test { function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) \n{ \n } \n }");
106 checkPHP("call_user_method_array($function_name[1], ${$objectname}, $arguments);");
107 checkPHP("@$connect_function($dbhost, $user, $pw);");
108 checkPHP("$conn = @$connect_function($dbhost, $user, $pw);");
109 checkPHP("global ${$objectname}; ");
110 checkPHP("class DB_mssql extends DB_common { var $connection; var $phptype, $dbsyntax; } ");
111 checkPHP("unset($this->blockvariables[$block][$varname]);");
112 checkPHP("new IT_Error(\"The block '$block' was not found in the template.\", __FILE__, __LINE__);");
113 checkPHP("for ($i=156, $j=0; $i<512; $i++, $j++) $v_checksum += ord(substr($v_binary_data_last,$j,1));");
114 checkPHP("define('MAIL_MIME_CRLF', $crlf, true);");
115 checkPHP("static $last_run = 0;");
116 checkPHP("unset($headers['Subject']);");
117 checkPHP("switch($func) {\n case \"f0\":\n case \"f1\":\n f1();\n break; \n case \"tt\": \n default: \n f0(); \n break;\n }");
118 checkPHP("function validateAndParseResponse($code, &$arguments) { }");
119 checkPHP("$options = Console_Getopt::getopt($argv, \"h?v:e:p:d:\");");
120 checkPHP("$this->container = new $container_class($container_options);");
121 checkPHP("class Cmd extends PEAR { var $arrSetting = array(); }");
122 checkPHP("class Cmd extends PEAR { var $arrSetting = array(), $i=10; }");
123 checkPHP("if (isset($test)) { } elseif (isset($lang)) { }");
124 checkPHP("require_once(\"mainfile.php\"); ");
125 checkPHP("if (eregi(\"footer.php\",$PHP_SELF)) {\n" + "Header(\"Location: index.php\");\n" + "die();\n" + "}\n");
126 checkPHP("while (eregi(\"footer.php\",$PHP_SELF)) {\n" + "Header(\"Location: index.php\");\n" + "die();\n" + "}\n");
127 checkPHP("while (eregi(\"footer.php\",$PHP_SELF)) :\n" + "Header(\"Location: index.php\");\n" + "die();\n" + "endwhile;\n");
128 checkPHP("$tipath = \"images/topics/\";");
129 checkPHP("$reasons = array(\"1\", \"2\",\"test\");");
130 checkPHP("if ($home == 1) { message_box(); blocks(Center);}");
131 checkPHP("$bresult = sql_query(\"select * from \".$prefix.\"_banner WHERE type='0' AND active='1'\", $dbi);");
132 checkPHP("switch($func) {\n case \"f1\":\n f1();\n break; \n default: \n f0(); \n break;\n }");
133 checkPHP("list ($catid) = sql_fetch_row($result, $dbi);");
134 checkPHP("if (!$name) { \n }");
135 checkPHP("mt_srand((double)microtime()*1000000);");
136 checkPHP("\"\\\"\";");
137 checkPHP("$v->read();");
138 checkPHP("$alttext = ereg_replace(\"\\\"\", \"\", $alttext);");
139 checkPHP("$message .= \"\"._THISISAUTOMATED.\"\\n\\n\";");
140 checkPHP("if (!empty($pass) AND $pass==$passwd) { }");
141 checkPHP("$AllowableHTML = array(\"b\"=>1,\n \"i\"=>1);");
142 checkPHP("if ($term{0}!=$firstChar) {}");
144 "echo \"<center><b>\"._NOADMINYET.\"</b></center><br><br>\"\n"
145 + ".\"<form action=\\\"admin.php\\\" method=\\\"post\\\">\"\n"
146 + ".\"<tr><td><b>\"._NICKNAME.\":</b></td><td><input type=\\\"text\\\" name=\\\"name\\\" size=\\\"30\\\" maxlength=\\\"25\\\"></td></tr>\"\n"
148 checkPHP("/* \n overLib is from Eric Bosrup (http://www.bosrup.com/web/overlib/) \n */;");
149 checkPHP("if ($arrAtchCookie[1]==0 && $IdAtchPostId!=null){ } ");
150 checkPHP("$arrAtchCookie[1] -= filesize(realpath($AtchTempDir).\"/\".$xattachlist)/ 1024; ");
152 "if (!isset($message)){ \n"
153 + "$message = $myrow[post_text];\n"
154 + "$message = eregi_replace(\"\\[addsig]\", \"\\n-----------------\\n\" . $myrow[user_sig], $message); \n"
155 + "$message = str_replace(\"<BR>\", \"\\n\", $message); \n"
156 + "$message = str_replace(\"<br>\", \"\\n\", $message); \n } ");
157 checkPHP("do {$array[] = array(\"$myrow[uid]\" => \"$myrow[uname]\"); } while($myrow = mysql_fetch_array($result));");
158 checkPHP("$ol = new Overlib();");
159 checkPHP("$risultato = mysql_query($sql) or\n die(mysql_error());");
162 private void checkPHP(String strEval) {
164 System.out.println("strEval = " + strEval);
165 parser.phpParserTester(strEval);
166 } catch (CoreException e) {
168 } catch (ParseException e) {
173 private void checkHTML(String strEval) {
175 System.out.println("strEval = " + strEval);
176 parser.htmlParserTester(strEval);
177 } catch (CoreException e) {
179 } catch (ParseException e) {
186 * The JUnit setup method
188 protected void setUp() {
189 parser = (test.PHPParser) PHPParserManager.getParser();