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

Dev-Anleitung #1209

Merged
merged 58 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
6f6cdb3
Initial version of wp-env file
datengraben Mar 2, 2023
1fb7707
added instructions for translation updates
hansmorb Apr 15, 2023
b88b553
Update Readme.md
datengraben Apr 16, 2023
1490013
Update Readme.md
datengraben Apr 16, 2023
9264bdf
Update Readme.md
hansmorb Apr 17, 2023
0356624
Add link to readme
datengraben May 10, 2023
a2d53a1
Adds useful plugins
datengraben May 14, 2023
5849d12
Merge branch 'master' into ft-wp-env
hansmorb May 14, 2023
1370b0e
updated composer packages
hansmorb May 14, 2023
919bb17
Merge branch 'master' into ft-wp-env
hansmorb May 14, 2023
42d8fd4
Mail logging plugin für convenience
datengraben Jun 21, 2023
eadb938
Merge branch 'master' into ft-wp-env
hansmorb Aug 28, 2023
143592b
fixed up README after merge
hansmorb Aug 28, 2023
021e28f
update composer packages after merge
hansmorb Aug 28, 2023
7033a1f
added experimental cypress support
hansmorb Aug 30, 2023
34aaba0
switch back ubuntu version
hansmorb Aug 31, 2023
2a1402f
tried adding compass
hansmorb Aug 31, 2023
00a179b
removed Cypress install
hansmorb Aug 31, 2023
9f0732b
removed video recording
hansmorb Aug 31, 2023
7ed9d2a
add error on purpose to see if tests will fail
hansmorb Aug 31, 2023
42baf06
fixed unit test to properly check if dashboard is present
hansmorb Aug 31, 2023
1c0b1fd
Revert "add error on purpose to see if tests will fail"
hansmorb Aug 31, 2023
4b08aca
upped WP version
hansmorb Aug 31, 2023
e209450
added tests to load every page
hansmorb Aug 31, 2023
4b0adc6
upped WP version
hansmorb Aug 31, 2023
91bdf2d
Add node 20.5.1 nvmrc
datengraben Sep 3, 2023
c497b2e
Use nvmrc in cypress path
datengraben Sep 3, 2023
ec6cce0
Use latest action and node 20
datengraben Sep 3, 2023
e2f00d3
Add bash script to build release
datengraben Apr 16, 2023
a527eae
Place nvmrc in root
datengraben Sep 3, 2023
46b7734
Revert "Add bash script to build release"
datengraben Sep 3, 2023
5d7163c
Takes screenshot of each page on success
datengraben Sep 3, 2023
5bcfddb
added cypress screenshot upload
hansmorb Sep 4, 2023
24c9cba
Merge pull request #1 from wielebenwir/experiment/cypress
datengraben Sep 4, 2023
528b4ac
Merge branch 'wielebenwir:master' into ft-wp-env
datengraben Sep 4, 2023
a58f265
added e2e testing instructions
hansmorb Sep 5, 2023
53c15d9
fixed typos & coherency
hansmorb Sep 5, 2023
6d01638
fixed jQuery not enqueued for map shortcodes
hansmorb Sep 11, 2023
df2feff
catch fatal error when import Locations from .xml export
hansmorb Sep 11, 2023
2b1e345
added test data & basic shortcode tests
hansmorb Sep 11, 2023
e04bc03
add rudimentary test for map shortcode
hansmorb Sep 11, 2023
5d4794b
added tests for booking process
hansmorb Sep 11, 2023
2e0aeae
fix load-wp tests & spread them out
hansmorb Sep 11, 2023
b31557c
Merge branch 'master' into ft-wp-env
hansmorb Sep 11, 2023
0c93dc1
updated cypress
hansmorb Sep 11, 2023
4fa6171
fix plugin activation sometimes not working
hansmorb Sep 11, 2023
5d98e90
Revert "fix plugin activation sometimes not working"
hansmorb Sep 11, 2023
19ebc3c
fixed broken behaviour when plugin was activated through cli
hansmorb Sep 11, 2023
1e2e256
added wait for map shortcode
hansmorb Sep 11, 2023
ea574d4
added badge for E2E tests
hansmorb Sep 11, 2023
74f49dc
added test for location & item frontend templates
hansmorb Sep 12, 2023
b81b0b2
added screenshots to gitignore
hansmorb Sep 12, 2023
9dd9f4f
Update Readme.md
hansmorb Sep 19, 2023
1570399
added start script (basically installation)
hansmorb Sep 19, 2023
1abdab2
added setup step to README.md
hansmorb Sep 19, 2023
c18a293
organized tests folders
hansmorb Sep 19, 2023
cae4f4b
Update Readme.md
hansmorb Sep 19, 2023
d574d95
Merge branch 'master' into ft-wp-env
hansmorb Sep 25, 2023
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
63 changes: 63 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: E2E Tests

