Exemplo n.º 1
0
        public void FindSuperglobalFields_Variable_ReturnsEmpty()
        {
            var tokens = GetTokens("<? $var1 = $_GET[$key]; ?>");

            var actual = StaticAnalyzer.FindSuperglobalFields(tokens);

            var expected = GetSuperglobalFields();

            AssertAreEqual(expected, actual);
        }
Exemplo n.º 2
0
        public void FindSuperglobalFields_SingleQuotedString_ReturnsSuperglobals()
        {
            var tokens = GetTokens("<? $var1 = $_GET['val1']; ?>");

            var actual = StaticAnalyzer.FindSuperglobalFields(tokens);

            var expected = GetSuperglobalFields();

            expected["$_GET"].Add("val1");

            AssertAreEqual(expected, actual);
        }
Exemplo n.º 3
0
        public void FindSuperglobalFields_Concatenated_ReturnsSuperglobals()
        {
            var tokens = GetTokens("<? $url = $_GET['title'].\"#\".$_GET['na']; ?>");

            var actual = StaticAnalyzer.FindSuperglobalFields(tokens);

            var expected = GetSuperglobalFields();

            expected["$_GET"].AddRange(new[] { "title", "na" });

            AssertAreEqual(expected, actual);
        }
Exemplo n.º 4
0
        public void FindSuperglobalFields_AllFields_ReturnsSuperglobals()
        {
            var tokens = GetTokensFromResource("PhpVH.Tests.Unit.Php.StaticAnalyzerSuperglobalFields.php");

            var actual = StaticAnalyzer.FindSuperglobalFields(tokens);

            var expected = GetSuperglobalFields();

            expected["$_GET"].Add("val1");
            expected["$_POST"].Add("val_2");
            expected["$_REQUEST"].Add("_var-3");
            expected["$_FILES"].Add("_$$REQUEST_var__4");
            expected["$_COOKIE"].Add("$REQUEST_var_5_");

            AssertAreEqual(expected, actual);
        }
Exemplo n.º 5
0
        public void FindSuperglobalFields_InIfBlocks_ReturnsSuperglobals()
        {
            var tokens = GetTokens("<?php\n" +
                                   "print_r($_GET);\n" +
                                   "if($_GET[\"a\"] === \"\") echo \"a is an empty string\n\";\n" +
                                   "if($_GET[\"b\"] === false) echo \"a is false\n\";\n" +
                                   "if($_GET[\"c\"] === null) echo \"a is null\n\";\n" +
                                   "if(isset($_GET[\"d\"])) echo \"a is set\n\";\n" +
                                   "if(!empty($_GET[\"e\"])) echo \"a is not empty\";\n" +
                                   "?>");

            var actual = StaticAnalyzer.FindSuperglobalFields(tokens);

            var expected = GetSuperglobalFields();

            expected["$_GET"].AddRange(new[] { "a", "b", "c", "d", "e" });

            AssertAreEqual(expected, actual);
        }