82 lines
2.5 KiB
PHP
82 lines
2.5 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']);
|
|
}
|
|
|
|
public function test_sanitize_rejected_cookies_trims_whitespace() {
|
|
$admin = new WP_Recache_Admin();
|
|
$result = $admin->sanitize_rejected_cookies(" wp-postpass \n comment_author_* ");
|
|
$this->assertEquals(['wp-postpass', 'comment_author_*'], $result);
|
|
}
|
|
|
|
public function test_sanitize_rejected_cookies_filters_empty_lines() {
|
|
$admin = new WP_Recache_Admin();
|
|
$result = $admin->sanitize_rejected_cookies("wp-postpass\n\n\ncomment_author_*\n");
|
|
$this->assertEquals(['wp-postpass', 'comment_author_*'], $result);
|
|
}
|
|
|
|
public function test_sanitize_rejected_cookies_handles_array_input() {
|
|
$admin = new WP_Recache_Admin();
|
|
$result = $admin->sanitize_rejected_cookies(['wp-postpass', 'comment_author_*']);
|
|
$this->assertEquals(['wp-postpass', 'comment_author_*'], $result);
|
|
}
|
|
|
|
public function test_rejected_cookies_option_is_registered() {
|
|
$admin = new WP_Recache_Admin();
|
|
$admin->init();
|
|
do_action('admin_init');
|
|
|
|
$this->assertEquals(WP_RECACHE_DEFAULT_REJECTED_COOKIES, get_option('wp_recache_rejected_cookies', WP_RECACHE_DEFAULT_REJECTED_COOKIES));
|
|
}
|
|
}
|