Fix code quality issues and improve test framework
This commit is contained in:
12
.github/workflows/wordpress-tests.yml
vendored
12
.github/workflows/wordpress-tests.yml
vendored
@@ -12,12 +12,12 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: '20'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
@@ -42,12 +42,12 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: '20'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ wp-plugin-starter-template/
|
|||||||
├── cypress.config.js # Cypress configuration
|
├── cypress.config.js # Cypress configuration
|
||||||
├── .ai-workflows/ # AI workflow documentation
|
├── .ai-workflows/ # AI workflow documentation
|
||||||
├── .wiki/ # Wiki documentation
|
├── .wiki/ # Wiki documentation
|
||||||
|
│ ├── Testing-Framework.md # Testing framework documentation
|
||||||
|
│ └── Multisite-Development.md # Multisite development guide
|
||||||
└── wp-plugin-starter-template.php # Main plugin file
|
└── wp-plugin-starter-template.php # Main plugin file
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -129,3 +131,5 @@ The plugin includes a comprehensive testing framework:
|
|||||||
## Conclusion
|
## Conclusion
|
||||||
|
|
||||||
This architecture provides a solid foundation for WordPress plugin development, following best practices and modern coding standards. It's designed to be maintainable, extensible, and easy to understand.
|
This architecture provides a solid foundation for WordPress plugin development, following best practices and modern coding standards. It's designed to be maintainable, extensible, and easy to understand.
|
||||||
|
|
||||||
|
For more details on using the testing framework, see [Testing Framework](Testing-Framework.md). For multisite development guidelines, refer to [Multisite Development](Multisite-Development.md).
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ This template includes configuration for WordPress Environment (wp-env) to make
|
|||||||
```
|
```
|
||||||
|
|
||||||
3. For testing in different WordPress environments:
|
3. For testing in different WordPress environments:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# For single site testing
|
# For single site testing
|
||||||
npm run setup:single
|
npm run setup:single
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Make the bin directory executable
|
# Make this script executable
|
||||||
chmod +x bin
|
chmod +x "$0"
|
||||||
|
|
||||||
# Check if wp-env is installed
|
# Check if wp-env is installed
|
||||||
if ! command -v wp-env &> /dev/null; then
|
if ! command -v wp-env &> /dev/null; then
|
||||||
@@ -23,11 +23,26 @@ if [ "$ENV_TYPE" == "single" ]; then
|
|||||||
# Start the environment
|
# Start the environment
|
||||||
wp-env start
|
wp-env start
|
||||||
|
|
||||||
# Wait for WordPress to be ready
|
# Wait for WordPress to be ready with a timeout
|
||||||
sleep 5
|
MAX_ATTEMPTS=30
|
||||||
|
ATTEMPT=0
|
||||||
|
echo "Waiting for WordPress to be ready..."
|
||||||
|
until wp-env run cli wp core is-installed || [ $ATTEMPT -ge $MAX_ATTEMPTS ]; do
|
||||||
|
ATTEMPT=$((ATTEMPT+1))
|
||||||
|
echo "Attempt $ATTEMPT/$MAX_ATTEMPTS..."
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $ATTEMPT -ge $MAX_ATTEMPTS ]; then
|
||||||
|
echo "Timed out waiting for WordPress to be ready."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Activate our plugin
|
# Activate our plugin
|
||||||
wp-env run cli wp plugin activate wp-plugin-starter-template-for-ai-coding
|
if ! wp-env run cli wp plugin activate wp-plugin-starter-template-for-ai-coding; then
|
||||||
|
echo "Failed to activate plugin. Exiting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
echo "WordPress Single Site environment is ready!"
|
echo "WordPress Single Site environment is ready!"
|
||||||
echo "Site: http://localhost:8888"
|
echo "Site: http://localhost:8888"
|
||||||
@@ -39,14 +54,32 @@ elif [ "$ENV_TYPE" == "multisite" ]; then
|
|||||||
# Start the environment with multisite configuration
|
# Start the environment with multisite configuration
|
||||||
wp-env start --config=.wp-env.multisite.json
|
wp-env start --config=.wp-env.multisite.json
|
||||||
|
|
||||||
# Wait for WordPress to be ready
|
# Wait for WordPress to be ready with a timeout
|
||||||
sleep 5
|
MAX_ATTEMPTS=30
|
||||||
|
ATTEMPT=0
|
||||||
|
echo "Waiting for WordPress to be ready..."
|
||||||
|
until wp-env run cli wp core is-installed || [ $ATTEMPT -ge $MAX_ATTEMPTS ]; do
|
||||||
|
ATTEMPT=$((ATTEMPT+1))
|
||||||
|
echo "Attempt $ATTEMPT/$MAX_ATTEMPTS..."
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $ATTEMPT -ge $MAX_ATTEMPTS ]; then
|
||||||
|
echo "Timed out waiting for WordPress to be ready."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Create a test site
|
# Create a test site
|
||||||
wp-env run cli wp site create --slug=testsite --title="Test Site" --email=admin@example.com
|
if ! wp-env run cli wp site create --slug=testsite --title="Test Site" --email=admin@example.com; then
|
||||||
|
echo "Failed to create test site. Exiting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Network activate our plugin
|
# Network activate our plugin
|
||||||
wp-env run cli wp plugin activate wp-plugin-starter-template-for-ai-coding --network
|
if ! wp-env run cli wp plugin activate wp-plugin-starter-template-for-ai-coding --network; then
|
||||||
|
echo "Failed to activate plugin. Exiting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
echo "WordPress Multisite environment is ready!"
|
echo "WordPress Multisite environment is ready!"
|
||||||
echo "Main site: http://localhost:8888"
|
echo "Main site: http://localhost:8888"
|
||||||
|
|||||||
@@ -2,27 +2,25 @@ describe('WordPress Multisite Tests', () => {
|
|||||||
it('Can access the main site', () => {
|
it('Can access the main site', () => {
|
||||||
cy.visit('/');
|
cy.visit('/');
|
||||||
cy.get('body').should('exist');
|
cy.get('body').should('exist');
|
||||||
|
cy.get('h1').should('exist');
|
||||||
|
cy.title().should('include', 'WordPress');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Can access the test subsite', () => {
|
it('Can access the test subsite', () => {
|
||||||
cy.visit('/testsite');
|
cy.visit('/testsite');
|
||||||
cy.get('body').should('exist');
|
cy.get('body').should('exist');
|
||||||
|
cy.get('h1').should('exist');
|
||||||
|
cy.title().should('include', 'Test Site');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Can login to the admin area', () => {
|
it('Can login to the admin area', () => {
|
||||||
cy.visit('/wp-admin');
|
cy.loginAsAdmin();
|
||||||
cy.get('#user_login').type('admin');
|
cy.get('#wpadminbar').should('exist');
|
||||||
cy.get('#user_pass').type('password');
|
cy.get('#dashboard-widgets').should('exist');
|
||||||
cy.get('#wp-submit').click();
|
|
||||||
cy.get('body.wp-admin').should('exist');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Can access network admin', () => {
|
it('Can access network admin', () => {
|
||||||
// Login first
|
cy.loginAsAdmin();
|
||||||
cy.visit('/wp-admin');
|
|
||||||
cy.get('#user_login').type('admin');
|
|
||||||
cy.get('#user_pass').type('password');
|
|
||||||
cy.get('#wp-submit').click();
|
|
||||||
|
|
||||||
// Go to network admin
|
// Go to network admin
|
||||||
cy.visit('/wp-admin/network/');
|
cy.visit('/wp-admin/network/');
|
||||||
@@ -30,14 +28,20 @@ describe('WordPress Multisite Tests', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Plugin is network activated', () => {
|
it('Plugin is network activated', () => {
|
||||||
// Login first
|
cy.loginAsAdmin();
|
||||||
cy.visit('/wp-admin');
|
|
||||||
cy.get('#user_login').type('admin');
|
|
||||||
cy.get('#user_pass').type('password');
|
|
||||||
cy.get('#wp-submit').click();
|
|
||||||
|
|
||||||
// Check plugins page
|
// Check plugins page
|
||||||
cy.visit('/wp-admin/network/plugins.php');
|
cy.visit('/wp-admin/network/plugins.php');
|
||||||
cy.contains('tr', 'WP Plugin Starter Template').should('contain', 'Network Active');
|
cy.contains('tr', 'WP Plugin Starter Template').should('contain', 'Network Active');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Network settings page loads correctly', () => {
|
||||||
|
cy.loginAsAdmin();
|
||||||
|
|
||||||
|
// Navigate to the network settings page (if it exists)
|
||||||
|
cy.visit('/wp-admin/network/settings.php');
|
||||||
|
|
||||||
|
// This is a basic check for the network settings page
|
||||||
|
cy.get('h1').should('contain', 'Network Settings');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,22 +5,26 @@ describe('WordPress Single Site Tests', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Can login to the admin area', () => {
|
it('Can login to the admin area', () => {
|
||||||
cy.visit('/wp-admin');
|
cy.loginAsAdmin();
|
||||||
cy.get('#user_login').type('admin');
|
cy.get('#wpadminbar').should('exist');
|
||||||
cy.get('#user_pass').type('password');
|
cy.get('#dashboard-widgets').should('exist');
|
||||||
cy.get('#wp-submit').click();
|
|
||||||
cy.get('body.wp-admin').should('exist');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Plugin is activated', () => {
|
it('Plugin is activated', () => {
|
||||||
// Login first
|
cy.loginAsAdmin();
|
||||||
cy.visit('/wp-admin');
|
|
||||||
cy.get('#user_login').type('admin');
|
|
||||||
cy.get('#user_pass').type('password');
|
|
||||||
cy.get('#wp-submit').click();
|
|
||||||
|
|
||||||
// Check plugins page
|
// Check plugins page
|
||||||
cy.visit('/wp-admin/plugins.php');
|
cy.visit('/wp-admin/plugins.php');
|
||||||
cy.contains('tr', 'WP Plugin Starter Template').should('contain', 'Deactivate');
|
cy.contains('tr', 'WP Plugin Starter Template').should('contain', 'Deactivate');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Plugin settings page loads correctly', () => {
|
||||||
|
cy.loginAsAdmin();
|
||||||
|
|
||||||
|
// Navigate to the plugin settings page (if it exists)
|
||||||
|
cy.visit('/wp-admin/options-general.php?page=wp-plugin-starter-template');
|
||||||
|
|
||||||
|
// This is a basic check - adjust based on your actual plugin's settings page
|
||||||
|
cy.get('h1').should('contain', 'WP Plugin Starter Template');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
20
cypress/support/commands.js
Normal file
20
cypress/support/commands.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// ***********************************************
|
||||||
|
// This example commands.js shows you how to
|
||||||
|
// create various custom commands and overwrite
|
||||||
|
// existing commands.
|
||||||
|
//
|
||||||
|
// For more comprehensive examples of custom
|
||||||
|
// commands please read more here:
|
||||||
|
// https://on.cypress.io/custom-commands
|
||||||
|
// ***********************************************
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom command to login as admin
|
||||||
|
*/
|
||||||
|
Cypress.Commands.add('loginAsAdmin', () => {
|
||||||
|
cy.visit('/wp-admin');
|
||||||
|
cy.get('#user_login').type('admin');
|
||||||
|
cy.get('#user_pass').type('password');
|
||||||
|
cy.get('#wp-submit').click();
|
||||||
|
cy.get('body.wp-admin').should('exist');
|
||||||
|
});
|
||||||
17
cypress/support/e2e.js
Normal file
17
cypress/support/e2e.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
// ***********************************************************
|
||||||
|
// This example support/e2e.js is processed and
|
||||||
|
// loaded automatically before your test files.
|
||||||
|
//
|
||||||
|
// This is a great place to put global configuration and
|
||||||
|
// behavior that modifies Cypress.
|
||||||
|
//
|
||||||
|
// You can change the location of this file or turn off
|
||||||
|
// automatically serving support files with the
|
||||||
|
// 'supportFile' configuration option.
|
||||||
|
//
|
||||||
|
// You can read more here:
|
||||||
|
// https://on.cypress.io/configuration
|
||||||
|
// ***********************************************************
|
||||||
|
|
||||||
|
// Import commands.js using ES2015 syntax:
|
||||||
|
import './commands';
|
||||||
@@ -43,9 +43,6 @@ class Admin {
|
|||||||
*
|
*
|
||||||
* This method is hooked into 'admin_enqueue_scripts'. It checks if the current
|
* This method is hooked into 'admin_enqueue_scripts'. It checks if the current
|
||||||
* screen is relevant to the plugin before enqueueing assets.
|
* screen is relevant to the plugin before enqueueing assets.
|
||||||
|
|
||||||
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public function enqueue_admin_assets(): void {
|
public function enqueue_admin_assets(): void {
|
||||||
|
|
||||||
|
|||||||
@@ -21,4 +21,4 @@ if ( is_multisite() ) {
|
|||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
For information on testing your plugin in a multisite environment, see the [Testing Framework](.wiki/Testing-Framework.md) documentation.
|
For information on testing your plugin in a multisite environment, see the [Testing Framework](../../.wiki/Testing-Framework.md) documentation.
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class Multisite {
|
|||||||
*
|
*
|
||||||
* @return bool Always returns true.
|
* @return bool Always returns true.
|
||||||
*/
|
*/
|
||||||
public function is_multisite_compatible() {
|
public function isMultisiteCompatible() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,9 +45,9 @@ class Multisite {
|
|||||||
*
|
*
|
||||||
* @return array An empty array as this is just a placeholder.
|
* @return array An empty array as this is just a placeholder.
|
||||||
*/
|
*/
|
||||||
public function get_network_sites() {
|
public function getNetworkSites() {
|
||||||
// This is just a placeholder method.
|
// This is just a placeholder method.
|
||||||
// In a real implementation, you might use get_sites() or a custom query.
|
// In a real implementation, you might use get_sites() or a custom query.
|
||||||
return array();
|
return function_exists('get_sites') ? get_sites(['public' => 1]) : array();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user