Update Consent API test to use closures
This commit is contained in:
parent
f8a24b6819
commit
df0f6a6fd3
|
@ -3,6 +3,7 @@
|
|||
namespace Automattic\WooCommerce\Tests\Internal\Integration;
|
||||
|
||||
use Automattic\WooCommerce\Internal\Integrations\WPConsentAPI;
|
||||
use Closure;
|
||||
use WP_UnitTestCase;
|
||||
|
||||
class WPConsentAPITest extends WP_UnitTestCase {
|
||||
|
@ -37,19 +38,30 @@ class WPConsentAPITest extends WP_UnitTestCase {
|
|||
unset( $this->plugin );
|
||||
}
|
||||
|
||||
public function test_wp_consent_api_not_available(): void {
|
||||
$this->WPConsentAPIIntegration->method( 'is_wp_consent_api_active' )
|
||||
->willReturn( false );
|
||||
$this->WPConsentAPIIntegration->register();
|
||||
$this->assertFalse( has_filter( "wp_consent_api_registered_{$this->plugin}" ) );
|
||||
/**
|
||||
* Get a closure for the on_plugins_loaded method of the WPConsentAPI class.
|
||||
*
|
||||
* @return Closure
|
||||
*/
|
||||
private function get_closure_for_on_plugins_loaded_method() {
|
||||
return Closure::bind(
|
||||
function() {
|
||||
$this->on_plugins_loaded();
|
||||
},
|
||||
$this->WPConsentAPIIntegration,
|
||||
$this->WPConsentAPIIntegration
|
||||
);
|
||||
}
|
||||
|
||||
public function test_wp_consent_api_not_available(): void {
|
||||
$this->WPConsentAPIIntegration->method( 'is_wp_consent_api_active' )->willReturn( false );
|
||||
$this->get_closure_for_on_plugins_loaded_method()();
|
||||
$this->assertFalse( has_filter( "wp_consent_api_registered_{$this->plugin}" ) );
|
||||
}
|
||||
|
||||
public function test_wp_consent_api_available(): void {
|
||||
$this->WPConsentAPIIntegration->method( 'is_wp_consent_api_active' )
|
||||
->willReturn( true );
|
||||
$this->WPConsentAPIIntegration->register();
|
||||
$this->WPConsentAPIIntegration->method( 'is_wp_consent_api_active' )->willReturn( true );
|
||||
$this->get_closure_for_on_plugins_loaded_method()();
|
||||
$this->assertTrue( has_filter( "wp_consent_api_registered_{$this->plugin}" ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue