wordpress - 在functions.php中错误WordPress测试Phpunit调用函数
问题描述
我正在使用 PhpUnit 进行测试,调用 functions.php 的函数
我有一个函数可以验证它是否是一个页面并且 SLUG 模板等于一个页面
function my_scripts() {
var_dump (get_page_template_slug());
if (is_page() && get_page_template_slug() == 'page-script.php') {
........
}
}
在我的测试中,我有这个代码
public function test_my_scripts(){
$page_id = $this->factory->post->create(
array(
'post_type' => 'page',
)
);
add_post_meta( $page_id , '_wp_page_template', 'page-script.php' );
add_filter( 'page_template', 'custom_page_template' );
var_dump(get_page_template_slug($page_id));
my_scripts();
}
我测试的 var_dump 的结果是
字符串(15)“页面脚本.php”
以及functions.php的功能
布尔(假)
并且不要输入条件 IF。
如何确定从页面调用函数和 slug 是否指示进入条件?
谢谢
解决方案
我找到了解决方案,将它放在调用函数 my_scripts(); 之前。
$this->go_to(get_permalink($page_id));
推荐阅读
- javascript - 有没有比 crypto.randomBytes 更好的方法来生成性能方面的唯一 ID?
- batch-file - 您可以将条目从批处理文件添加到命令行历史记录吗?
- python - 从 Python 中的现有序列生成扩展的时间序列数据
- cmis - 用于 FileNet SOAP 服务的 CMIS
- python - 使用 Kivy buildozer 将 python 文件转换为 android 文件
- javascript - 在firebase上上传文件夹 - javascript
- android - 如何在多个活动中传递一个计算变量
- node.js - Mocha、Chai、TypeError 无法读取未定义的属性“集合”
- php - Laravel 中“资源”路由的不同策略
- machine-learning - 使用先前预测的支持向量机