Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
aa2437d
Add plugins folder
mukeshpanchal27 Jan 18, 2024
c366c91
ignore plugins folder
mukeshpanchal27 Jan 18, 2024
2ebdda4
Restructure the plugins.json file
mukeshpanchal27 Jan 18, 2024
c59f9f9
Update build-plugins script
mukeshpanchal27 Jan 18, 2024
5ab7268
Update test-plugins script
mukeshpanchal27 Jan 18, 2024
177b2e9
Update Deploy standalone plugins workflow
mukeshpanchal27 Jan 18, 2024
c55b3e6
Add plugins in tooling
mukeshpanchal27 Jan 18, 2024
7c3d1d1
Merge branch 'feature/modules-to-plugins' into add/934-plugins-folder
mukeshpanchal27 Jan 18, 2024
7df015d
Apply suggestions from code review
mukeshpanchal27 Jan 18, 2024
643d78b
Update variable names
mukeshpanchal27 Jan 19, 2024
b0bad91
Remove the temporary changes
mukeshpanchal27 Jan 19, 2024
16fda54
Merge pull request #948 from WordPress/add/934-plugins-folder
felixarntz Jan 19, 2024
dbe1a99
Plugin test suite
mukeshpanchal27 Jan 29, 2024
cef64a3
Add test file
mukeshpanchal27 Jan 29, 2024
8a40b2c
Run test for branch
mukeshpanchal27 Jan 29, 2024
43b630a
Update test command
mukeshpanchal27 Jan 30, 2024
54ca2e6
Update unit test command
mukeshpanchal27 Jan 30, 2024
218a69d
Merge pull request #959 from WordPress/trunk
westonruter Jan 30, 2024
7c92bc0
Merge branch 'feature/modules-to-plugins' into add/plugins-test-suite
mukeshpanchal27 Jan 31, 2024
4d18663
Add another test
mukeshpanchal27 Feb 5, 2024
2b9693f
Merge branch 'add/plugins-test-suite' of github.com:WordPress/perform…
mukeshpanchal27 Feb 5, 2024
8c04816
Merge pull request #968 from WordPress/trunk
mukeshpanchal27 Feb 5, 2024
f47b1f8
Merge branch 'feature/modules-to-plugins' into add/plugins-test-suite
mukeshpanchal27 Feb 5, 2024
c75b3dc
Revert changes
mukeshpanchal27 Feb 5, 2024
ecd9d21
Adjust composer update
mukeshpanchal27 Feb 5, 2024
500fb91
Update plugin name to Test Plugin
mukeshpanchal27 Feb 6, 2024
4c21e8f
Merge pull request #956 from WordPress/add/plugins-test-suite
mukeshpanchal27 Feb 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/docs export-ignore
/tests export-ignore
/plugin-tests export-ignore
/plugins export-ignore

/*.DS_store export-ignore
/.DS_store? export-ignore
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-standalone-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
# for use in the matrix.
# The "dry-run" parameter is included here to set the deployment mode.
# When running the manual (workflow_dispatch) workflow, this value will be set from manual input type.
echo "matrix="$(jq -c '{include:[keys[] as $k | {name:$k,slug:.[$k].slug,version:.[$k].version,"dry-run":false }]}' plugins.json) >> $GITHUB_OUTPUT
echo "matrix="$(jq -c '{include:[.modules | to_entries[] | {name:.key,slug:.value.slug,version:.value.version,"dry-run":false }]}' plugins.json) >> $GITHUB_OUTPUT
fi
deploy:
name: Deploy Plugin
Expand Down
78 changes: 78 additions & 0 deletions .github/workflows/php-test-plugins.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Unit Testing for Test Plugin

on:
push:
branches:
- trunk
- 'release/**'
# Only run if PHP-related files changed.
paths:
- '.github/workflows/php-test-plugins.yml'
- '**.php'
- '.wp-env.json'
- '**/package.json'
- 'package-lock.json'
- 'phpunit.xml.dist'
- 'tests/multisite.xml'
- 'composer.json'
- 'composer.lock'
pull_request:
branches:
- trunk
- 'release/**'
- 'feature/**'
# Only run if PHP-related files changed.
paths:
- '.github/workflows/php-test-plugins.yml'
- '**.php'
- '.wp-env.json'
- '**/package.json'
- 'package-lock.json'
- 'phpunit.xml.dist'
- 'tests/multisite.xml'
- 'composer.json'
- 'composer.lock'
types:
- opened
- reopened
- synchronize

jobs:
php-test-plugins:
name: "PHP ${{ matrix.php }} / WP ${{ matrix.wp }}"
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
php: ['8.2', '8.1', '8.0', '7.4', '7.3', '7.2', '7.1', '7.0']
wp: [ 'latest' ]
include:
- php: '7.4'
wp: '6.3'
- php: '8.3'
wp: 'trunk'
env:
WP_ENV_PHP_VERSION: ${{ matrix.php }}
WP_ENV_CORE: ${{ matrix.wp == 'trunk' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wp ) }}
steps:
- uses: styfle/cancel-workflow-action@0.11.0
- uses: actions/checkout@v3
- name: Setup Node.js (.nvmrc)
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: npm
- name: npm install
run: npm ci
- name: Install WordPress
run: npm run wp-env start
# Note that `composer update` is required instead of `composer install`
# for the sake of PHP versions older than 8.1, which is the version of
# PHP that the composer.lock was created for.
- name: Composer update
run: npm run wp-env run tests-cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer update --no-interaction
- name: Running single site unit tests
run: npm run test-php -- -- -- --testsuite test-plugin
- name: Running multisite unit tests
run: npm run test-php-multisite -- -- -- --testsuite test-plugin
11 changes: 10 additions & 1 deletion bin/plugin/commands/build-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ exports.handler = async () => {
}

try {
const plugins = JSON.parse( jsonString );
const pluginsConfig = JSON.parse( jsonString );
const plugins = pluginsConfig.modules;
if ( ! plugins ) {
log(
formats.error(
'The given module configuration is invalid, the modules are missing, or they are misspelled.'
)
);
return;
}
for ( const moduleDir in plugins ) {
const pluginVersion = plugins[ moduleDir ]?.version;
const pluginSlug = plugins[ moduleDir ]?.slug;
Expand Down
14 changes: 12 additions & 2 deletions bin/plugin/commands/get-plugin-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,25 @@ function doRunGetPluginVersion( settings ) {
);
}

const plugins = JSON.parse( pluginsFileContent );
const pluginsConfig = JSON.parse( pluginsFileContent );

// Check for valid and not empty object resulting from plugins JSON file parse.
if ( 'object' !== typeof plugins || 0 === Object.keys( plugins ).length ) {
if (
'object' !== typeof pluginsConfig ||
0 === Object.keys( pluginsConfig ).length
) {
throw Error(
`File at "${ pluginsFile }" parsed, but detected empty/non valid JSON object.`
);
}

const plugins = pluginsConfig.modules;
if ( ! plugins ) {
throw Error(
`File at "${ pluginsFile }" parsed, but the modules are missing, or they are misspelled.`
);
}

for ( const moduleDir in plugins ) {
const pluginVersion = plugins[ moduleDir ]?.version;
const pluginSlug = plugins[ moduleDir ]?.slug;
Expand Down
26 changes: 19 additions & 7 deletions bin/plugin/commands/test-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,12 @@ function doRunStandalonePluginTests( settings ) {
);
}

const pluginsJsonFileContentAsJson = JSON.parse( pluginsJsonFileContent );
const pluginsConfig = JSON.parse( pluginsJsonFileContent );

// Check for valid and not empty object resulting from plugins JSON file parse.
if (
'object' !== typeof pluginsJsonFileContentAsJson ||
0 === Object.keys( pluginsJsonFileContentAsJson ).length
'object' !== typeof pluginsConfig ||
0 === Object.keys( pluginsConfig ).length
) {
log(
formats.error(
Expand All @@ -445,24 +445,36 @@ function doRunStandalonePluginTests( settings ) {
process.exit( 1 );
}

const plugins = pluginsConfig.modules;
if ( ! plugins ) {
log(
formats.error(
'The given module configuration is invalid, the modules are missing, or they are misspelled.'
)
);

// Return with exit code 1 to trigger a failure in the test pipeline.
process.exit( 1 );
}

// Create an array of plugins from entries in plugins JSON file.
builtPlugins = Object.keys( pluginsJsonFileContentAsJson )
builtPlugins = Object.keys( plugins )
.filter( ( item ) => {
if (
! fs.pathExistsSync(
`${ settings.builtPluginsDir }${ pluginsJsonFileContentAsJson[ item ].slug }`
`${ settings.builtPluginsDir }${ plugins[ item ].slug }`
)
) {
log(
formats.error(
`Built plugin path "${ settings.builtPluginsDir }${ pluginsJsonFileContentAsJson[ item ].slug }" not found, skipping and removing from plugin list`
`Built plugin path "${ settings.builtPluginsDir }${ plugins[ item ].slug }" not found, skipping and removing from plugin list`
)
);
return false;
}
return true;
} )
.map( ( item ) => pluginsJsonFileContentAsJson[ item ].slug );
.map( ( item ) => plugins[ item ].slug );

// For each built plugin, copy the test assets.
builtPlugins.forEach( ( plugin ) => {
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"phpstan": "build-cs/vendor/bin/phpstan analyse --memory-limit=2048M -c phpstan.neon.dist",
"format": "build-cs/vendor/bin/phpcbf --standard=phpcs.xml.dist --report-summary --report-source",
"lint": "build-cs/vendor/bin/phpcs --standard=phpcs.xml.dist",
"test": "phpunit -c phpunit.xml.dist --verbose",
"test-multisite": "phpunit -c tests/multisite.xml --verbose"
"test": "phpunit -c phpunit.xml.dist --verbose --testsuite performance-lab",
"test-multisite": "phpunit -c tests/multisite.xml --verbose --testsuite performance-lab"
},
"config": {
"allow-plugins": {
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<file>./admin</file>
<file>./load.php</file>
<file>./modules</file>
<file>./plugins</file>
<file>./server-timing</file>
<file>./tests</file>

Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ parameters:
- load.php
- module-i18n.php
- modules/
- plugins/
- server-timing/
- tests/
- uninstall.php
Expand Down
8 changes: 6 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite name="default">
<testsuite name="performance-lab">
<directory suffix=".php">./tests</directory>
<exclude>./tests/utils</exclude>
<exclude>./tests/utils</exclude>
<exclude>./tests/plugins</exclude>
</testsuite>
<testsuite name="test-plugin">
<directory suffix=".php">./tests/plugins/test-plugin</directory>
</testsuite>
</testsuites>
<groups>
Expand Down
17 changes: 10 additions & 7 deletions plugins.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"images/dominant-color-images": {
"slug": "dominant-color-images",
"version": "1.0.1"
"modules": {
"images/dominant-color-images": {
"slug": "dominant-color-images",
"version": "1.0.1"
},
"images/webp-uploads": {
"slug": "webp-uploads",
"version": "1.0.5"
}
},
"images/webp-uploads": {
"slug": "webp-uploads",
"version": "1.0.5"
}
"plugins": []
}
Empty file added plugins/.gitkeep
Empty file.
20 changes: 20 additions & 0 deletions tests/plugins/test-plugin/test-plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Class Plugin Test Suite
*
* @package performance-lab
*/

/**
* Plugin test case.
*/
class PluginTest extends WP_UnitTestCase {

public function test_plugin_does_not_fatal() {
$this->assertTrue( true );
}

public function test_another_plugin_does_not_fatal() {
$this->assertTrue( true );
}
}