diff --git a/packages/playground/blueprints/src/lib/steps/activate-plugin.spec.ts b/packages/playground/blueprints/src/lib/steps/activate-plugin.spec.ts index 7fbf2ff4cc..44540f01f0 100644 --- a/packages/playground/blueprints/src/lib/steps/activate-plugin.spec.ts +++ b/packages/playground/blueprints/src/lib/steps/activate-plugin.spec.ts @@ -28,7 +28,7 @@ describe('Blueprint step activatePlugin()', () => { ` { expect(response.text).toBe('true'); }); + it('should detect a silent failure in activating the plugin', async () => { + const docroot = php.documentRoot; + php.writeFile( + `/${docroot}/wp-content/plugins/test-plugin.php`, + ` + await activatePlugin(php, { + pluginPath: 'test-plugin.php', + }) + ).rejects.toThrow(/Plugin test-plugin.php could not be activated/); + }); + it('should run the activation hooks as a priviliged user', async () => { const docroot = php.documentRoot; const createdFilePath = @@ -56,7 +74,7 @@ describe('Blueprint step activatePlugin()', () => { ` ); await activatePlugin(php, { - pluginPath: docroot + '/wp-content/plugins/test-plugin.php', + pluginPath: 'test-plugin.php', }); expect(php.fileExists(createdFilePath)).toBe(true); diff --git a/packages/playground/blueprints/src/lib/steps/activate-plugin.ts b/packages/playground/blueprints/src/lib/steps/activate-plugin.ts index 37a56755cb..a14b34664f 100644 --- a/packages/playground/blueprints/src/lib/steps/activate-plugin.ts +++ b/packages/playground/blueprints/src/lib/steps/activate-plugin.ts @@ -1,5 +1,6 @@ import { phpVar } from '@php-wasm/util'; import { StepHandler } from '.'; +import { logger } from '@php-wasm/logger'; /** * @inheritDoc activatePlugin @@ -34,7 +35,7 @@ export const activatePlugin: StepHandler = async ( progress?.tracker.setCaption(`Activating ${pluginName || pluginPath}`); const docroot = await playground.documentRoot; - await playground.run({ + const result = await playground.run({ code: ` = async ( throw new Exception( 'Unable to activate plugin' ); `, }); + if (result.text !== 'Plugin activated successfully') { + logger.debug(result); + throw new Error( + `Plugin ${pluginPath} could not be activated – WordPress exited with no error. ` + + `Sometimes, when $_SERVER or site options are not configured correctly, ` + + `WordPress exits early with a 301 redirect. ` + + `Inspect the "debug" logs in the console for more details` + ); + } }; diff --git a/packages/playground/blueprints/src/lib/steps/activate-theme.spec.ts b/packages/playground/blueprints/src/lib/steps/activate-theme.spec.ts index 5ce4f05110..a5d99baf62 100644 --- a/packages/playground/blueprints/src/lib/steps/activate-theme.spec.ts +++ b/packages/playground/blueprints/src/lib/steps/activate-theme.spec.ts @@ -80,4 +80,28 @@ describe('Blueprint step activateTheme()', () => { expect(php.fileExists(createdFilePath)).toBe(true); }); + + it('should detect a silent failure in activating the theme', async () => { + const docroot = php.documentRoot; + php.mkdir(`${docroot}/wp-content/themes/test-theme`); + php.writeFile( + `${docroot}/wp-content/themes/test-theme/style.css`, + `/** +* Theme Name: Test Theme +* Theme URI: https://example.com/test-theme +* Author: Test Author +*/ + ` + ); + php.writeFile( + `/${docroot}/wp-content/mu-plugins/0-exit.php`, + ` + await activateTheme(php, { + themeFolderName: 'test-theme', + }) + ).rejects.toThrow(/Theme test-theme could not be activated/); + }); }); diff --git a/packages/playground/blueprints/src/lib/steps/activate-theme.ts b/packages/playground/blueprints/src/lib/steps/activate-theme.ts index 697d27bb4f..8b05fb1165 100644 --- a/packages/playground/blueprints/src/lib/steps/activate-theme.ts +++ b/packages/playground/blueprints/src/lib/steps/activate-theme.ts @@ -1,5 +1,5 @@ -import { phpVar } from '@php-wasm/util'; import { StepHandler } from '.'; +import { logger } from '@php-wasm/logger'; /** * @inheritDoc activateTheme @@ -44,15 +44,33 @@ export const activateTheme: StepHandler = async ( More info can be found in the Blueprint documentation: https://wordpress.github.io/wordpress-playground/blueprints-api/steps/#ActivateThemeStep `); } - await playground.run({ + const result = await playground.run({ code: ` 'Administrator') )[0]->ID ); - switch_theme( ${phpVar(themeFolderName)} ); + switch_theme( getenv('themeFolderName') ); + + if( wp_get_theme()->get_stylesheet() !== getenv('themeFolderName') ) { + throw new Exception( 'Theme ' . getenv('themeFolderName') . ' could not be activated.' ); + } + die('Theme activated successfully'); `, + env: { + docroot, + themeFolderName, + }, }); + if (result.text !== 'Theme activated successfully') { + logger.debug(result); + throw new Error( + `Theme ${themeFolderName} could not be activated – WordPress exited with no error. ` + + `Sometimes, when $_SERVER or site options are not configured correctly, ` + + `WordPress exits early with a 301 redirect. ` + + `Inspect the "debug" logs in the console for more details` + ); + } };