Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress E2E Tests #68

Draft
wants to merge 42 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
aed8849
Update .editorconfig
joshuadavidnelson Dec 23, 2023
61b1f57
bump supported php and wp versions
joshuadavidnelson Jun 16, 2024
304dc8b
first go at some cypress tests
joshuadavidnelson May 12, 2023
723a77f
remove composer install from cypress workflow
joshuadavidnelson May 12, 2023
dbb579e
remove unused packages from package.json
joshuadavidnelson May 12, 2023
f60258d
fix bash script permissions
joshuadavidnelson May 12, 2023
bdf4b66
fix min wp core in cypress action
joshuadavidnelson May 12, 2023
dbbb86c
fix permissions on initialize.sh
joshuadavidnelson May 12, 2023
65426a7
fix stray comma in .wp-env.json
joshuadavidnelson May 12, 2023
94b60aa
Update .gitignore
joshuadavidnelson May 12, 2023
52f155f
add wait to tests
joshuadavidnelson May 12, 2023
549cca1
update admin test message
joshuadavidnelson May 12, 2023
5008f25
Update cypress.yml
joshuadavidnelson May 12, 2023
47db867
Update package.json
joshuadavidnelson May 12, 2023
920f062
remove blog redirect test for now
joshuadavidnelson May 12, 2023
915509a
use a function to test redirect request & response
joshuadavidnelson May 12, 2023
9c99552
add some more e2e tests
joshuadavidnelson May 14, 2023
69fb144
Update config.config.js
joshuadavidnelson May 15, 2023
2ad550a
update redirect tests to use custom command
joshuadavidnelson May 15, 2023
ef58275
Create sitemap.test.js
joshuadavidnelson May 15, 2023
04f854c
Update redirects.test.js
joshuadavidnelson May 15, 2023
3801dd2
add xml-rpc endpoints checks
joshuadavidnelson May 15, 2023
e9b8ad4
check disable-comments plugin works with disable-blog
joshuadavidnelson May 15, 2023
a6c4cb6
readme
joshuadavidnelson May 15, 2023
2d16094
Update comments.test.js
joshuadavidnelson May 15, 2023
53861ba
bump up min wp tested to reduce ci errors
joshuadavidnelson May 15, 2023
67fecbe
remove disable-comments test
joshuadavidnelson May 15, 2023
0a9b234
simplify testing matrix to start
joshuadavidnelson May 15, 2023
1986d24
clean wp test environment on initialize
joshuadavidnelson May 16, 2023
9dce864
create a blog page on initialize
joshuadavidnelson May 16, 2023
00f2a2c
flush out the comment test
joshuadavidnelson May 16, 2023
a0c8cd1
Update endpoints.test.js
joshuadavidnelson May 16, 2023
4159c98
add test to set blog page
joshuadavidnelson May 16, 2023
7e217fd
add init script to cypress commands
joshuadavidnelson May 16, 2023
5b3d4dc
bump up wp min tested to v5.6
joshuadavidnelson May 16, 2023
856b776
Update .wp-env.json
joshuadavidnelson Jun 15, 2024
b85c2ca
update cypress
joshuadavidnelson Jun 16, 2024
a748e0c
Update class-disable-blog-functions.php
joshuadavidnelson Jun 16, 2024
96c9e7c
Update README.md
joshuadavidnelson Jun 16, 2024
9f82893
Update cypress.yml
joshuadavidnelson Jun 16, 2024
e5c9627
Update class-disable-blog-functions.php
joshuadavidnelson Jun 16, 2024
71229c2
Update class-disable-blog-functions.php
joshuadavidnelson Jun 16, 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
22 changes: 21 additions & 1 deletion .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,32 @@
/tests/
.editorconfig
.gitignore
.gitattributes
.distignore
composer.json
composer.lock
code-of-conduct.md
contributing.md
phpstan.neon.dist
*.sql
*.tar.gz
*.zip
.git
.github
.travis.yml
.DS_Store
.wp-env.json
Thumbs.db
bin
package.json
package-lock.json
.wp-env.json
node_modules
phpunit.xml
phpunit.xml.dist
phpstan.neon
phpstan.neon.dist
README.md
tests
.wordpress-org
wp-cli.local.yml
cypress.config.js
6 changes: 3 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[*.yml]
[*.{yml,yaml,json,js,css}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[{*.txt,wp-config-sample.php}]
end_of_line = crlf
[*.{txt,php}]
end_of_line = crlf
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Directories
/.wordpress-org export-ignore
/.github export-ignore

# Files
/.gitattributes export-ignore
/.gitignore export-ignore
52 changes: 52 additions & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: E2E Testing

on:
push:
branches:
- stable
- develop
pull_request:
branches:
- stable
- develop

jobs:
cypress:
name: ${{ matrix.core.name }} / ${{ matrix.php.name }}
## Pending upgrade of `@wordpress/env` package.
continue-on-error: ${{ matrix.core.version == 'WordPress/WordPress#master' }}
runs-on: ubuntu-latest
strategy:
matrix:
php:
- {name: 'PHP Default', version: null}
core:
- {name: 'WP stable', version: 'latest'}
- {name: 'WP 5.9', version: 'WordPress/WordPress#5.9'}
- {name: 'WP trunk', version: 'WordPress/WordPress#master'}
include:
- php: {name: 'PHP 7.1', version: '7.1'}
core: {name: 'WP 5.9', version: 'WordPress/WordPress#5.9'}
- php: {name: 'PHP 8.3', version: '8.3'}
core: {name: 'WP stable', version: 'latest'}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install dependencies
run: npm install

- name: Set the core version
run: |
./tests/bin/set-core-version.js ${{ matrix.core.version }} ${{ matrix.php.version }}

- name: Set up WP environment
run: npm run env:start

- name: Log WP environment versions
run: |
npx wp-env run cli "wp core version"
npx wp-env run cli "php --version"

- name: Test
run: npm run cypress:run
6 changes: 3 additions & 3 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: "ubuntu-latest"
strategy:
matrix:
php-versions: ['7.4', '8.0', '8.1', '8.2.']
php-versions: ['8.1', '8.2.', '8.3']
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
Expand All @@ -32,7 +32,7 @@ jobs:
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.1"
php-version: "8.2"
- name: "Install PHPCS"
run: |
composer require --no-plugins --dev wp-coding-standards/wpcs
Expand All @@ -50,7 +50,7 @@ jobs:
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.1"
php-version: "8.2"
- name: "Install PHPStan"
run: "composer require --dev szepeviktor/phpstan-wordpress"
- name: "Run PHPStan"
Expand Down
14 changes: 11 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
/vendor/
/node_modules/
.DS_Store
*.lock
Thumbs.db
wp-cli.local.yml
*.sql
*.tar.gz
*.zip
tests/cypress/videos
tests/cypress/screenshots
tests/cypress/downloads
node_modules
dist
vendor
9 changes: 7 additions & 2 deletions .wp-env.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
"WP_DEBUG": true,
"WP_DEBUG_LOG": true
},
"phpVersion": "8.2",
"phpVersion": "8.3",
"plugins": [
"."
]
],
"mappings": {
"wp-cli.yml": "./tests/bin/wp-cli.yml",
"wp-content/plugins/author-archive-filter.php": "./tests/cypress/test-plugins/author-archive-filter.php",
"wp-content/plugins/remove-options-writing.php": "./tests/cypress/test-plugins/remove-options-writing.php"
}
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.5.5
- Tested up to WordPress 6.5.4
- Bump minimum WordPress version to 5.9, aligning with minimum PHP support.
- Tested up to PHP 8.3
- Bump minimum PHP to 8.1, lowest version being maintained.

