Skip to content

Commit 3d06315

Browse files
authored
Test Fixes
1 parent 175cefc commit 3d06315

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

.github/workflows/wp-compatibility-test.yml

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ jobs:
216216
# Use WordPress-specific PHPMD configuration (WordPress snake_case compatible)
217217
echo "Using WordPress-specific PHPMD configuration (WordPress snake_case compatible)..."
218218
# Run PHPMD but don't fail the build on naming convention issues
219-
phpmd optimizations-ace-mc.php text phpmd.xml || echo "PHPMD completed with warnings (WordPress naming conventions may differ from PHPMD defaults)"
219+
phpmd free-gift-bulk-coupon-generator.php text phpmd.xml || echo "PHPMD completed with warnings (WordPress naming conventions may differ from PHPMD defaults)"
220220
221221
- name: Create issue on PHPMD failure
222222
if: ${{ failure() }}
@@ -608,7 +608,8 @@ jobs:
608608
609609
class Test_Free_Gift_Bulk_Coupon_Generator extends WP_UnitTestCase {
610610
public function test_plugin_loaded() {
611-
$this->assertTrue(function_exists('fgbcg_admin_menu'), 'Plugin was not loaded correctly');
611+
$this->assertTrue(function_exists('wc_free_gift_bulk_coupons_is_loaded'), 'Plugin helper function should exist');
612+
$this->assertTrue(wc_free_gift_bulk_coupons_is_loaded(), 'Plugin was not loaded correctly');
612613
}
613614
614615
public function test_wordpress_version_compatibility() {
@@ -628,9 +629,8 @@ jobs:
628629
629630
public function test_woocommerce_version_compatibility() {
630631
if (class_exists('WooCommerce')) {
631-
global $woocommerce;
632-
if ($woocommerce && isset($woocommerce->version)) {
633-
$wc_version = $woocommerce->version;
632+
$wc_version = WC()->version ?? null;
633+
if ($wc_version) {
634634
$min_wc_version = '5.0';
635635
$this->assertTrue(version_compare($wc_version, $min_wc_version, '>='),
636636
"WooCommerce version {$wc_version} should be >= {$min_wc_version}");
@@ -713,11 +713,34 @@ jobs:
713713
return;
714714
}, 0);
715715
716+
// Suppress database errors during testing
717+
add_filter('query', function($query) {
718+
// Skip WooCommerce webhook and taxonomy queries that may fail in test environment
719+
if (strpos($query, 'wptests_wc_webhooks') !== false ||
720+
strpos($query, 'wptests_woocommerce_attribute_taxonomies') !== false) {
721+
return "SELECT 1"; // Return harmless query
722+
}
723+
return $query;
724+
});
725+
716726
// Load WooCommerce first (dependency)
717727
$wc_plugin_file = '/tmp/wordpress/wp-content/plugins/woocommerce/woocommerce.php';
718728
if (file_exists($wc_plugin_file)) {
719729
require_once $wc_plugin_file;
720730
echo "WooCommerce loaded for testing\n";
731+
732+
// Initialize WooCommerce for testing without full activation
733+
add_action('init', function() {
734+
if (class_exists('WooCommerce')) {
735+
// Suppress WooCommerce database errors in test environment
736+
add_filter('woocommerce_load_webhooks', '__return_false');
737+
738+
// Initialize WC object
739+
if (function_exists('WC')) {
740+
WC();
741+
}
742+
}
743+
}, 0);
721744
} else {
722745
echo "Warning: WooCommerce not found at $wc_plugin_file\n";
723746
}

0 commit comments

Comments
 (0)