on:
push:
paths-ignore:
- '**.md'
- '**.txt'
pull_request:
branches:
- 'master'

env:
DB_DATABASE: wordpress_test
DB_USER: root
DB_PASSWORD: ''

jobs:
build:

runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3

- uses: shivammathur/setup-php@v2
with:
php-version: '7.4'

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

- name: Install dependencies
run: |
composer install --no-dev --prefer-dist --no-progress

- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci --legacy-peer-deps --include=dev
- run: docker-compose -v
- name: setup wp env
run: npm run env:start

- name: install test data for e2e test
run: npm run cypress:setup

- name: Cypress run
uses: cypress-io/github-action@v6
with:
install: false
config-file: tests/cypress/cypress.config.js

- uses: actions/upload-artifact@v3
with:
name: cypress-screenshots
path: ${{ github.workspace }}/tests/cypress/screenshots/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ yarn.lock
cache
commonsbooking.zip
node_modules
./phpunit
src/Wordpress/.DS_Store
/vendor
src/.DS_Store
Expand All @@ -21,3 +22,4 @@ copy-svn.sh
cb-local-1.code-workspace
commonsbookingdocker.code-workspace
wp-core
cypress/screenshots
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.5.1
28 changes: 28 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"phpVersion": "7.4",
"core": "Wordpress/Wordpress#6.3.1",
"plugins": [
".",
"https://downloads.wordpress.org/plugin/wp-crontrol.zip",
"https://downloads.wordpress.org/plugin/wordpress-importer.zip",
"https://downloads.wordpress.org/plugin/query-monitor.zip",
"https://downloads.wordpress.org/plugin/wp-mail-logging.zip"
],
"port": 1000,
"testsPort": 1001,
"config": {
"WP_DEBUG": true,
"WP_DEBUG_LOG": true,
"WP_DEBUG_DISPLAY": false
},
"themes": [
"flegfleg/kasimir-theme"
],
"env": {
"tests": {
"mappings": {
"wp-content/plugins/commonsbooking": "."
}
}
}
}
106 changes: 102 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![PHP Composer](https://github.com/wielebenwir/commonsbooking/actions/workflows/php.yml/badge.svg)](https://github.com/wielebenwir/commonsbooking/actions/workflows/php.yml)
[![PHP Composer](https://github.com/wielebenwir/commonsbooking/actions/workflows/php.yml/badge.svg)](https://github.com/wielebenwir/commonsbooking/actions/workflows/php.yml)
[![E2E Tests](https://github.com/wielebenwir/commonsbooking/actions/workflows/e2e.yml/badge.svg)](https://github.com/wielebenwir/commonsbooking/actions/workflows/e2e.yml)
[![WP compatibility](https://plugintests.com/plugins/wporg/commonsbooking/wp-badge.svg)](https://plugintests.com/plugins/wporg/commonsbooking/latest)
[![PHP compatibility](https://plugintests.com/plugins/wporg/commonsbooking/php-badge.svg)](https://plugintests.com/plugins/wporg/commonsbooking/latest)
[![codecov](https://codecov.io/gh/wielebenwir/commonsbooking/branch/master/graph/badge.svg?token=STJC8WPWIC)](https://codecov.io/gh/wielebenwir/commonsbooking)
Expand All @@ -14,18 +15,115 @@ CommonsBooking is a plugin for the management and booking of common goods. This

## Links

* [Wordpress Plugin Page](https://wordpress.org/plugins/commonsbooking/)
* [WordPress Plugin Page](https://wordpress.org/plugins/commonsbooking/)
* [View Changelog](https://wordpress.org/plugins/commonsbooking/#developers)
* [Official Website](https://commonsbooking.org)
* For users get [Support](https://commonsbooking.org/kontakt/)
* For developers use the [Bug-Tracker](https://github.com/wielebenwir/commonsbooking/issues)

## Installation

## Development Installation
### Using The WordPress Dashboard

1. Navigate to the 'Add New' in the plugins dashboard
2. Search for 'commonsbooking'
3. Click 'Install Now'
4. Activate the plugin in the plugins dashboard


### Uploading in WordPress Dashboard

1. Navigate to the 'Add New' in the plugins dashboard
2. Navigate to the 'Upload' area
3. Select `commonsbooking.zip` from your computer
4. Click 'Install Now'
5. Activate the plugin in the plugins dashboard

### Using FTP

1. Download `commonsbooking.zip`
2. Extract the `commonsbooking` directory to your computer
3. Upload the `commonsbooking` directory to the `/wp-content/plugins/` directory
4. Activate the plugin in the plugins dashboard

### Using GitHub (developers only)

1. Make sure that composer is installed on your system
2. Navigate into your wp-content/plugins directory
3. Open a terminal and run `git clone https://github.com/wielebenwir/commonsbooking`
4. cd into the directory commonsbooking and run `composer install`
> This might fail, if you don't have the PHP extension [uopz](https://www.php.net/manual/en/book.uopz.php) installed. Try running `composer install --no-dev` if you just quickly want to test a specific branch without installing the extension.
5. Activate the plugin in the Plugin dashboard
5. Activate the plugin in the plugins dashboard

## Contribute

Either through translating WordPress into your native tongue ([see the already existing WordPress Plugin Translations](https://translate.wordpress.org/projects/wp-plugins/commonsbooking/)) or through developing and testing new versions of the application.

## Development

### Run plugin

First, we have to install the necessary dependencies and packages, we can do this by using the
```
npm run start
```
command.

The most easy way to start hacking WordPress plugins in general (if you have no other development environment set up) is using [wp-env](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/). Install it and it's dependencies (mainly Docker) and run this to start the enviroment:
```
npm run env:start
```
The provided `.wp-env.json` should be sufficient for normal development, for details see the [documentation of wp-env config](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/#wp-env-json). [You can create](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/#wp-env-override-json) a `.wp-env.override.json` for a custom configuration you don't want to check in.

For testing, you can activate the [kasimir theme](github.com/flegfleg/kasimir-theme) via [wp cli](https://make.wordpress.org/cli/handbook/) inside the wp-env docker container:
```
wp-env run cli wp theme activate kasimir-theme
```

### Test plugin

To test the code you first run the [preparation scripts](https://github.com/wp-cli/scaffold-command#wp-scaffold-plugin-tests) to load the wordpress core and configure database connection via `wp-config.php`. The following line can vary on your system, use the appropriate credentials, databse port and version of wordpress. The appropriate database port is printed out by `npm run env:start`:
```
bash bin/install-wp-tests.sh wordpress root password 127.0.0.1:49153 latest
```

Testing the plugin code via `phpunit`. At the moment it works only with a manually downloaded phar. We are using PHPUnit 9 and PHP7.4 for the automated tests. The tests might fail if you are using a different version.
```
php ~/phpunit.phar --bootstrap tests/bootstrap.php
```

E2E (end to end) tests are written in [cypress](https://www.cypress.io/). To run them you need to install cypress and start the wordpress environment:
```bash
npm run env:start
```
Now, install the test data needed for the tests:
```bash
npm run cypress:setup
```

Then you can run the tests:
```bash
npm run cypress:run
```
Or open Cypress using
```bash
npm run cypress:open
```

### Update translations

Currently, we only manage German and English translations as po files in the repository, so they are available at build time.
See the [WordPress plugin translation page](https://translate.wordpress.org/projects/wp-plugins/commonsbooking/) for other languages available at runtime.

Create a new .pot file using the
```
wp i18n make-pot . languages/commonsbooking.pot
```
command in the plugin directory. Make sure that all of your strings use the `__` function with the domain `commonsbooking`. Then you can use `poedit` to open the `commonsbooking-de_DE.po` and update the strings from the `pot` file.

### Build plugin zip
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hansmorb Also diese Stelle stimmt jetzt nicht mehr, das bin/build-zip.sh ist irgendwie rausgeflogen.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dann lass uns doch gerne zuerst die #1223 mergen und dann diesen Branch.


To create the plugin zip file for uploading to a development server:
```
bin/build-zip.sh
```
15 changes: 15 additions & 0 deletions bin/install-wp-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# install-wp-cli.sh
#
# Felipe Elia <contato@felipeelia.com.br> and 10up contributors
#
# The following code is a derivative work of the code from the ElasticPress project,
# which is licensed GPLv2. This code therefore is also licensed under the terms
# of the GNU Public License, version 2.'

#!/usr/bin/env bash

echo "Installing WP-CLI in $1"

./bin/wp-env-cli $1 curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
./bin/wp-env-cli $1 chmod +x wp-cli.phar
./bin/wp-env-cli $1 mv wp-cli.phar /usr/local/bin/wp
13 changes: 13 additions & 0 deletions bin/setup-cypress-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# setup-cypress-env.sh
# Felipe Elia <contato@felipeelia.com.br> and 10up contributors
#
# The following code is a derivative work of the code from the ElasticPress project,
# which is licensed GPLv2. This code therefore is also licensed under the terms
# of the GNU Public License, version 2.'

#!/bin/bash

# Install our example posts from a WP export file
./bin/wp-env-cli tests-wordpress "wp --allow-root import /var/www/html/wp-content/plugins/commonsbooking/tests/cypress/wordpress-files/content-example.xml --authors=create"
# Create subscriber with username "subscriber" and password "password"
./bin/wp-env-cli tests-wordpress "wp --allow-root user create subscriber sub@sub.de --role=subscriber --user_pass=password"
52 changes: 52 additions & 0 deletions bin/wp-env-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env node

const path = require('path');
const { spawn } = require('child_process');
const { readConfig } = require('@wordpress/env/lib/config');

function spawnCommandDirectly({ container, command, dockerComposeConfigPath }) {
const composeCommand = [
'-f',
dockerComposeConfigPath,
'exec -T',
container,
...command.split(' '), // The command will fail if passed as a complete string.
];

return new Promise((resolve, reject) => {
const childProc = spawn('docker-compose', composeCommand, {
stdio: 'inherit',
shell: true,
});
childProc.on('error', reject);
childProc.on('exit', (code) => {
// Code 130 is set if the user tries to exit with ctrl-c before using
// ctrl-d (so it is not an error which should fail the script.)
if (code === 0 || code === 130) {
resolve();
} else {
reject(code);
}
});
});
}

const run = async () => {
const configPath = path.resolve('.wp-env.json');
const { dockerComposeConfigPath } = await readConfig(configPath);

const container = process.argv[2];
const command = process.argv.splice(3).join(' ');

try {
await spawnCommandDirectly({
container,
command,
dockerComposeConfigPath,
});
} catch (errorCode) {
process.exit(errorCode);
}
};

run();
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"allow-plugins": {
"php-http/discovery": true
}
},
},
"autoload": {
"files": [
"includes/OptionsArray.php",
Expand All @@ -22,7 +22,7 @@
},
"autoload-dev": {
"psr-4": {
"CommonsBooking\\Tests\\": "tests/"
"CommonsBooking\\Tests\\": "tests/php/"
}
},
"repositories": [
Expand Down
Loading