misc parser changes
[phpeclipse.git] / net.sourceforge.phpeclipse.tests / src / net / sourceforge / phpeclipse / tests / parser / PHPParserTestCase.java
1 package net.sourceforge.phpeclipse.tests.parser;
2 /*******************************************************************************
3  * Copyright (c) 2002 Klaus Hartlage - www.eclipseproject.de All rights
4  * reserved. This program and the accompanying materials are made available
5  * under the terms of the Common Public License v1.0 which accompanies this
6  * distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html
7  ******************************************************************************/
8 import net.sourceforge.phpdt.core.tests.util.AbstractCompilerTest;
9 import net.sourceforge.phpdt.internal.compiler.parser.Parser;
10 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
11 /**
12  * Tests the php parser
13  */
14 public class PHPParserTestCase extends AbstractCompilerTest {
15 //  Parser parser;
16   public PHPParserTestCase(String name) {
17     super(name);
18   }
19   /**
20    * Test the PHP Parser with different PHP snippets
21    */
22   public void testPHPParser() {
23     checkHTML("<?php echo $bgcolor2?>");
24     checkPHP("if ($topic<1) { $topic = 1;}");
25     checkPHP("$this->result_field_names[$result_id][] = odbc_field_name($result_id, $i);");
26     checkPHP("$db->sql_query($sql);");
27     checkPHP("$val = $$add;");
28     //  checkPHP("if(!$result = mysql_query($sql)) return(array());");
29     checkPHP("class test { function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) \n{ \n } \n }");
30     // Bugs item #690938
31     checkPHP("$ebus_sql['sel_url_list'] = <<<EOS\n"
32         + "select rtrim(URL_NAME) as url_name\n" + "    , rtrim(URL) as url\n"
33         + "     , rtrim(URL_DESC) as url_desc\n" + "from appl_url\n"
34         + "where appl_instnc_sk = <<INSTNC>>\n"
35         + "and appl_sect_deftn_sk = <<SECT>>\n" + "order by url_ord\n"
36         + "EOS;\n");
37     checkPHP("foreach ($HTTP_GET_VARS as $secvalue) { }");
38     checkPHP("\"\\\"\";");
39     checkPHP("\"\\[addsig]\"");
40     checkPHP("$v->read();");
41     checkPHP("$add = 'a'.$i;$val = $$add;");
42     checkPHP("($a==\"b\") || (c($this->x)==\"d\");");
43     checkPHP("(substr($this->file, 0, 2) == \"MM\");");
44     checkPHP("(substr($this->file, 0, 2) == \"MM\") || substr($this->file, 0, 2) == \"II\";");
45     checkPHP("return (substr($this->file, 0, 2) == \"MM\") || substr($this->file, 0, 2) == \"II\";");
46     checkPHP("$this->highlightfile->linkscripts{$category}");
47     checkPHP("$code = call_user_method($this->highlightfile->linkscripts{$category}, $this->highlightfile, $oldword, $this->output_module)");
48     checkPHP("$this->startmap[$startcurrtag]();");
49     checkPHP("new $this->startmap[$startcurrtag]();");
50     checkPHP("$this->highlightfile = new $this->startmap[$startcurrtag]();");
51     checkPHP("echo \"Test\", \"me\";");
52     checkPHP("print (\"Test me\");");
53     checkPHP("$s = <<<HEREDOC \n dskjfhskj\n \n\nHEREDOC;");
54     checkPHP("$a == 0 ? print \"true\" : print \"false\";");
55     checkPHP("call_user_method_array($function_name[1], ${$objectname}, $arguments);");
56     checkPHP("@$connect_function($dbhost, $user, $pw);");
57     checkPHP("$conn = @$connect_function($dbhost, $user, $pw);");
58     checkPHP("global ${$objectname}; ");
59    // checkPHP("class DB_mssql extends DB_common { var $connection; var $phptype, $dbsyntax; }  ");
60     checkPHP("unset($this->blockvariables[$block][$varname]);");
61     checkPHP("new IT_Error(\"The block '$block' was not found in the template.\", __FILE__, __LINE__);");
62     checkPHP("for ($i=156, $j=0; $i<512; $i++, $j++) $v_checksum += ord(substr($v_binary_data_last,$j,1));");
63     checkPHP("define('MAIL_MIME_CRLF', $crlf, true);");
64     checkPHP("static $last_run = 0;");
65     checkPHP("unset($headers['Subject']);");
66     checkPHP("switch($func) {\n case \"f0\":\n case \"f1\":\n f1();\n break; \n case \"tt\": \n default: \n f0(); \n break;\n }");
67     checkPHP("function validateAndParseResponse($code, &$arguments) { }");
68     checkPHP("$options = Console_Getopt::getopt($argv, \"h?v:e:p:d:\");");
69     checkPHP("$this->container = new $container_class($container_options);");
70    // checkPHP("class Cmd extends PEAR { var $arrSetting     = array(); }");
71   //  checkPHP("class Cmd extends PEAR { var $arrSetting     = array(), $i=10; }");
72     checkPHP("if (isset($test)) { } elseif (isset($lang)) { }");
73     checkPHP("require_once(\"mainfile.php\");  ");
74     checkPHP("if (eregi(\"footer.php\",$PHP_SELF)) {\n"
75         + "Header(\"Location: index.php\");\n" + "die();\n" + "}\n");
76     checkPHP("while (eregi(\"footer.php\",$PHP_SELF)) {\n"
77         + "Header(\"Location: index.php\");\n" + "die();\n" + "}\n");
78     checkPHP("while (eregi(\"footer.php\",$PHP_SELF)) :\n"
79         + "Header(\"Location: index.php\");\n" + "die();\n" + "endwhile;\n");
80     checkPHP("$tipath = \"images/topics/\";");
81     checkPHP("$reasons = array(\"1\", \"2\",\"test\");");
82     checkPHP("if ($home == 1) { message_box(); blocks(Center);}");
83     checkPHP("$bresult = sql_query(\"select * from \".$prefix.\"_banner WHERE type='0' AND active='1'\", $dbi);");
84     checkPHP("switch($func) {\n case \"f1\":\n f1();\n break; \n default: \n f0(); \n break;\n }");
85     checkPHP("list ($catid) = sql_fetch_row($result, $dbi);");
86     checkPHP("if (!$name) { \n }");
87     checkPHP("mt_srand((double)microtime()*1000000);");
88     checkPHP("$alttext = ereg_replace(\"\\\"\", \"\", $alttext);");
89     checkPHP("$message .= \"\"._THISISAUTOMATED.\"\\n\\n\";");
90     checkPHP("if (!empty($pass) AND $pass==$passwd) { }");
91     checkPHP("$AllowableHTML = array(\"b\"=>1,\n \"i\"=>1);");
92     checkPHP("if ($term{0}!=$firstChar) {}");
93     checkPHP("echo \"<center><b>\"._NOADMINYET.\"</b></center><br><br>\"\n"
94         + ".\"<form action=\\\"admin.php\\\" method=\\\"post\\\">\"\n"
95         + ".\"<tr><td><b>\"._NICKNAME.\":</b></td><td><input type=\\\"text\\\" name=\\\"name\\\" size=\\\"30\\\" maxlength=\\\"25\\\"></td></tr>\"\n"
96         + ";");
97     checkPHP("/* \n overLib is from Eric Bosrup (http://www.bosrup.com/web/overlib/) \n */");
98     checkPHP("if ($arrAtchCookie[1]==0 && $IdAtchPostId!=null){  } ");
99     checkPHP("$arrAtchCookie[1] -= filesize(realpath($AtchTempDir).\"/\".$xattachlist)/ 1024; ");
100     checkPHP("if (!isset($message)){ \n"
101         + "$message = $myrow[post_text];\n"
102         + "$message = eregi_replace(\"\\[addsig]\", \"\\n-----------------\\n\" .    $myrow[user_sig], $message); \n"
103         + "$message = str_replace(\"<BR>\", \"\\n\", $message); \n"
104         + "$message = str_replace(\"<br>\", \"\\n\", $message); \n } ");
105     checkPHP("do {$array[] = array(\"$myrow[uid]\" => \"$myrow[uname]\"); } while($myrow = mysql_fetch_array($result));");
106     checkPHP("$ol = new Overlib();");
107     checkPHP("$risultato = mysql_query($sql) or\n    die(mysql_error());");
108 //    checkHTML("\n\n\n\n  <?php print \"Hello world\" ?>");
109 //    checkHTML("<?php phpinfo(); ?>");
110 //    checkHTML("<?php phpinfo()?>");
111 //    checkHTML("<?php phpinfo(); ?> foo <?php phpinfo(); ?>");
112 //    checkHTML(" <?php //this is a line comment ?>");
113 //    checkHTML("<?php echo $module_name ?>");
114   }
115   private void checkPHP(String strEval) {
116     if (Scanner.DEBUG) {
117       System.out.println("\n------------------------------------");
118       System.out.println(strEval);
119     }
120     checkParsePHP(
121         strEval.toCharArray(),
122                 "");
123 //    parser.phpParserTester(strEval, 1);
124   }
125   private void checkHTML(String strEval) {
126     if (Scanner.DEBUG) {
127       System.out.println("\n------------------------------------");
128       System.out.println(strEval);
129     }
130     checkParseHTML(
131         strEval.toCharArray(),
132                 "");
133 //    parser.phpParserTester(strEval, 1);
134   }
135 //  private void checkHTML(String strEval) {
136 //    if (Scanner.DEBUG) {
137 //      System.out.println("\n------------------------------------");
138 //      System.out.println(strEval);
139 //    }
140 //    parser.parse(strEval);
141 //  }
142 //  /**
143 //   * The JUnit setup method
144 //   */
145 //  protected void setUp() {
146 //    parser = new Parser(null);
147 //  }
148 }