Newer
Older
<?php
/**
* Test UI methods.
*
* @package WP_Revisions_Control
*/
/**
* Class TestUI.
*/
class TestUI extends WP_UnitTestCase {
/**
* Plugin slug used in many settings etc.
*
* @var string
*/
protected static $settings_section = 'wp_revisions_control';
/**
* Plugin's limit meta key.
*
* @var string
*/
protected static $meta_key = '_wp_rev_ctl_limit';
/**
* Test meta box with no meta set.
*/
public function test_no_meta() {
ob_start();
WP_Revisions_Control::get_instance()->revisions_meta_box( get_post( $post_id ) );
$meta_box = ob_get_clean();
$this->assertContains(
'value=""',
$meta_box,
'Failed to assert that meta box has no value when no setting exists.'
);
}
/**
* Test meta box with no limit set.
*/
public function test_no_limit() {
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
update_post_meta( $post_id, static::$meta_key, -1 );
ob_start();
WP_Revisions_Control::get_instance()->revisions_meta_box( get_post( $post_id ) );
$meta_box = ob_get_clean();
$this->assertContains(
'value=""',
$meta_box,
'Failed to assert that meta box has no value when no limit exists.'
);
}
/**
* Test settings-field output when no options are set.
*/
public function test_settings_fields_no_options() {
ob_start();
WP_Revisions_Control::get_instance()->field_post_type( array( 'post_type' => 'post' ) );
$post_field = ob_get_clean();
ob_start();
WP_Revisions_Control::get_instance()->field_post_type( array( 'post_type' => 'page' ) );
$page_field = ob_get_clean();
$name_format = 'name="%1$s[%2$s]"';
$value_format = 'value=""';
$this->assertContains(
sprintf(
$name_format,
static::$settings_section,
'post'
),
$post_field,
'Failed to assert that post field had correct name for post type.'
);
$this->assertContains(
sprintf(
$name_format,
static::$settings_section,
'page'
),
$page_field,
'Failed to assert that page field had correct name for post type.'
);
$this->assertContains(
$value_format,
$post_field,
'Failed to assert that post field had correct value.'
);
$this->assertContains(
$value_format,
$page_field,
'Failed to assert that page field had correct value.'
);
}
/**
* Test settings-field output when options are set.
*/
public function test_settings_fields_with_options() {
$value = 12;
update_option(
static::$settings_section,
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
149
150
151
152
153
154
155
156
);
ob_start();
WP_Revisions_Control::get_instance()->field_post_type( array( 'post_type' => 'post' ) );
$post_field = ob_get_clean();
$name_format = 'name="%1$s[%2$s]"';
$value_format = 'value="%1$s"';
$this->assertContains(
sprintf(
$name_format,
static::$settings_section,
'post'
),
$post_field,
'Failed to assert that post field had correct name for post type.'
);
$this->assertContains(
sprintf(
$value_format,
$value
),
$post_field,
'Failed to assert that post field had correct value.'
);
}
/**
* Test settings-field output when options are set.
*/
public function test_settings_fields_with_options_keep_all() {
$value = -1;
update_option(
static::$settings_section,
);
ob_start();
WP_Revisions_Control::get_instance()->field_post_type( array( 'post_type' => 'post' ) );
$post_field = ob_get_clean();
$name_format = 'name="%1$s[%2$s]"';
$value_format = 'value=""';
$this->assertContains(
sprintf(
$name_format,
static::$settings_section,
'post'
),
$post_field,
'Failed to assert that post field had correct name for post type.'
);
$this->assertContains(
$post_field,
'Failed to assert that post field had correct value.'
);
}
}