Update Consent API test to use closures

This commit is contained in:
Jeremy Pry 2023-09-07 16:44:02 -04:00 committed by Justin Palmer
parent f8a24b6819
commit df0f6a6fd3
No known key found for this signature in database
GPG Key ID: ACAB7C35AA2577AF
1 changed files with 21 additions and 9 deletions

View File

@ -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}" ) );
}
}