forked from timber/timber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-timber-post-password.php
56 lines (53 loc) · 1.98 KB
/
test-timber-post-password.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
<?php
/**
* @group called-post-constructor
*/
class TestTimberPostPassword extends Timber_UnitTestCase
{
public function testPasswordedContentDefault()
{
$quote = 'The way to do well is to do well.';
$post_id = $this->factory->post->create();
$post = Timber::get_post($post_id);
$post->post_content = $quote;
$post->post_password = 'burrito';
wp_update_post($post);
$password_form = get_the_password_form($post->ID);
$this->assertEquals(wpautop($quote), $post->content());
}
public function testPasswordedContentWhenEnabled()
{
add_filter('timber/post/content/show_password_form_for_protected', function ($maybe_show) {
return true;
});
$quote = 'The way to do well is to do well.';
$post_id = $this->factory->post->create();
$post = Timber::get_post($post_id);
$post->post_content = $quote;
$post->post_password = 'burrito';
wp_update_post($post);
$password_form = get_the_password_form($post->ID);
$this->assertEquals($password_form, $post->content());
}
public function testPasswordedContentWhenEnabledWithCustomForm()
{
add_filter('timber/post/content/show_password_form_for_protected', function ($maybe_show) {
return true;
});
add_filter('timber/post/content/password_form', function ($form, $post) {
return Timber::compile('assets/password-form.twig', [
'post' => $post,
]);
}, 10, 2);
$quote = 'The way to do well is to do well.';
$post_id = $this->factory->post->create([
'post_title' => 'Secrets!',
]);
$post = Timber::get_post($post_id);
$post->post_content = $quote;
$post->post_password = 'burrito';
wp_update_post($post);
$password_form = '<form>Enter password to see Secrets!</form>';
$this->assertEquals($password_form, $post->content());
}
}