-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing test case and @cover annotations for improved code covera…
…ge in web-worker-offloading plugin
- Loading branch information
Sarthak Jaiswal
authored and
Sarthak Jaiswal
committed
Feb 14, 2025
1 parent
d94977f
commit 1c60b11
Showing
10 changed files
with
181 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
plugins/web-worker-offloading/tests/third-party/test-google-site-kit.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* Test cases for google-site-kit.php in Web Worker Offloading. | ||
* | ||
* @package web-worker-offloading | ||
*/ | ||
class Test_Google_Site_Kit extends WP_UnitTestCase { | ||
|
||
/** | ||
* Test the function that configures WWO for Google Site Kit. | ||
* | ||
* @covers ::plwwo_google_site_kit_configure | ||
*/ | ||
public function test_plwwo_google_site_kit_configure(): void { | ||
$configuration = array(); | ||
$expected_configuration = array( | ||
'globalFns' => array( 'gtag', 'wp_has_consent' ), | ||
'forward' => array( 'dataLayer.push', 'gtag' ), | ||
'mainWindowAccessors' => array( | ||
'_googlesitekitConsentCategoryMap', | ||
'_googlesitekitConsents', | ||
'wp_consent_type', | ||
'wp_fallback_consent_type', | ||
'wp_has_consent', | ||
'waitfor_consent_hook', | ||
), | ||
); | ||
|
||
$result = plwwo_google_site_kit_configure( $configuration ); | ||
|
||
$this->assertEquals( $expected_configuration, $result ); | ||
} | ||
|
||
/** | ||
* Test the function that filters inline script attributes. | ||
* | ||
* @covers ::plwwo_google_site_kit_filter_inline_script_attributes | ||
*/ | ||
public function test_plwwo_google_site_kit_filter_inline_script_attributes(): void { | ||
$attributes = array( 'id' => 'google_gtagjs-js-consent-mode-data-layer' ); | ||
$expected_attributes = array( | ||
'id' => 'google_gtagjs-js-consent-mode-data-layer', | ||
'type' => 'text/partytown', | ||
); | ||
|
||
$result = plwwo_google_site_kit_filter_inline_script_attributes( $attributes ); | ||
|
||
$this->assertEquals( $expected_attributes, $result ); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
plugins/web-worker-offloading/tests/third-party/test-seo-by-rank-math.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* Test cases for seo-by-rank-math.php in Web Worker Offloading. | ||
* | ||
* @package web-worker-offloading | ||
*/ | ||
|
||
class Test_Seo_By_Rank_Math extends WP_UnitTestCase { | ||
|
||
/** | ||
* Test the function that configures WWO for Rank Math SEO. | ||
*/ | ||
public function test_plwwo_rank_math_configure(): void { | ||
$configuration = array(); | ||
$expected_configuration = array( | ||
'globalFns' => array( 'gtag' ), | ||
'forward' => array( 'dataLayer.push', 'gtag' ), | ||
); | ||
|
||
$result = plwwo_rank_math_configure( $configuration ); | ||
|
||
$this->assertEquals( $expected_configuration, $result ); | ||
} | ||
|
||
/** | ||
* Test the function that filters script attributes. | ||
* | ||
* @covers ::plwwo_rank_math_filter_script_attributes | ||
*/ | ||
public function test_plwwo_rank_math_filter_script_attributes(): void { | ||
$attributes = array( 'id' => 'google_gtagjs' ); | ||
$expected_attributes = array( | ||
'id' => 'google_gtagjs', | ||
'type' => 'text/partytown', | ||
); | ||
|
||
$result = plwwo_rank_math_filter_script_attributes( $attributes ); | ||
|
||
$this->assertEquals( $expected_attributes, $result ); | ||
} | ||
|
||
/** | ||
* Test the function that filters inline script attributes. | ||
* | ||
* @covers ::plwwo_rank_math_filter_inline_script_attributes | ||
*/ | ||
public function test_plwwo_rank_math_filter_inline_script_attributes(): void { | ||
$attributes = array( 'id' => 'google_gtagjs-inline' ); | ||
$expected_attributes = array( | ||
'id' => 'google_gtagjs-inline', | ||
'type' => 'text/partytown', | ||
); | ||
|
||
$result = plwwo_rank_math_filter_inline_script_attributes( $attributes ); | ||
|
||
$this->assertEquals( $expected_attributes, $result ); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
plugins/web-worker-offloading/tests/third-party/test-woocommerce.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
/** | ||
* Test cases for woocommerce.php in Web Worker Offloading. | ||
* | ||
* @package web-worker-offloading | ||
*/ | ||
|
||
class Test_WooCommerce extends WP_UnitTestCase { | ||
|
||
/** | ||
* Test the function that configures WWO for WooCommerce. | ||
*/ | ||
public function test_plwwo_woocommerce_configure(): void { | ||
$configuration = array(); | ||
$expected_configuration = array( | ||
'globalFns' => array( 'gtag' ), | ||
'forward' => array( 'dataLayer.push', 'gtag' ), | ||
); | ||
|
||
$result = plwwo_woocommerce_configure( $configuration ); | ||
|
||
$this->assertEquals( $expected_configuration, $result ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters