@@ -26,4 +26,47 @@ function test_mp_filter() {
2626 )
2727 );
2828 }
29+
30+ function test_micropub_get_mf2_skips_empty_string_properties () {
31+ $ post_id = $ this ->factory ->post ->create ();
32+
33+ // Add an empty string property (simulates unset property).
34+ update_post_meta ( $ post_id , 'mf2_location ' , '' );
35+ // Add a valid property.
36+ update_post_meta ( $ post_id , 'mf2_category ' , array ( 'test ' ) );
37+
38+ $ mf2 = micropub_get_mf2 ( $ post_id );
39+
40+ // Empty string property should be skipped.
41+ $ this ->assertArrayNotHasKey ( 'location ' , $ mf2 ['properties ' ] );
42+ // Valid property should exist.
43+ $ this ->assertArrayHasKey ( 'category ' , $ mf2 ['properties ' ] );
44+ }
45+
46+ function test_micropub_get_mf2_wraps_non_array_values () {
47+ $ post_id = $ this ->factory ->post ->create ();
48+
49+ // Add a non-array property value (string).
50+ update_post_meta ( $ post_id , 'mf2_syndication ' , 'https://twitter.com/example/123 ' );
51+
52+ $ mf2 = micropub_get_mf2 ( $ post_id );
53+
54+ // Property value should be wrapped in an array.
55+ $ this ->assertIsArray ( $ mf2 ['properties ' ]['syndication ' ] );
56+ $ this ->assertEquals ( array ( 'https://twitter.com/example/123 ' ), $ mf2 ['properties ' ]['syndication ' ] );
57+ }
58+
59+ function test_micropub_get_mf2_preserves_array_values () {
60+ $ post_id = $ this ->factory ->post ->create ();
61+
62+ // Add an array property value.
63+ $ categories = array ( 'tech ' , 'indieweb ' );
64+ update_post_meta ( $ post_id , 'mf2_category ' , $ categories );
65+
66+ $ mf2 = micropub_get_mf2 ( $ post_id );
67+
68+ // Property value should remain as array.
69+ $ this ->assertIsArray ( $ mf2 ['properties ' ]['category ' ] );
70+ $ this ->assertEquals ( $ categories , $ mf2 ['properties ' ]['category ' ] );
71+ }
2972}
0 commit comments