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