diff --git a/.warden/wordpress/wp-config.php b/.warden/wordpress/wp-config.php index 1393a82..bdafd04 100644 --- a/.warden/wordpress/wp-config.php +++ b/.warden/wordpress/wp-config.php @@ -1,4 +1,6 @@ inTest) return $this->inTestResult; + + // Early return if not enabled + if (!$this->is_enabled()) return true; + + $language = get_bloginfo('language'); + + // clean base domain + if (function_exists('rocket_clean_domain')) { + rocket_clean_domain($language); + } + + // clean minified CSS and JS + if (function_exists('rocket_clean_minify')) { + rocket_clean_minify($language); + } + + return true; + } + + /** + * Flush cache for a specific domain + * @param null $domain + * @return bool True on success + */ + public function flush_domain($domain = null) { + // early exit when in phpunittest + if ($this->inTest) return $this->inTestEnabled; + + // Early return if not enabled + if (!$this->is_enabled()) return true; + + // Early return if no domain specified + if (is_null($domain) || empty($domain)) { + return true; + } + + if (function_exists('rocket_clean_files')) { + $language = get_bloginfo('language'); + $paths = [ + 'https://' . $domain . '/', + 'http://' . $domain . '/' + ]; + rocket_clean_files($language); + } + + return true; + } + + /** + * Check if the WP Rocket plugin is enabled + * + * @return bool + */ + public function is_enabled() + { + // early exit when in phpunittest + if ($this->inTest) return $this->inTestEnabled; + + // See if the plugin exists / is activated by checking if its functions exists + return function_exists('get_rocket_cdn_url'); + } +} diff --git a/warpdrive-plugin/src/class-database-size-plugin.php b/warpdrive-plugin/src/class-database-size-plugin.php index a8dac67..fa8b0f1 100644 --- a/warpdrive-plugin/src/class-database-size-plugin.php +++ b/warpdrive-plugin/src/class-database-size-plugin.php @@ -129,6 +129,7 @@ function readableBytes($bytes) { $i = floor(log($bytes) / log(1024)); $sizes = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); - return sprintf('%.02F', $bytes / pow(1024, $i)) * 1 . ' ' . $sizes[$i]; + $pow = ($p = pow(1024, $i)) == 0 ? 1: $p; + return sprintf('%.02F', $bytes / $pow) * 1 . ' ' . $sizes[$i]; } } diff --git a/warpdrive-plugin/src/class-options.php b/warpdrive-plugin/src/class-options.php index 90e81d8..8eff667 100644 --- a/warpdrive-plugin/src/class-options.php +++ b/warpdrive-plugin/src/class-options.php @@ -17,7 +17,7 @@ class Options { const REPO_LOCATION = 'https://github.com/Savvii/warpdrive'; const REPO_RELEASES_LOCATION = 'https://api.github.com/repos/Savvii/warpdrive/releases/latest'; const REPO_RELEASES_LATEST_ZIPBALL = 'https://github.com/Savvii/warpdrive/releases/latest/download/package.zip'; - const AVAILABLE_CACHES = ['memcached', 'opcache', 'varnish', 'sucuri']; + const AVAILABLE_CACHES = ['memcached', 'opcache', 'varnish', 'sucuri', 'wprocket' ]; /************************************************** * Groups consts diff --git a/warpdrive-plugin/src/class-savvii-dashboard.php b/warpdrive-plugin/src/class-savvii-dashboard.php index f93ce13..3b2e594 100644 --- a/warpdrive-plugin/src/class-savvii-dashboard.php +++ b/warpdrive-plugin/src/class-savvii-dashboard.php @@ -164,7 +164,7 @@ function warpdrive_dashboard() { is_enabled()) : ?> -
  • +
  • diff --git a/warpdrive-plugin/tests/savvii/class-cache-flusher-wprocket-test.php b/warpdrive-plugin/tests/savvii/class-cache-flusher-wprocket-test.php new file mode 100644 index 0000000..d738639 --- /dev/null +++ b/warpdrive-plugin/tests/savvii/class-cache-flusher-wprocket-test.php @@ -0,0 +1,75 @@ +cache = new \Savvii\CacheFlusherWPRocket(); + $this->setProtectedProperty($this->cache, 'inTest', true); + } + + /** + * Should return true + */ + public function test_successfull_flush() + { + $this->assertTrue($this->cache->flush()); + } + + /** + * Should return true + */ + public function test_successfull_flush_domain() + { + $this->assertTrue($this->cache->flush_domain('example.com')); + } + + /** + * Flush should fail + */ + public function test_unsuccessfull_flush() + { + // let the flush fail + $this->setProtectedProperty($this->cache, 'inTestResult', false); + + $this->assertFalse($this->cache->flush()); + } + + /** + * Flush_domain() should always succeed + */ + public function test_unsuccessfull_but_successfull_flush_domain() + { + // let the 'normal' flush fail + $this->setProtectedProperty($this->cache, 'inTestResult', false); + + $this->assertTrue($this->cache->flush_domain('example.com')); + } + + /** + * Check successfull is_enabled() + */ + public function test_success_is_enabled() + { + $this->assertTrue($this->cache->is_enabled()); + } + + /** + * Check unsuccessfull is_enabled() + */ + public function test_unsuccessfull_is_enabled() + { + $this->setProtectedProperty($this->cache, 'inTestEnabled', false); + $this->assertFalse($this->cache->is_enabled()); + } +}