-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-settings.php
More file actions
88 lines (73 loc) · 2.64 KB
/
Copy pathtest-settings.php
File metadata and controls
88 lines (73 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* Test settings save/load functionality
* Run this from command line: php test-settings.php
*/
// Simulate WordPress environment minimally
define('ABSPATH', true);
// Mock WordPress functions
function update_option($name, $value) {
static $options = [];
$old_value = $options[$name] ?? null;
$options[$name] = $value;
// WordPress returns false if value didn't change
if ($old_value === $value) {
return false;
}
return true;
}
function get_option($name, $default = false) {
static $options = [];
return $options[$name] ?? $default;
}
function wp_parse_args($args, $defaults) {
return is_array($args) ? array_merge($defaults, $args) : $defaults;
}
// Load the settings class
require_once __DIR__ . '/includes/class-domscribe-wp-settings.php';
echo "Testing Domscribe WordPress Settings...\n\n";
// Test 1: Create settings
echo "Test 1: Create new settings instance\n";
$settings = new Domscribe_WP_Settings();
echo "✓ Settings created\n\n";
// Test 2: Get default values
echo "Test 2: Check default values\n";
$all = $settings->get_all();
echo " - Enabled: " . ($all['enabled'] ? 'Yes' : 'No') . "\n";
echo " - Extract main: " . ($all['extract_main_content'] ? 'Yes' : 'No') . "\n";
echo " - Cache: " . ($all['enable_cache'] ? 'Yes' : 'No') . "\n";
echo "✓ Defaults OK\n\n";
// Test 3: Modify settings
echo "Test 3: Modify settings\n";
$settings->set('enabled', false);
$settings->set('cache_duration', 7200);
echo " - Set enabled to false\n";
echo " - Set cache_duration to 7200\n";
echo "✓ Values modified\n\n";
// Test 4: Save settings (first time)
echo "Test 4: Save settings (first time)\n";
$result = $settings->save();
echo " - Save result: " . ($result ? 'Success' : 'Failed') . "\n";
if ($result) {
echo "✓ First save successful\n\n";
} else {
echo "✗ First save failed\n\n";
}
// Test 5: Save settings again (without changes)
echo "Test 5: Save settings again (unchanged)\n";
$result = $settings->save();
echo " - Save result: " . ($result ? 'Success' : 'Failed') . "\n";
if ($result) {
echo "✓ Unchanged save handled correctly\n\n";
} else {
echo "✗ Unchanged save failed (this was the bug!)\n\n";
}
// Test 6: Load and verify
echo "Test 6: Load fresh instance and verify\n";
$settings2 = new Domscribe_WP_Settings();
echo " - Enabled: " . ($settings2->get('enabled') ? 'Yes' : 'No') . "\n";
echo " - Cache duration: " . $settings2->get('cache_duration') . "\n";
echo "✓ Settings persisted correctly\n\n";
echo "✅ All tests passed!\n";
echo "\nThe bug was that update_option() returns false when the value hasn't changed.\n";
echo "This has been fixed in the save() method.\n";