-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_nav_menu_item_autosave_fields.sh
More file actions
executable file
·137 lines (108 loc) · 3.87 KB
/
test_nav_menu_item_autosave_fields.sh
File metadata and controls
executable file
·137 lines (108 loc) · 3.87 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
# Script to test all nav menu item autosave fields
# This script tests each field individually to see if it gets saved in the autosave
# Don't exit on errors - we want to test all fields even if some fail
set +e
CREDS_FILE="test_credentials.json"
ADMIN_USER=$(jq -r '.admin_username' "$CREDS_FILE")
ADMIN_PASS=$(jq -r '.admin_password' "$CREDS_FILE")
MENU_ITEM_ID=$(jq -r '.nav_menu_item_id' "$CREDS_FILE")
BASE_URL="http://localhost/wp-json/wp/v2"
echo "========================================="
echo "Testing Nav Menu Item Autosave Fields"
echo "========================================="
echo "Menu Item ID: $MENU_ITEM_ID"
echo ""
# Function to restore server
restore_server() {
echo "Restoring server..."
make -C .. restore-server > /dev/null 2>&1
sleep 2
echo "Server restored"
echo ""
}
# Function to test a field
test_field() {
local field_name=$1
local field_value=$2
local jq_path=$3
local expected_value=$4
echo "========================================="
echo "Testing field: $field_name"
echo "========================================="
# Create autosave with the field
echo "Creating autosave with $field_name..."
RESPONSE=$(curl --silent --user "$ADMIN_USER:$ADMIN_PASS" \
-H "Content-Type: application/json" \
-d "$field_value" \
"$BASE_URL/menu-items/$MENU_ITEM_ID/autosaves")
AUTOSAVE_ID=$(echo "$RESPONSE" | jq -r '.id')
echo "Autosave created with ID: $AUTOSAVE_ID"
# Check if autosave creation failed
if [ "$AUTOSAVE_ID" = "null" ] || [ -z "$AUTOSAVE_ID" ]; then
ERROR=$(echo "$RESPONSE" | jq -r '.message // .code')
echo "❌ ERROR: Failed to create autosave - $ERROR"
echo ""
return
fi
# Retrieve the autosave
echo "Retrieving autosave..."
AUTOSAVE=$(curl --silent --user "$ADMIN_USER:$ADMIN_PASS" \
"$BASE_URL/menu-items/$MENU_ITEM_ID/autosaves/$AUTOSAVE_ID")
# Check if field was saved
FIELD_VALUE=$(echo "$AUTOSAVE" | jq "$jq_path")
echo "Expected: $expected_value"
echo "Actual: $FIELD_VALUE"
# Compare with expected value
if echo "$FIELD_VALUE" | grep -q "$expected_value"; then
echo "✅ SUCCESS: Field was saved correctly"
else
echo "❌ FAILED: Field was NOT saved or value is incorrect"
fi
echo ""
}
# Test 1: title
test_field "title" '{"title":"TEST AUTOSAVE TITLE"}' '.title.rendered' "TEST AUTOSAVE TITLE"
restore_server
# Test 2: type
test_field "type" '{"type":"post_type"}' '.type' "post_type"
restore_server
# Test 3: status
test_field "status" '{"status":"draft"}' '.status' "draft"
restore_server
# Test 4: attr_title
test_field "attr_title" '{"attr_title":"Test Attribute Title"}' '.attr_title' "Test Attribute Title"
restore_server
# Test 5: classes
test_field "classes" '{"classes":["test-class-1","test-class-2"]}' '.classes' "test-class-1"
restore_server
# Test 6: description
test_field "description" '{"description":"Test Description"}' '.description' "Test Description"
restore_server
# Test 7: menu_order
test_field "menu_order" '{"menu_order":5}' '.menu_order' "5"
restore_server
# Test 8: object
test_field "object" '{"object":"page"}' '.object' "page"
restore_server
# Test 9: object_id
test_field "object_id" '{"object_id":999}' '.object_id' "999"
restore_server
# Test 10: target
test_field "target" '{"target":"_blank"}' '.target' "_blank"
restore_server
# Test 11: url
test_field "url" '{"url":"https://test-autosave.example.com"}' '.url' "test-autosave.example.com"
restore_server
# Test 12: xfn
test_field "xfn" '{"xfn":["friend","colleague"]}' '.xfn' "friend"
restore_server
# Test 13: menus
test_field "menus" '{"menus":[1]}' '.menus' "1"
restore_server
# Test 14: meta
test_field "meta" '{"meta":{}}' '.meta' "{}"
restore_server
echo "========================================="
echo "All tests completed!"
echo "========================================="