forked from timber/timber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-timber-wp-functions.php
147 lines (134 loc) · 4.71 KB
/
test-timber-wp-functions.php
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
<?php
use Timber\FunctionWrapper;
use Timber\Helper;
class TestTimberWPFunctions extends Timber_UnitTestCase
{
public function testFunctionFire()
{
$str = '{{function("my_test_function")}}';
$output = Timber::compile_string($str);
$this->assertEquals('jared sez hi', $output);
}
/**
* @expectedDeprecated the_block_template_skip_link
*/
public function testFooterOnFooterFW()
{
global $wp_scripts;
$wp_scripts = null;
wp_enqueue_script('jquery', false, [], false, true);
$fw1 = new FunctionWrapper('wp_footer', [], true);
$fw2 = new FunctionWrapper('wp_footer', [], true);
$this->assertGreaterThan(50, strlen($fw1->call()));
//this is bunk because footer scripts will only print once
$this->assertSame(0, strlen($fw2->call()));
wp_dequeue_script('jquery');
$wp_footer_output1 = new FunctionWrapper('wp_footer', [], true);
$this->assertSame(0, strlen($wp_footer_output1));
}
/**
* @expectedDeprecated the_block_template_skip_link
*/
public function testFooterAlone()
{
global $wp_scripts;
$wp_scripts = null;
wp_enqueue_script('jquery', false, [], false, true);
$fw1 = new FunctionWrapper('wp_footer', [], true);
$this->assertGreaterThan(50, strlen($fw1->call()));
}
public function testDoubleAction()
{
add_action('jared_action', function () {
echo 'bar';
});
$fw1 = new FunctionWrapper('do_jared_action', [], true);
$fw2 = new FunctionWrapper('do_jared_action', [], true);
$this->assertEquals($fw1->call(), $fw2->call());
$this->assertEquals('bar', $fw1->call());
}
/**
* @expectedDeprecated the_block_template_skip_link
*/
public function testDoubleActionWPFooter()
{
global $wp_scripts;
$wp_scripts = null;
add_action('wp_footer', 'echo_junk');
$fw1 = new FunctionWrapper('wp_footer', [], true);
$fw2 = new FunctionWrapper('wp_footer', [], true);
$this->assertEquals($fw1->call(), $fw2->call());
$pos = strpos($fw2->call(), 'foo');
$this->assertGreaterThan(-1, $pos);
remove_action('wp_footer', 'echo_junk');
}
/**
* @expectedDeprecated the_block_template_skip_link
*/
public function testInTwig()
{
global $wp_scripts;
$wp_scripts = null;
wp_enqueue_script('jquery', false, [], false, true);
$str = Timber::compile('assets/wp-footer.twig', []);
$pos = strpos($str, 'wp-includes/js/jquery/jquery');
$this->assertGreaterThan(-1, $pos);
}
/**
* @expectedDeprecated the_block_template_skip_link
*/
public function testInTwigString()
{
global $wp_scripts;
$wp_scripts = null;
wp_enqueue_script('jquery', false, [], false, true);
$str = Timber::compile_string('{{function("wp_footer")}}', []);
$pos = strpos($str, 'wp-includes/js/jquery/jquery');
$this->assertGreaterThan(-1, $pos);
}
/**
* @expectedDeprecated the_block_template_skip_link
*/
public function testAgainstFooterFunctionOutput()
{
global $wp_scripts;
$wp_scripts = null;
wp_enqueue_script('colorpicker', false, [], false, true);
wp_enqueue_script('fake-js', 'http://example.org/fake-js.js', [], false, true);
$wp_footer = Helper::ob_function('wp_footer');
global $wp_scripts;
$wp_scripts = null;
wp_enqueue_script('colorpicker', false, [], false, true);
wp_enqueue_script('fake-js', 'http://example.org/fake-js.js', [], false, true);
$str = Timber::compile_string('{{function("wp_footer")}}');
$this->assertEquals($wp_footer, $str);
$this->assertGreaterThan(50, strlen($str));
}
public function testInTwigStringHeadAndFooter()
{
global $wp_scripts;
$wp_scripts = null;
//send colorpicker to the header
wp_enqueue_script('colorpicker', false, [], false, false);
//send fake-js to the footer
wp_enqueue_script('fake-js', 'http://example.org/fake-js.js', [], false, true);
$str = Timber::compile_string('<head>{{function("wp_head")}}</head><footer>{{function("wp_footer")}}</footer>');
$footer_tag = strpos($str, '<footer>');
$colorpicker = strpos($str, 'colorpicker');
$this->assertGreaterThan(1, $colorpicker);
//make sure that footer appears after colorpicker
$this->assertGreaterThan($colorpicker, $footer_tag);
}
}
function do_jared_action()
{
do_action('jared_action');
}
function echo_junk()
{
echo 'foo';
}
function my_test_function()
{
return 'jared sez hi';
}