Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
200 views
in Technique[技术] by (71.8m points)

WordPress Testing: Check if plugin activation has successfully created custom tables

first of all, my plugin works on wordpress (it's currently running on production) and creates the DB tables as expected. I recently just started implementing tests and I have the following problem now:

I have set up the testing environment according to the official wordpress documentation. I can execute phpunit and run the example test provided by wordpress without any errors.

I would now like to test the activation of my plugin and also whether the tables that are normally created during activation are available. (I have a connection the testing db.)

public function testPluginActivation(): void
{
    do_action('activate_' . static::PLUGIN_BASENAME);
}

My problems:

  • I am not sure if the code above actually simulates a correct activation.
  • I don't know how to prove if the tables are being created. (If I take a look at the testing db after running the tests, the tables are not there, only the default ones created by WP at the beginning, but I am not sure if WP kinda does a rollback after all tests.)
question from:https://stackoverflow.com/questions/65842294/wordpress-testing-check-if-plugin-activation-has-successfully-created-custom-ta

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...