admin管理员组文章数量:1426855
This question is related to this SO post
I'm testing a plugin, and in it I have
public function enqueue_scripts() {
$main_style = 'public/scripts/application.js';
wp_register_script( 'plugin-scripts', plugin_dir_url( __DIR__ ) . $main_script, array() );
wp_enqueue_script( 'plugin-scripts' );
}
The plugin is using composer
and npm
, so it needs to be built to work.
And it is built (locally where I'm testing it, it works in a local instance I have on VVV). The test I wrote looks like this
public function test_enqueued_scripts() {
$this->admin->enqueue_scripts();
$this->assertTrue( wp_script_is( 'plugin-scripts' ) );
}
$this->admin
is just an instance of the class where my enqueue method is in the setUp()
method.
The test fails (Failed asserting that false is true
), and I wanted to see what's wrong so I added
public function enqueue_scripts() {
$main_style = 'public/scripts/application.js';
error_log( print_r( plugin_dir_url( __DIR__ ), true ) );
error_log( print_r( __DIR__, true ) );
wp_register_script( 'plugin-scripts', plugin_dir_url( __DIR__ ) . $main_script, array() );
wp_enqueue_script( 'plugin-scripts' );
}
And ran the unit test, I saw
/
For the plugin_dir_url( __DIR__ )
, and for the __DIR__
I have
/vagrant-local/www/projects/project/public_html/wp-content/plugins/my-plugin/
The test WordPress instance is located in a temporary folder that looks something like
/var/folders/xj/14b3w8w51ll6rw09q72p45cr0000gn/T/wordpress/
But my plugins are not installed there. I'm guessing the tests are only using that as a source for the core functionality. Also the bootstrap.php
file is referencing the wordpress-develop
that is located in my VVV folder.
What I don't understand is why do I get that example
url? And how can I successfully test the enqueueing/registering of the script?
This question is related to this SO post
I'm testing a plugin, and in it I have
public function enqueue_scripts() {
$main_style = 'public/scripts/application.js';
wp_register_script( 'plugin-scripts', plugin_dir_url( __DIR__ ) . $main_script, array() );
wp_enqueue_script( 'plugin-scripts' );
}
The plugin is using composer
and npm
, so it needs to be built to work.
And it is built (locally where I'm testing it, it works in a local instance I have on VVV). The test I wrote looks like this
public function test_enqueued_scripts() {
$this->admin->enqueue_scripts();
$this->assertTrue( wp_script_is( 'plugin-scripts' ) );
}
$this->admin
is just an instance of the class where my enqueue method is in the setUp()
method.
The test fails (Failed asserting that false is true
), and I wanted to see what's wrong so I added
public function enqueue_scripts() {
$main_style = 'public/scripts/application.js';
error_log( print_r( plugin_dir_url( __DIR__ ), true ) );
error_log( print_r( __DIR__, true ) );
wp_register_script( 'plugin-scripts', plugin_dir_url( __DIR__ ) . $main_script, array() );
wp_enqueue_script( 'plugin-scripts' );
}
And ran the unit test, I saw
http://example/wp-content/plugins/Users/dingo_d/vagrant-local/www/projects/project/public_html/wp-content/plugins/my-plugin/
For the plugin_dir_url( __DIR__ )
, and for the __DIR__
I have
/vagrant-local/www/projects/project/public_html/wp-content/plugins/my-plugin/
The test WordPress instance is located in a temporary folder that looks something like
/var/folders/xj/14b3w8w51ll6rw09q72p45cr0000gn/T/wordpress/
But my plugins are not installed there. I'm guessing the tests are only using that as a source for the core functionality. Also the bootstrap.php
file is referencing the wordpress-develop
that is located in my VVV folder.
What I don't understand is why do I get that example
url? And how can I successfully test the enqueueing/registering of the script?
1 Answer
Reset to default 1You need to run do_action('wp_enqueue_scripts')
prior to executing your assertions. This article has more details and an example.
本文标签: oopIntegration tests test script enqueueregister fails
版权声明:本文标题:oop - Integration tests test script enqueueregister fails 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745483584a2660283.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论