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