Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test if gzip extension is available #308

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions inc/class-cachify-hdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public static function is_available() {
* @since 2.4.0
*/
public static function is_gzip_enabled() {
if ( ! function_exists( 'gzencode' ) ) {
// GZip is not available on the system.
return false;
}

/**
* Filter that allows to enable/disable gzip file creation
*
Expand Down
11 changes: 10 additions & 1 deletion tests/test-cachify-hdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@ public function test_stringify_method() {
* Test GZip availability.
*/
public function test_is_gzip_enabled() {
self::assertTrue( Cachify_HDD::is_gzip_enabled(), 'GZip should be enabled by default' );
if ( ! function_exists( 'gzencode' ) ) {
self::assertFalse( Cachify_HDD::is_gzip_enabled(), 'GZip should be disabled, if not available' );

// Define gzencode function for testing the hook.
function gzencode( $data, $level = -1 ) {
return $data;
}
}

self::assertTrue( Cachify_HDD::is_gzip_enabled(), 'GZip should be enabled if available' );

$capture = null;
add_filter(
Expand Down