-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathtest-metadata-compatibility.php
More file actions
184 lines (157 loc) · 5.57 KB
/
test-metadata-compatibility.php
File metadata and controls
184 lines (157 loc) · 5.57 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
/**
* Test metadata compatibility with other plugins.
*
* @package Feedzy
* @subpackage Tests
* @copyright Copyright (c) 2026, Marius Cristea
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*/
/**
* Class Test_Feedzy_Metadata_Compatibility
*
* Tests that Feedzy's metadata filters don't interfere with other plugins.
* Specifically tests the issue where Slider Hero button text changes don't save
* when Feedzy is active.
*/
class Test_Feedzy_Metadata_Compatibility extends WP_UnitTestCase {
/**
* Test that metadata updates on non-feedzy post types work correctly.
*
* This simulates the Slider Hero plugin saving button text metadata.
*
* @access public
*/
public function test_non_feedzy_post_meta_updates() {
// Create a regular post (simulating Slider Hero's post type).
$user_id = $this->factory->user->create(
array(
'role' => 'administrator',
)
);
wp_set_current_user( $user_id );
$post_id = $this->factory->post->create(
array(
'post_title' => 'Test Slider',
'post_type' => 'post', // Not a feedzy post type
'post_author' => $user_id,
)
);
// Ensure the post was created.
$this->assertGreaterThan( 0, $post_id );
// Simulate Slider Hero saving button text metadata.
$button_text = 'Click Me Now';
$result = update_post_meta( $post_id, 'slider_button_text', $button_text );
// Verify the metadata was saved successfully.
$this->assertNotFalse( $result, 'Metadata update should succeed' );
// Retrieve the metadata and verify it matches.
$saved_value = get_post_meta( $post_id, 'slider_button_text', true );
$this->assertEquals( $button_text, $saved_value, 'Button text should be saved correctly' );
// Update it again with different text.
$new_button_text = 'Updated Button Text';
$result = update_post_meta( $post_id, 'slider_button_text', $new_button_text );
$this->assertNotFalse( $result, 'Second metadata update should succeed' );
// Verify the new value.
$saved_value = get_post_meta( $post_id, 'slider_button_text', true );
$this->assertEquals( $new_button_text, $saved_value, 'Updated button text should be saved correctly' );
}
/**
* Test that multiple metadata updates on non-feedzy posts work.
*
* @access public
*/
public function test_multiple_non_feedzy_meta_updates() {
$user_id = $this->factory->user->create(
array(
'role' => 'administrator',
)
);
wp_set_current_user( $user_id );
$post_id = $this->factory->post->create(
array(
'post_title' => 'Test Multiple Meta',
'post_type' => 'page', // Different post type
'post_author' => $user_id,
)
);
// Save multiple pieces of metadata.
$meta_data = array(
'button_text' => 'Click Here',
'button_url' => 'https://example.com',
'button_style' => 'primary',
);
foreach ( $meta_data as $key => $value ) {
$result = update_post_meta( $post_id, $key, $value );
$this->assertNotFalse( $result, "Metadata update for {$key} should succeed" );
}
// Verify all metadata was saved.
foreach ( $meta_data as $key => $value ) {
$saved_value = get_post_meta( $post_id, $key, true );
$this->assertEquals( $value, $saved_value, "Metadata {$key} should match saved value" );
}
}
/**
* Test that feedzy_categories metadata still works correctly.
*
* This ensures our fix doesn't break existing functionality.
*
* @access public
*/
public function test_feedzy_category_meta_still_works() {
$user_id = $this->factory->user->create(
array(
'role' => 'administrator',
)
);
wp_set_current_user( $user_id );
$post_id = $this->factory->post->create(
array(
'post_title' => 'Test Feedzy Category',
'post_type' => 'feedzy_categories',
'post_author' => $user_id,
)
);
$feed_url = 'https://example.com/feed';
// Set up the POST data as Feedzy expects.
$_POST['id'] = $post_id;
$_POST['feedzy_category_meta_noncename'] = wp_create_nonce( FEEDZY_BASEFILE );
$_POST['post_type'] = 'feedzy_categories';
$_POST['feedzy_category_feed'] = $feed_url;
// Trigger the save_post action.
$post = get_post( $post_id );
do_action( 'save_post', $post_id, $post );
// Verify the feed URL was validated and saved.
$saved_feed = get_post_meta( $post_id, 'feedzy_category_feed', true );
// Note: The validate_category_feeds filter may modify the URL or return empty if invalid.
// For this test, we just need to verify that the meta operation completed without errors.
$this->assertNotNull( $saved_feed, 'Feedzy category feed metadata should be processed' );
}
/**
* Test add_post_meta for non-feedzy post types.
*
* @access public
*/
public function test_add_meta_for_non_feedzy_posts() {
$user_id = $this->factory->user->create(
array(
'role' => 'administrator',
)
);
wp_set_current_user( $user_id );
$post_id = $this->factory->post->create(
array(
'post_title' => 'Test Add Meta',
'post_type' => 'post',
'post_author' => $user_id,
)
);
// Use add_post_meta instead of update_post_meta.
$result = add_post_meta( $post_id, 'new_slider_field', 'New Value', true );
// add_post_meta returns meta_id on success, false on failure.
$this->assertNotFalse( $result, 'add_post_meta should succeed for non-feedzy posts' );
$this->assertIsNumeric( $result, 'add_post_meta should return meta_id' );
// Verify the metadata.
$saved_value = get_post_meta( $post_id, 'new_slider_field', true );
$this->assertEquals( 'New Value', $saved_value, 'Metadata should be saved correctly via add_post_meta' );
}
}