admin管理员组文章数量:1392110
I am currently doing TDD with WordPress, in the PHPUnit I need to test if the meta box is actually registered on a method call, I could not find any function in WordPress to do that, so I was trying to verify it by calling global $wp_meta_boxes
, but it returns null
when invoked inside a PHPUnit test.
Is this variable is assigned on a hook?
Could any one provide the action/filter name?
I am currently doing TDD with WordPress, in the PHPUnit I need to test if the meta box is actually registered on a method call, I could not find any function in WordPress to do that, so I was trying to verify it by calling global $wp_meta_boxes
, but it returns null
when invoked inside a PHPUnit test.
Is this variable is assigned on a hook?
Could any one provide the action/filter name?
Share Improve this question edited Feb 5, 2020 at 9:52 Mayeenul Islam 12.9k21 gold badges85 silver badges169 bronze badges asked Feb 5, 2020 at 9:35 NaveenNaveen 1273 bronze badges1 Answer
Reset to default -1Here is what i have did as a workaround, i realized we cant do that in TDD way.so its better to write the code first instead of writing the test when you face this problem.
So in my code i have added this
add_meta_box( 'meta-box-id', __( 'My Meta Box', 'textdomain' ), 'wpdocs_my_display_callback', 'post' );
and in test the $wp_meta_boxes
is now displaying the array of registered meta boxes.
array(1) {
["post"]=>
array(1) {
["advanced"]=>
array(1) {
["default"]=>
array(1) {
["meta-box-id"]=>
array(4) {
["id"]=>
string(11) "meta-box-id"
["title"]=>
string(11) "My Meta Box"
["callback"]=>
string(26) "wpdocs_my_display_callback"
["args"]=>
NULL
}
}
}
}
}
This changes nothing, the code still remains the same, but the way of writing differs now due to this issue.
本文标签: metaboxHow to verify meta box is registered in Unit Testing
版权声明:本文标题:metabox - How to verify meta box is registered in Unit Testing? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744775965a2624624.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论