* under the terms of the Common Public License v1.0 which accompanies this
* distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html
******************************************************************************/
-import junit.framework.TestCase;
-import net.sourceforge.phpdt.internal.compiler.parser.Parser;
+import net.sourceforge.phpdt.core.tests.util.AbstractCompilerTest;
import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
/**
* Tests the php parser
*/
-public class PHPManualTestCase extends TestCase {
- Parser parser;
+public class PHPManualTestCase extends AbstractCompilerTest {
+// Parser parser;
public PHPManualTestCase(String name) {
super(name);
}
* Test the PHP Parser with different PHP snippets
*/
public void testPHPParser() {
+ checkPHP("if ((eregi(\"<[^>]*script*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
+ " (eregi(\"<[^>]*object*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
+ " (eregi(\"<[^>]*iframe*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
+ " (eregi(\"<[^>]*applet*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
+ " (eregi(\"<[^>]*meta*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
+ " (eregi(\"<[^>]*style*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
+ " (eregi(\"<[^>]*form*\\\"?[^>]*>\", $secvalue)) ||\r\n" +
+ " (eregi(\"\\([^>]*\\\"?[^)]*\\)\", $secvalue)) ||\r\n" +
+ " (eregi(\"\\\"\", $secvalue))) {\r\n" +
+ " die (\"<center><img src=images/logo.gif><br><br><b>The html tags you attempted to use are not allowed</b><br><br>[ <a href=\\\"javascript:history.go(-1)\\\"><b>Go Back</b></a> ]\");\r\n" +
+ " }");
checkPHP("function foo()" + "{" + " echo \"In foo()<br>\\n\";" + "}"
+ "" + "function bar($arg = '')" + "{"
+ " echo \"In bar(); argument was '$arg'.<br>\\n\";" + "}" + ""
+ " echo \"<hr>\\n\";\n" + "}\n" + "\n"
+ "// ...because you can simply type\n" + "if ($show_separators) {\n"
+ " echo \"<hr>\\n\";\n" + "}");
- checkPHP("echo gettype((bool) \"\"); // bool(false)\n"
- + "echo gettype((bool) 1); // bool(true)\n"
+ checkPHP( // "echo gettype((bool) \"\"); // bool(false)\n"
+ "echo gettype((bool) 1); // bool(true)\n"
+ "echo gettype((bool) -2); // bool(true)\n"
+ "echo gettype((bool) \"foo\"); // bool(true)\n"
+ "echo gettype((bool) 2.3e5); // bool(true)\n"
+ "echo 'This will not expand: \\n a newline';\n" + "\n"
+ "// Outputs: Variables do not $expand $either\n"
+ "echo 'Variables do not $expand $either';\n");
- checkPHP("$str = <<<EOD\n" + "Example of string\n"
- + "spanning multiple lines\n" + "using heredoc syntax.\n" + "EOD;\n"
- + "\n" + "/* More complex example, with variables. */\n"
- + "class foo\n" + "{\n" + " var $foo;\n" + " var $bar;\n" + "\n"
- + " function foo()\n" + " {\n" + " $this->foo = 'Foo';\n"
- + " $this->bar = array('Bar1', 'Bar2', 'Bar3');\n" + " }\n"
- + "}\n" + "\n" + "$foo = new foo();\n" + "$name = 'MyName';\n" + "\n"
- + "echo <<<EOT\n"
- + "My name is \"$name\". I am printing some $foo->foo.\n"
- + "Now, I am printing some {$foo->bar[1]}.\n"
- + "This should print a capital 'A': \\x41\n" + "EOT;\n");
+
checkPHP("echo \"This works: \" . $arr['foo'][3];");
checkPHP("echo \"\\$foo==$foo; type is \" . gettype ($foo) . \"<br />\\n\";");
checkPHP("$arr = array(\"foo\" => \"bar\", 12 => true);\n" + "\n"
System.out.println("\n------------------------------------");
System.out.println(strEval);
}
- parser.phpParserTester(strEval, 1);
- }
- private void checkHTML(String strEval) {
- if (Scanner.DEBUG) {
- System.out.println("\n------------------------------------");
- System.out.println(strEval);
- }
- parser.parse(strEval);
+ checkParsePHP(
+ strEval.toCharArray(),
+ "");
+// parser.phpParserTester(strEval, 1);
}
+// private void checkHTML(String strEval) {
+// if (Scanner.DEBUG) {
+// System.out.println("\n------------------------------------");
+// System.out.println(strEval);
+// }
+// parser.parse(strEval);
+// }
/**
* The JUnit setup method
*/
- protected void setUp() {
- parser = new Parser(null);
- }
+// protected void setUp() {
+// parser = new Parser(null);
+// }
}