10quality / wpmvc-addon-testsuite
Test suite for WordPress MVC (WPMVC) framework add-ons.
Installs: 40
Dependents: 4
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/10quality/wpmvc-addon-testsuite
Requires
- php: >=5.4.0
- 10quality/wpmvc-addon: 1.0.*
- 10quality/wpmvc-core: >=3.1.0
Requires (Dev)
- phpunit/phpunit: 9.*
This package is auto-updated.
Last update: 2025-10-11 04:27:47 UTC
README
Install
Composer command to install as required-dev:
composer install 10quality/wpmvc-addon-testsuite --dev
Test Case Class
Instead of the default PHPUnit test case use the following:
use WPMVC\Addons\PHPUnit\TestCase; class MyTest extends TestCase { // Your test methods }
This classs will allow you to use the following assertiong methods:
| Method | Parameters | Description |
|---|---|---|
$this->assertDidAction |
$handle the action hook name handle. |
Asserts if an action ran. |
$this->assertDidNotAction |
$handle the action hook name handle. |
Asserts if an action not ran. |
$this->assertAppliedFilters |
$handle the filter hook name handle. |
Asserts if filters have been applied to a hook. |
$this->assertNotAppliedFilters |
$handle the filter hook name handle. |
Asserts if filters have been not applied to a hook. |
$this->assertAddedAction |
$handle the action hook name handle. |
Asserts if an action handler has been added for a hook. |
$this->assertNotAddedAction |
$handle the action hook name handle. |
Asserts if no action handlers has been added for a hook. |
$this->assertAddedFilter |
$handle the filter hook name handle. |
Asserts if a filter handler has been added for a hook. |
$this->assertNotAddedFilter |
$handle the filter hook name handle. |
Asserts if no filter handlers has been added for a hook. |
$this->assertHasRegisterStyle |
$handle the style name handle. |
Asserts if a style asset has been registered. |
$this->assertNotHasRegisterStyle |
$handle the style hook name handle. |
Asserts if a style asset has not been registered. |
$this->assertHasRegisterScript |
$handle the script name handle. |
Asserts if a script asset has been registered. |
$this->assertNotHasRegisterScript |
$handle the script hook name handle. |
Asserts if a script asset has not been registered. |
$this->assertHasEnqueueStyle |
$handle the style name handle. |
Asserts if a style asset has been registered. |
$this->assertNotHasEnqueueStyle |
$handle the style hook name handle. |
Asserts if a style asset has not been registered. |
$this->assertHasEnqueueScript |
$handle the script name handle. |
Asserts if a script asset has been enqueued. |
$this->assertNotHasEnqueueScript |
$handle the script hook name handle. |
Asserts if a script asset has not been enqueued. |
$this->assertHasCalledWP |
$function the name of a WordPress core function. |
Asserts if a core WordPress function has been called. |
$this->assertNotHasCalledWP |
$function the name of a WordPress core function. |
Asserts if a core WordPress function has not been called. |
Example:
use WPMVC\Addons\PHPUnit\TestCase; class MyTest extends TestCase { public function testAction() { // Run do_action( 'init' ); // Assert $this->assertDidAction( 'init' ); } }
Test your addon
You addon main class needs a WordPress MVC main class (bridge) instance to work correctly. The TestCase class include the method getBridgeMock() that allows you to test your addon mocking the Bridge class.
Example:
use WPMVC\Addons\PHPUnit\TestCase; use MyAddon; class MyAddonTest extends TestCase { public function testInit() { // Prepare $bridge = $this->getBridgeMock(); $addon = new MyAddon( $bridge ); // Run $addon->init(); // Assert $this->assertAddedAction( 'init' ); $this->assertHasRegisterScript( 'my-js' ); } }
The example above tests the method init() of the addon class MyAddon, which receives the $bridge initialized as a mock. The example asserts that an action hook has been added and a script has been registered during the method call.
You can mock the Bridge for your own benefit:
use WPMVC\Addons\PHPUnit\TestCase; use WPMVC\Addons\PHPUnit\Mocks\Brige; use MyAddon; class MyAddonTest extends TestCase { public function testInit() { // Prepare $bridge = $this->getMockBuilder( Brige::class ) ->disableOriginalConstructor() ->getMock(); $addon = new MyAddon( $bridge ); // Run $addon->init(); // Assert $this->assertAddedAction( 'init' ); $this->assertHasRegisterScript( 'my-js' ); } }
Reset test suite data
You can reset test suite data by calling the function wpmvc_addon_phpunit_reset() inside the setUp or tearDown methods.
WordPress core functions mocked
The following WordPress core functions are mocked and included through composer:
___eadd_actionadd_filteradd_query_argadd_submenu_pageadmin_urlapply_filtersdo_actionesc_attresc_htmlesc_html_eesc_urlget_filesystem_methodget_localeget_stylesheet_directoryhome_urlrequest_filesystem_credentialssanitize_text_fieldsite_urlsubmit_buttonwp_enqueue_scriptwp_enqueue_stylewp_register_scriptwp_register_styleWP_Filesystem
WordPress core constants mocked
The following constants are mocked through composer if they are not defined:
ABSPATH
WordPress core classes mocked
The following WordPress classes are mocked and included through composer:
WP_Filesystem