diff --git a/inc/class-cachify-hdd.php b/inc/class-cachify-hdd.php index 103234e..3fa167e 100644 --- a/inc/class-cachify-hdd.php +++ b/inc/class-cachify-hdd.php @@ -36,9 +36,12 @@ public static function is_gzip_enabled() { /** * Filter that allows to enable/disable gzip file creation * - * @param bool $create_gzip_files Whether to create gzip files. Default is `true` + * @param bool $create_gzip_files Whether to create gzip files. Default is `true`, if gzip is available. */ - return apply_filters( 'cachify_create_gzip_files', true ); + return apply_filters( + 'cachify_create_gzip_files', + function_exists( 'gzencode' ) + ); } /** diff --git a/tests/test-cachify-hdd.php b/tests/test-cachify-hdd.php index e5b7ab2..d220044 100644 --- a/tests/test-cachify-hdd.php +++ b/tests/test-cachify-hdd.php @@ -33,19 +33,24 @@ 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' ); + $gzip_available = function_exists( 'gzencode' ); + self::assertSame( + $gzip_available, + Cachify_HDD::is_gzip_enabled(), + 'GZip should be ' . ( $gzip_available ? 'enabled' : 'disabled' ) . ' by default' + ); $capture = null; add_filter( 'cachify_create_gzip_files', - function ( $original ) use ( &$capture ) { + function ( $original ) use ( &$capture, $gzip_available ) { $capture = $original; - return false; + return ! $gzip_available; } ); - self::assertFalse( Cachify_HDD::is_gzip_enabled(), 'GZip should be disabled by filter' ); - self::assertTrue( $capture, 'Filter was not applied' ); + self::assertSame( ! $gzip_available, Cachify_HDD::is_gzip_enabled(), 'GZip should be changed by filter' ); + self::assertSame( $gzip_available, $capture, 'Filter was not applied' ); } /**