doupo5178 2015-10-26 19:19
浏览 15

模拟Wordpress单元测试

The function I'm testing requires another plugin, but I want to test it in isolation without having that plugin activated.

function functionName() {
   ...
   if (!is_plugin_active('path/to/plugin.php')) {
      return false;
   }
   return true;
}

How can I simulate that call returning true when I write a unit test?

  • 写回答

1条回答 默认 最新

  • du248227 2016-02-23 13:47
    关注

    You can modify the 'active_plugins' option during your tests to include that plugin.

    See https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-admin/includes/plugin.php#L434.

    评论

报告相同问题?