If you have phpUnit configured for testing a WP plugin, you can use a test case like this:
In your plugin-directory/tests/Some_Test_Case.php
:
class Plugin_Test extends WP_UnitTestCase {
/**
* @dataProvider post_IDs_and_expected_results
*/
public function test_something( $post_id, $expected_result ) {
global $post;
$post = get_post( $post_id );
$plugin_content = call_plugin_function(); // Your function name here
$this->assertEquals( $expected_result, $plugin_content, "Content OK for post $post_id" );
}
public function post_IDs_and_expected_results() {
return array(
array( 1, 'expected result for post_id = 1' ),
array( 2, 'expected result for post_id = 2' )
);
}
}
Command line in your plugin’s directory: phpunit ./tests/Some_Test_Case.php
Related Posts:
- Unit tests – Dealing with dependencies
- How to write testable classes in WordPress
- PHPUnit testing WordPress Plugin
- Implement phpunit testing on a plugin
- Unit testing to simulate the loop
- What is the best way to do unit tests for your plugin in 2018 [closed]
- Plugin development with unit tests
- Unit testing wordpress plugins with plugin options
- Install and load additional plugins when running unit tests
- Unit Testing a Plugin functionality with cron
- PHPUnit test plugin activation
- Why is WP_Mock not used instead of WP_UnitTestCase for writing unit tests by most plugins?
- DataBase connection problem with PHPUnit and WordPress
- Unit testing a plugin with a theme dependency
- PHPUnit Testing and woocommerce Constant
- Unit Testing action hook
- PHPUnit Ajax Serialization of ‘Closure’ is not allowed
- PHPUnit Testing Installation Issue
- What’s the difference between term_id and term_taxonomy_id
- How are bulk actions handled in custom list table classes?
- How do I programatically insert a new menu item?
- Creating Settings Page with dropdowns for Plugin
- Custom Nav Menu items default to ‘menu-item-type’ => ‘custom’. How to make a “page” menu item?
- How to tell if an option has been created vs an empty option?
- jQuery in header or footer
- Notice: _usort_terms_by_ID is deprecated since version 4.7.0! Use wp_list_sort instead
- How to add a new plugin page under desired Options page?
- How to make WordPress use non-greedy shortcode parsing?
- How to get current page name in my wordpress plugin
- WP Cron doesn’t save or in post body
- Use register_taxonomy() in register_activation_hook()
- Pages 404 in wordpress
- Calling apply_filters on non-documented hooks
- Multiple entries in get_option results? or why is _multiwidget set to 1?
- Check if I am in the Admin Panel (wp-admin)?
- Commit changes to WordPress Plugin SVN with TortoiseSVN
- WordPress Admin Post Type Table Class Filter Hook
- Order of Operation for these three hooks
- save_post hook not triggered in WP v3.6.1
- How to get the ID of the currently logged in user?
- Using a Shortcode to Replace Themes Stylesheet?
- Where should I put “run once” plugin pages?
- Initial help with official “create a block” tutorial
- Slow WP_query due to nested wp_query. Need Suggestions
- Plugin Development Output
- How to modify product page for Jigoshop
- Adding Second Plugin Author
- Is @wordpress/env locked to node v14 or can I also use node v16?
- Securing/Escaping Output of file content – reading via fread() in PHP
- Run code once when block is created
- Intermittent database errors when accessing WordPress database
- How to create a “View” page for entry in add_menu_page wordpress admin area (CRUD operation)
- what is the standard ulr for wordpress plugin development?
- Customize WooCommerce my account dashboard through plugin
- Precaching WordPress posts with a ServiceWorker
- Shortcode returning localized HTML part
- Create a custom capability to allow an ‘Editor’ to edit only ‘Subscriber’ users
- global $current_user not current user
- What is the proper way to get logged in user id in a plugin?
- Custom WordPress Plugin will install new and not update
- get_option() will not work without access to wp-config.php
- register_activation_hook on multisite
- Use ‘get’ form action within a WordPress plugin admin page
- Template directory in plugin
- WordPress Admin Login Custom Logo
- How can I add a simple custom field to my plugin?
- Ajax is not working in a loop
- Woocommerce order empty items array
- Bind a function with its own argument to show something dynamically after every content
- Plugin development – loading Javascript and Flash
- Drawing the line between theme & plugin on large scale bespoke projects
- Update variable value via add_filter
- Do I need to create an endpoint?
- Run uninstall.php if a checkbox is checked from settings page
- How to check whether checkbox is checked in WordPress customizer
- How to find list of all functions bind to a particular hook from my plugin?
- Multiple page plugin settings
- how to get the top 10 popular blogs
- How to output CSS to the beginning of the stylesheet in a WordPress Plugin
- Set page to draft on plugin deactivation
- Can one plugin activate another plugin via script?
- Insert and read media from the WordPress library and call in the plugin
- Get value of custom checkbox from Gutenberg sidebar in plugin
- Enable a role named ‘backend_user’ to access my plugin pages
- Hiding class namespace from plugin’s extensions
- How to trigger WooCommerce user profile edit change?
- Relational / Associate tables using native WordPress functionality
- Stop unauthorised file access
- Changed media upload path for plugin, but generates error & shows wrong url
- How to pass a more variable with page/subpage in Wordprees URL?
- Dynamic sidebar areas not working on the Theme Customizer
- Woo-commerce: Adding additional page sections using a child theme
- Plugin dev: How to multiply instances of a plugin in the same metabox?
- How to get html tag ids from template?
- Getting Plugin to read all script files
- How to Prove Ownership of plugin [closed]
- WordPress, GIT, Renamed Plugin Dir + files – Working Code now Broken [closed]
- get_term_by() returning null on plugin
- Advanced Custom Fields conflicting with custom plugin when saving custom field
- WordPress plugin boilerplate AJAX functionality