-
Notifications
You must be signed in to change notification settings - Fork 794
/
test_class.publicize.php
93 lines (66 loc) · 2.6 KB
/
test_class.publicize.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
<?php
require dirname( __FILE__ ) . '/../../../../modules/publicize.php';
class WP_Test_Publicize extends WP_UnitTestCase {
private $fired_publicized_post = false;
private $publicized_post_id = null;
private $post;
public function setUp() {
parent::setUp();
$this->publicize = publicize_init();
$this->fired_publicized_post = false;
$this->publicized_post_id = null;
$post_id = $this->factory->post->create( array( 'post_status' => 'draft' ) );
$this->post = get_post( $post_id );
Jetpack_Options::update_options( array( 'publicize_connections' => array( 'not_empty' ) ) );
add_action( 'jetpack_publicize_post', array( $this, 'publicized_post' ), 10, 1 );
}
public function test_fires_jetpack_publicize_post_on_save_as_published() {
$this->post->post_status = 'publish';
wp_insert_post( $this->post->to_array() );
$this->assertPublicized( true, $this->post );
}
public function test_does_not_fire_jetpack_publicize_post_on_save_as_published() {
$this->post->post_status = 'publish';
Jetpack_Options::delete_option( array( 'publicize_connections' ) );
wp_insert_post( $this->post->to_array() );
$this->assertPublicized( false, $this->post );
}
public function test_does_not_fire_jetpack_publicize_post_on_other_status_transitions() {
$this->post->post_status = 'pending';
wp_insert_post( $this->post->to_array() );
$this->assertPublicized( false, $this->post );
}
public function test_filter_can_prevent_publicize() {
add_filter( 'publicize_should_publicize_published_post', array( $this, 'prevent_publicize_post' ), 10, 2 );
$this->post->post_status = 'publish';
wp_insert_post( $this->post->to_array() );
$this->assertPublicized( false, $this->post );
}
public function test_publicize_does_not_fire_on_post_types_that_do_not_support_it() {
$args = array(
'public' => true,
'label' => 'unregister post type'
);
register_post_type( 'foo', $args );
$this->post->post_type = 'foo';
$this->post->post_status = 'publish';
wp_insert_post( $this->post->to_array() );
$this->assertPublicized( false, $this->post );
}
function assertPublicized( $should_have_publicized, $post ) {
if ( $should_have_publicized ) {
$this->assertTrue( $this->fired_publicized_post );
$this->assertEquals( $post->ID, $this->publicized_post_id );
} else {
$this->assertFalse( $this->fired_publicized_post );
$this->assertNull( $this->publicized_post_id );
}
}
function publicized_post( $post_id ) {
$this->fired_publicized_post = true;
$this->publicized_post_id = $post_id;
}
function prevent_publicize_post( $should_publicize, $post ) {
return false;
}
}