forked from WordPress/wordpress-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-plugin.spec.ts
57 lines (47 loc) · 1.28 KB
/
install-plugin.spec.ts
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
import { NodePHP } from '@php-wasm/node';
import { compileBlueprint, runBlueprintSteps } from '../compile';
const phpVersion = '8.0';
describe('Blueprint step installPlugin', () => {
let php: NodePHP;
beforeEach(async () => {
php = await NodePHP.load(phpVersion, {
requestHandler: {
documentRoot: '/',
isStaticFilePath: (path) => !path.endsWith('.php'),
},
});
});
it('should install a plugin', async () => {
// Create test plugin
php.mkdir('/tmp/test-plugin');
php.writeFile(
'/tmp/test-plugin/index.php',
`/**\n * Plugin Name: Test Plugin`
);
const zipFileName = 'test-plugin-0.0.1.zip';
await php.run({
code: `<?php $zip = new ZipArchive(); $zip->open("${zipFileName}", ZIPARCHIVE::CREATE); $zip->addFile("/tmp/test-plugin/index.php"); $zip->close();`,
});
php.rmdir('/tmp/test-plugin');
// Note the package name is different from plugin folder name
expect(php.fileExists(zipFileName)).toBe(true);
await runBlueprintSteps(
compileBlueprint({
steps: [
{
step: 'installPlugin',
pluginZipFile: {
resource: 'vfs',
path: zipFileName,
},
},
],
}),
php
);
php.unlink(zipFileName);
expect(
php.fileExists(`${php.documentRoot}/wp-content/test-plugin`)
).toBe(true);
}, 30000);
});