Test content'; $result = $cache->cache_output($output); $this->assertEquals($output, $result); $this->assertFileExists($path); $this->assertEquals($output, file_get_contents($path)); } public function test_purge_post_cache_removes_file() { $cache = new WP_Recache_WPCache(); $post_id = $this->factory()->post->create(); $url = get_permalink($post_id); $path = wp_recache_get_cache_path($url); wp_mkdir_p(dirname($path)); file_put_contents($path, 'cached content'); $this->assertFileExists($path); $cache->purge_post_cache($post_id); $this->assertFileDoesNotExist($path); } public function test_get_current_url_returns_correct_url() { $cache = new WP_Recache_WPCache(); $_SERVER['HTTP_HOST'] = 'example.com'; $_SERVER['REQUEST_URI'] = '/test-page/'; $_SERVER['HTTPS'] = 'off'; $reflection = new ReflectionClass($cache); $method = $reflection->getMethod('get_current_url'); $method->setAccessible(true); $url = $method->invoke($cache); $this->assertEquals('http://example.com/test-page/', $url); } public function test_cache_file_is_created_with_correct_permissions() { $cache = new WP_Recache_WPCache(); $_SERVER['HTTP_HOST'] = 'example.com'; $_SERVER['REQUEST_URI'] = '/test-page/'; $_SERVER['HTTPS'] = 'off'; unset($_SERVER['HTTP_USER_AGENT']); $url = 'https://example.com/test-page/'; $path = wp_recache_get_cache_path($url); wp_mkdir_p(dirname($path)); $output = 'Test content'; $cache->cache_output($output); $this->assertFileExists($path); $this->assertTrue(is_readable($path)); } }