## 0.5.4
- Tested up to WordPress 6.4.2.
- Bump minimum WordPress version to 5.3, aligning with minimum PHP support.
Expand Down
31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ Disable Blog

[![WordPress Plugin Version](https://img.shields.io/wordpress/plugin/v/disable-blog)](https://wordpress.org/plugins/disable-blog/) ![Downloads](https://img.shields.io/wordpress/plugin/dt/disable-blog.svg) ![Rating](https://img.shields.io/wordpress/plugin/r/disable-blog.svg)

**Requires at least WordPress:** 5.3
**Tested up to WordPress:** 6.4.2
**Stable version:** 0.5.4
**Requires at least WordPress:** 5.9
**Tested up to WordPress:** 6.5.4
**Stable version:** 0.5.5
**License:** GPLv2 or later
**Requires PHP:** 7.4
**Tested up to PHP:** 8.2
**Requires PHP:** 8.1
**Tested up to PHP:** 8.3

All the power of WordPress, without a blog.

Expand Down Expand Up @@ -122,3 +122,24 @@ The `develop` branch is the most current working branch. _Please direct all pull
This repo contains the files needed to boot up a local development environment using [wp-env](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/).

Run `npm install` and the `npm run env:start` to boot up a local environment.

### Running Tests

End to end testing is setup to run with Cypress (see more documentation [here](https://docs.cypress.io/) and [here](https://deliciousbrains.com/cypress-testing/)).

The intent with these tests is to show that Disable Blog works with common WordPress core user experiences as expected.

If you're contributing new functionality to the plugin, please write tests! If you're altering functionality, please make sure existing tests continue to work or update and explain why the change was needed in your pull request.

To setup Cypress from the root directory of the plugin:
1. Run `npm install` to install Cypress and other dependencies.
2. Run `npm run cypress:open` to open Cypress.

### Unit Tests

Unit tests are run on `phpunit`. You'll need `composer` to install the required packages.

1. Run `composer install`
2. Run `./vendor/bin/phpunit` to run tests.

All tests should go into the `tests/php/` subfolder, be named as a class extending `TestCase` with the filename
164 changes: 82 additions & 82 deletions disable-blog.php
Original file line number Diff line number Diff line change
@@ -1,82 +1,82 @@
<?php
/**
* The plugin bootstrap file.
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link https://github.com/joshuadavidnelson/disable-blog
* @since 0.4.0
* @package Disable_Blog
*
* @wordpress-plugin
* Plugin Name: Disable Blog
* Plugin URI: https://wordpress.org/plugins/disable-blog/
* Description: Go blog-less with WordPress. This plugin disables all blog-related functionality (by hiding, removing, and redirecting).
* Version: 0.5.4
* Author: Joshua David Nelson
* Author URI: http://joshuadnelson.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: disable-blog
* Domain Path: /languages
*/

/**
* Exit if accessed directly.
*
* Prevent direct access to this file.
*
* @since 0.1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
die;
}

/**
* The code that runs during plugin activation.
* This action is documented in includes/class-disable-blog-activator.php
*/
function activate_disable_blog() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-disable-blog-activator.php';
Disable_Blog_Activator::activate();
}

/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-disable-blog-deactivator.php
*/
function deactivate_disable_blog() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-disable-blog-deactivator.php';
Disable_Blog_Deactivator::deactivate();
}
register_activation_hook( __FILE__, 'activate_disable_blog' );
register_deactivation_hook( __FILE__, 'deactivate_disable_blog' );

// Constants.
define( 'DWPB_DIR', __DIR__ );
define( 'DWPB_URL', plugins_url( '/', __FILE__ ) );
define( 'DWPB_PLUGIN_NAME', 'disable-blog' );
define( 'DWPB_VERSION', '0.5.4' );

/**
* The core plugin class that is used to define everything.
*/
require plugin_dir_path( __FILE__ ) . 'includes/class-disable-blog.php';

/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 0.4.0
*/
function run_disable_blog() {
$plugin = new Disable_Blog( DWPB_PLUGIN_NAME, DWPB_VERSION );
$plugin->run();
}
add_action( 'plugins_loaded', 'run_disable_blog', 10, 0 );
<?php
/**
* The plugin bootstrap file.
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link https://github.com/joshuadavidnelson/disable-blog
* @since 0.4.0
* @package Disable_Blog
*
* @wordpress-plugin
* Plugin Name: Disable Blog
* Plugin URI: https://wordpress.org/plugins/disable-blog/
* Description: Go blog-less with WordPress. This plugin disables all blog-related functionality (by hiding, removing, and redirecting).
* Version: 0.5.5
* Author: Joshua David Nelson
* Author URI: http://joshuadnelson.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: disable-blog
* Domain Path: /languages
*/
/**
* Exit if accessed directly.
*
* Prevent direct access to this file.
*
* @since 0.1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
die;
}
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-disable-blog-activator.php
*/
function activate_disable_blog() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-disable-blog-activator.php';
Disable_Blog_Activator::activate();
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-disable-blog-deactivator.php
*/
function deactivate_disable_blog() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-disable-blog-deactivator.php';
Disable_Blog_Deactivator::deactivate();
}
register_activation_hook( __FILE__, 'activate_disable_blog' );
register_deactivation_hook( __FILE__, 'deactivate_disable_blog' );
// Constants.
define( 'DWPB_DIR', __DIR__ );
define( 'DWPB_URL', plugins_url( '/', __FILE__ ) );
define( 'DWPB_PLUGIN_NAME', 'disable-blog' );
define( 'DWPB_VERSION', '0.5.5' );
/**
* The core plugin class that is used to define everything.
*/
require plugin_dir_path( __FILE__ ) . 'includes/class-disable-blog.php';
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 0.4.0
*/
function run_disable_blog() {
$plugin = new Disable_Blog( DWPB_PLUGIN_NAME, DWPB_VERSION );
$plugin->run();
}
add_action( 'plugins_loaded', 'run_disable_blog', 10, 0 );
Loading
Loading