Skip to content

Commit 7d60642

Browse files
committed
Refactor tests to use matrix-based approach for all WordPress hook functions
1 parent 8b3bf6a commit 7d60642

File tree

4 files changed

+206
-417
lines changed

4 files changed

+206
-417
lines changed

src/test/suite/callbackCompletion.test.ts

Lines changed: 58 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -2,99 +2,64 @@ import * as assert from 'assert';
22
import * as vscode from 'vscode';
33

44
suite('Callback Completion Test Suite', () => {
5-
test('Should provide callback completions for add_action', async () => {
6-
const doc = await vscode.workspace.openTextDocument({
7-
language: 'php',
8-
content: "<?php\nadd_action('init', ",
5+
// Only add_action and add_filter support callbacks
6+
const callbackFunctions = [
7+
{ fn: 'add_action', hook: 'init' },
8+
{ fn: 'add_filter', hook: 'the_content' },
9+
];
10+
11+
const commonCallbackTypes = [
12+
{ label: 'Closure' },
13+
{ label: 'Function' },
14+
];
15+
16+
const filterSpecificTypes = [
17+
{ label: 'Arrow' },
18+
];
19+
20+
callbackFunctions.forEach(({ fn, hook }) => {
21+
const isFilter = fn.includes('filter');
22+
23+
test(`Should provide callback completions for ${fn}`, async () => {
24+
const doc = await vscode.workspace.openTextDocument({
25+
language: 'php',
26+
content: `<?php\n${fn}('${hook}', `,
27+
});
28+
29+
await vscode.window.showTextDocument(doc);
30+
await new Promise((resolve) => setTimeout(resolve, 100));
31+
32+
const pos = fn.length + hook.length + 7;
33+
const position = new vscode.Position(1, pos);
34+
35+
const completions = await vscode.commands.executeCommand<vscode.CompletionList>(
36+
'vscode.executeCompletionItemProvider',
37+
doc.uri,
38+
position,
39+
);
40+
41+
assert.ok(completions, 'Completions should be returned');
42+
assert.ok(completions.items.length > 0, 'Should have completion items');
43+
44+
const labels = completions.items.map((item) => (typeof item.label === 'string' ? item.label : item.label.label));
45+
46+
// Test common callback types
47+
commonCallbackTypes.forEach(({ label }) => {
48+
assert.ok(
49+
labels.some((l) => l === label || l.includes(label)),
50+
`Should include ${label} option for ${fn}`,
51+
);
52+
});
53+
54+
// Test filter-specific types
55+
if (isFilter) {
56+
filterSpecificTypes.forEach(({ label }) => {
57+
assert.ok(
58+
labels.some((l) => l === label || l.includes(label)),
59+
`Should include ${label} option for ${fn}`,
60+
);
61+
});
62+
}
963
});
10-
11-
await vscode.window.showTextDocument(doc);
12-
await new Promise((resolve) => setTimeout(resolve, 100));
13-
14-
const position = new vscode.Position(1, 20);
15-
16-
const completions = await vscode.commands.executeCommand<vscode.CompletionList>(
17-
'vscode.executeCompletionItemProvider',
18-
doc.uri,
19-
position,
20-
);
21-
22-
assert.ok(completions, 'Completions should be returned');
23-
assert.ok(completions.items.length > 0, 'Should have completion items');
24-
25-
const labels = completions.items.map((item) => (typeof item.label === 'string' ? item.label : item.label.label));
26-
27-
// Should have standard callback types
28-
assert.ok(
29-
labels.some((label) => label === 'Closure' || label.includes('Closure')),
30-
'Should include Closure option',
31-
);
32-
assert.ok(
33-
labels.some((label) => label === 'Function' || label.includes('Function')),
34-
'Should include Function option',
35-
);
36-
});
37-
38-
test('Should provide callback completions for add_filter', async () => {
39-
const doc = await vscode.workspace.openTextDocument({
40-
language: 'php',
41-
content: "<?php\nadd_filter('the_content', ",
42-
});
43-
44-
await vscode.window.showTextDocument(doc);
45-
await new Promise((resolve) => setTimeout(resolve, 100));
46-
47-
const position = new vscode.Position(1, 32);
48-
49-
const completions = await vscode.commands.executeCommand<vscode.CompletionList>(
50-
'vscode.executeCompletionItemProvider',
51-
doc.uri,
52-
position,
53-
);
54-
55-
assert.ok(completions, 'Completions should be returned');
56-
assert.ok(completions.items.length > 0, 'Should have completion items');
57-
58-
const labels = completions.items.map((item) => (typeof item.label === 'string' ? item.label : item.label.label));
59-
60-
// Should have callback types including arrow function for filters
61-
assert.ok(
62-
labels.some((label) => label === 'Arrow function' || label.includes('Arrow')),
63-
'Should include Arrow function option for filters',
64-
);
65-
});
66-
67-
test('Should include WordPress utility functions for filters', async () => {
68-
const doc = await vscode.workspace.openTextDocument({
69-
language: 'php',
70-
content: "<?php\nadd_filter('the_content', ",
71-
});
72-
73-
await vscode.window.showTextDocument(doc);
74-
await new Promise((resolve) => setTimeout(resolve, 100));
75-
76-
const position = new vscode.Position(1, 32);
77-
78-
const completions = await vscode.commands.executeCommand<vscode.CompletionList>(
79-
'vscode.executeCompletionItemProvider',
80-
doc.uri,
81-
position,
82-
);
83-
84-
assert.ok(completions, 'Completions should be returned');
85-
const labels = completions.items.map((item) => (typeof item.label === 'string' ? item.label : item.label.label));
86-
87-
// Check for WordPress utility functions
88-
const hasUtilityFunctions = labels.some((label) => label && (
89-
label.includes('Return true')
90-
|| label.includes('Return false')
91-
|| label.includes('Return null')
92-
|| label.includes('return')
93-
));
94-
95-
assert.ok(
96-
hasUtilityFunctions,
97-
`Should include WordPress utility function options. Got: ${labels.slice(0, 15).join(', ')}`,
98-
);
9964
});
10065
});

src/test/suite/edgeCases.test.ts

Lines changed: 0 additions & 184 deletions
This file was deleted.

0 commit comments

Comments
 (0)