DereferenceShortcodeVarsTest.php
5.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
include_once(dirname(dirname(__FILE__)) . '/DereferenceShortcodeVars.php');
class DereferenceShortcodeVarsTest extends PHPUnit_Framework_TestCase {
public function test() {
$dref = new DereferenceShortcodeVars;
$this->assertEquals('stuff', $dref->extractParamName('_POST', '$_POST(\'stuff\')'));
}
public function testf() {
$dref = new DereferenceShortcodeVars;
$this->assertEquals('', $dref->extractParamName('_POST', '$_POSTxxxx(\'stuff\')'));
}
public function test_doublequotes() {
$dref = new DereferenceShortcodeVars;
$this->assertEquals('stuff', $dref->extractParamName('_POST', '$_POST("stuff")'));
}
public function testf_doublequotes() {
$dref = new DereferenceShortcodeVars;
$this->assertEquals('', $dref->extractParamName('_POST', '$_POSTx("stuff")'));
}
public function test_noquotes() {
$dref = new DereferenceShortcodeVars;
$this->assertEquals('stuff', $dref->extractParamName('_POST', '$_POST(stuff)'));
}
public function test_mixedQuotes() {
$dref = new DereferenceShortcodeVars;
$this->assertEquals('"stuff\'', $dref->extractParamName('_POST', '$_POST("stuff\')'));
}
public function test_empty1() {
$dref = new DereferenceShortcodeVars;
$this->assertEquals('', $dref->extractParamName('_POST', '$_POST("")'));
}
public function test_empty2() {
$dref = new DereferenceShortcodeVars;
$this->assertEquals('', $dref->extractParamName('_POST', '$_POST(\'\')'));
}
public function test_getMatches_in_middle() {
$dref = new DereferenceShortcodeVars;
$matches = $dref->getMatches('_POST', 'blah blah $_POST(mike1)blah');
print_r($matches);
$this->assertEquals(1, count($matches));
$this->assertEquals('$_POST(mike1)', $matches[0]);
$this->assertEquals('mike1', $dref->extractParamName('_POST', $matches[0]));
}
public function test_getMatches_multi_in_middle_1_noquotes() {
$dref = new DereferenceShortcodeVars;
$matches = $dref->getMatches('_POST', 'blah blah $_POST(mike2)blah$_POST(oya)');
print_r($matches);
$this->assertEquals(2, count($matches));
$this->assertEquals('$_POST(mike2)', $matches[0]);
$this->assertEquals('$_POST(oya)', $matches[1]);
$this->assertEquals('mike2', $dref->extractParamName('_POST', $matches[0]));
$this->assertEquals('oya', $dref->extractParamName('_POST', $matches[1]));
}
public function test_getMatches_multi_in_middle_1_quotes() {
$dref = new DereferenceShortcodeVars;
$matches = $dref->getMatches('_POST', 'blah blah $_POST("mike2")blah$_POST("oya")');
print_r($matches);
$this->assertEquals(2, count($matches));
$this->assertEquals('$_POST("mike2")', $matches[0]);
$this->assertEquals('$_POST("oya")', $matches[1]);
$this->assertEquals('mike2', $dref->extractParamName('_POST', $matches[0]));
$this->assertEquals('oya', $dref->extractParamName('_POST', $matches[1]));
}
public function test_getMatches_multi_in_middle_2_quotes() {
$dref = new DereferenceShortcodeVars;
$matches = $dref->getMatches('_POST', 'blah blah $_POST(\'mike3\')blah$_POST(oya)');
print_r($matches);
$this->assertEquals(2, count($matches));
$this->assertEquals('$_POST(\'mike3\')', $matches[0]);
$this->assertEquals('$_POST(oya)', $matches[1]);
$this->assertEquals('mike3', $dref->extractParamName('_POST', $matches[0]));
$this->assertEquals('oya', $dref->extractParamName('_POST', $matches[1]));
}
public function test_getMatches_multi_in_middle_4_spaceBeforeOpenParen() {
$dref = new DereferenceShortcodeVars;
$matches = $dref->getMatches('_POST', 'blah blah $_POST (\'mike4\')blah$_POST (oya4)');
print_r($matches);
$this->assertEquals(2, count($matches));
$this->assertEquals('$_POST (\'mike4\')', $matches[0]);
$this->assertEquals('$_POST (oya4)', $matches[1]);
$this->assertEquals('mike4', $dref->extractParamName('_POST', $matches[0]));
$this->assertEquals('oya4', $dref->extractParamName('_POST', $matches[1]));
}
public function test_getMatches_multi_in_middle_5_spaceBeforeCloseParen() {
$dref = new DereferenceShortcodeVars;
$matches = $dref->getMatches('_POST', 'blah blah $_POST (\'mike5\' )blah$_POST (oya5 )');
print_r($matches);
$this->assertEquals(2, count($matches));
$this->assertEquals('$_POST (\'mike5\' )', $matches[0]);
$this->assertEquals('$_POST (oya5 )', $matches[1]);
$this->assertEquals('mike5', $dref->extractParamName('_POST', $matches[0]));
$this->assertEquals('oya5 ', $dref->extractParamName('_POST', $matches[1]));
}
public function test_getMatches_multi_in_middle_6_spacesAfterOpenParen() {
$dref = new DereferenceShortcodeVars;
$matches = $dref->getMatches('_POST', 'blah blah $_POST ( \'mike6\' )blah$_POST ( oya )');
print_r($matches);
$this->assertEquals(2, count($matches));
$this->assertEquals('$_POST ( \'mike6\' )', $matches[0]);
$this->assertEquals('$_POST ( oya )', $matches[1]);
$this->assertEquals('mike6', $dref->extractParamName('_POST', $matches[0]));
$this->assertEquals(' oya ', $dref->extractParamName('_POST', $matches[1]));
}
public function test_qname() {
$dref = new DereferenceShortcodeVars;
$this->assertEquals('qname', $dref->extractParamName('_POST', '$_POST(qname)'));
}
public function testConvert() {
$dref = new DereferenceShortcodeVars;
$string = $dref->convert('your-name=$_POST(aname)&&your-subject=$_POST(subject)');
$this->assertEquals('your-name=&&your-subject=', $string);
}
}