Skip to content

Commit 03db5af

Browse files
add test for form tags
1 parent c609c37 commit 03db5af

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

tests/MC4WP_Form_Tags_Test.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
5+
/**
6+
* Class FormTest
7+
* @ignore
8+
*/
9+
class MC4WP_Form_Tags_Test extends TestCase
10+
{
11+
public function test_replace_in_html(): void
12+
{
13+
$t = new MC4WP_Form_Tags();
14+
$t->register();
15+
16+
$p = new WP_Post;
17+
$p->ID = 1;
18+
global $post;
19+
$post = $p;
20+
$f = new MC4WP_Form(1, $p, []);
21+
$e = new MC4WP_Form_Element($f, 1, []);
22+
23+
self::assertEquals('<script>alert(1);</script>', $t->replace_in_form_content('<script>alert(1);</script>', $f, $e));
24+
self::assertEquals('Post ID: 1', $t->replace_in_form_content('Post ID: {post property=\'ID\'}', $f, $e));
25+
26+
$_GET['foo'] = 'bar';
27+
self::assertEquals('URL Parameter: bar', $t->replace_in_form_content('URL Parameter: {data key="foo"}', $f, $e));
28+
29+
$_GET['foo'] = '<script>alert(1);</script>';
30+
self::assertEquals('URL Parameter: &lt;script&gt;alert(1);&lt;/script&gt;', $t->replace_in_form_content('URL Parameter: {data key="foo"}', $f, $e));
31+
}
32+
}

tests/mock.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function sanitize_text_field($value)
7474
/** @ignore */
7575
function esc_html($value)
7676
{
77-
return $value;
77+
return htmlspecialchars($value);
7878
}
7979

8080

@@ -161,6 +161,11 @@ function is_email($email)
161161
return filter_var($email, FILTER_VALIDATE_EMAIL);
162162
}
163163

164+
function get_locale(): string
165+
{
166+
return 'en_US';
167+
}
168+
164169
/**
165170
* Straight copy from WP source
166171
*

0 commit comments

Comments
 (0)