This repo uses docker to run wordpress insance with phpunit inside. 2 main reasone to use this repo are:
- Run phpunit tests for our wordpress environment (can also be used without docker).
- Run a local instance of wordpress for development.
- Clone this repository
- Copy all the content to the root folder of the website (
wp-test-includesshould be a sibling ofwp-includes) - Modify the following values in wp-tests-config.php so that they are identical to the values in wp-config.php:
- DB_NAME
- DB_USER
- DB_PASSWORD
- DB_HOST
- For Windows only: add to the system PATH the following value:
c:\xampplite\php - In case you have the folder mu-plugins under wp-content, move all of its content to a different folder
- Open command line/terminal/bash. Go to the website root folder and run PHPUnit
- Clone this repository
- Run
docker-compose up -dfrom the folder you cloned the repo to - Run
docker-compose exec wordpress phpunit
-
Create a new directory that will contain the 3 repositories. In the next steps we will call this directory the root (e.g.
/home/projects/wordpress-dev) If you want to change the structure of the directories, make sure to map the paths inknowledgebase-tests/docker-compose.override.yml -
Clone this repository under the root directory (i.e.
_root_/knowledgebase-tests) -
Login to Soluto's dockerhub using
docker login -
Clone the theme repository under the root folder (i.e.
_root_/knowledgebase-wordpress-theme) -
Create a folder named
wordpress-docker-dataunder the root folder
This folder will function as a "view" to the wordpress folder in the container. You will be able to edit and open wp files from it (for ex the debug file) -
Install and run composer:
- MacOS/Linux:
- Go to the themes folder
- Make sure php is installed. If not, run:
curl -s http://php-osx.liip.ch/install.sh | bash -s 7.2 wget https://getcomposer.org/composer.pharorcurl -O https://getcomposer.org/composer.pharphp composer.phar install
- On windows you can install composer globally and run
composer installfrom the theme's folder
- MacOS/Linux:
-
Run
npm installform the theme's folder- If you don't have composer globally installed, you will get
sh: composer: command not found. Just runphp composer.phar installagain from the previous step.
- If you don't have composer globally installed, you will get
-
Run
gulp buildfrom the theme's folder- If you don't have gulp globally installed, run
node node_modules/gulp-cli/bin/gulp.js build
- If you don't have gulp globally installed, run
-
Clone the plugin repository under the root folder (i.e.
_root_/knowledgebase-plugins) -
Run
docker-compose up -dfrom_root_/knowledgebase-tests- For Windows Only:
- On the first run of docker-compose, you should get a pop-up asking permissions to share drive C:. If it doesn't show, rerun docker-compose.
- Then, you'll get another pop-up window where you need to type your local credentials (your Soluto username and password)
- For Windows Only:
-
You are done! - you can now open http://localhost:8000/ to configure your wordpress instance.
-
Activate our theme:
- Click Appearance -> Themes
- Click Activate on "Empty Theme"
-
Copy from production the relevant plugins:
- Advanced Custom Fields Pro
- CPT UI
- << OTHERS? >>
You can download the plugins with sftp from WP Engine (
kbsolutonew-youyousername@kbsolutonew.sftp.wpengine.com:2222/wp-content/plugins). You will need to create staging/production users from the WP Engine website.
-
Activate the desired plugins
-
Import post status definitions from production:
- In https://kb.mysoluto.com/wp-admin: Custom Fields -> Tools -> Toggle All -> Download Export File
- In https://localhost:8000/wp-admin: Custom Fields -> Tools -> Choose File -> Import
-
Import CPT UI definitions from prod/staging
-
Import Menu Editor Pro definitions from prod/staging (important: click Save Changes after import)
-
Import Symptoms Library: Tools -> Export -> Symptoms Library -> click Download Export File, and then Import in the local env
-
To enable Languages, and generation of Topic IDs:
-
Go to Languages -> Languages, and verify the English is the default language (marked with a star on the languages table)
-
Go to Languages -> Settings -> Custom post types and Taxonomies -> Settings, and check all post types except:
Alerts,Multi Article | StepsandSymptoms Library. Then, click "Save Changes"
- Change permalink settings as follows:
-
Go to Settings -> Permalinks
-
Choose
Custom Structureand in the text box fill in/%post_id%. -
Save changes
- To enable debug logs:
- Go to the
wordpress-docker-datafolder and openwp-config.phpfor editing - Replace
withdefine('WP_DEBUG', false);
define('WP_DEBUG', true); define('WP_DEBUG_DISPLAY', true ); define('WP_DEBUG_LOG', true );
- Go to the
- Add appropriate subfolder to
/path/to/website/wp-content/themes/empty-theme/tests.
- Path should reflect the structure of the tested code. e.g. the test functions of
empty-theme/components/feedbackwill be placed underempty-theme/tests/components/feedback
- File name should start with "test-" and end with ".php".
- Copy structure and use example from
/path/to/website/wp-content/themes/empty-theme/tests/components/some_component/test-some-component.php
Q: Why does my wp-json endpint does not work
A: According to this you need to enable pretty permalinks so the wp-json endpoint will work.
Just go to the permalink in the settings, Select the 'Custom Structure' and put '/%post_id%'