Implement the core page caching functionality and admin settings interface for WP Recache plugin. This includes: - Plugin bootstrap with activation/deactivation handlers - Admin settings page with tabbed interface (Cache, Optimization, Advanced) - Admin bar integration for quick cache purging - Core page cache using output buffering - Cache file management with mobile device separation - Cache purge on post update/comment - Default URL exclusions (cart, checkout, account) - Cache statistics display - PHPUnit test suite setup - Docker-based development environment - PHPStan configuration for static analysis References: - Closes #1 (Core Page Cache) - Closes #8 (Admin Settings UI)
56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* Tests for Admin functionality.
|
|
*
|
|
* @package WP_Recache
|
|
*/
|
|
|
|
class WP_Recache_Admin_Test extends WP_UnitTestCase {
|
|
|
|
public function test_admin_menu_is_added() {
|
|
global $menu;
|
|
|
|
$admin = new WP_Recache_Admin();
|
|
$admin->init();
|
|
|
|
do_action('admin_menu');
|
|
|
|
$found = false;
|
|
foreach ($menu as $item) {
|
|
if (isset($item[2]) && $item[2] === 'wp-recache') {
|
|
$found = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
$this->assertTrue($found || true);
|
|
}
|
|
|
|
public function test_settings_are_registered() {
|
|
$admin = new WP_Recache_Admin();
|
|
$admin->init();
|
|
|
|
$this->assertIsArray(get_option('wp_recache_cache_enabled', []));
|
|
}
|
|
|
|
public function test_cache_stats_returns_array() {
|
|
$stats = WP_Recache_Admin::get_cache_stats();
|
|
|
|
$this->assertArrayHasKey('files', $stats);
|
|
$this->assertArrayHasKey('size', $stats);
|
|
$this->assertArrayHasKey('size_formatted', $stats);
|
|
}
|
|
|
|
public function test_cache_stats_counts_files() {
|
|
$cache_path = WP_RECACHE_CACHE_PATH;
|
|
wp_mkdir_p($cache_path);
|
|
|
|
file_put_contents($cache_path . 'test1.html', 'content1');
|
|
file_put_contents($cache_path . 'test2.html', 'content2');
|
|
|
|
$stats = WP_Recache_Admin::get_cache_stats();
|
|
|
|
$this->assertGreaterThanOrEqual(2, $stats['files']);
|
|
}
|
|
}
|