Skip to content

Commit

Permalink
Merge branch 'feature/2771' into feature/2766
Browse files Browse the repository at this point in the history
* feature/2771:
  markdown fix in testing docs #2771
  migrate in e2e tests #2771
  Setup test imports for e2e tests #2771
  setup unit tests seperate from WordPress 'unit' tests #2701
  cypress tests #2771
  cache dirs on travis #2771
  make phpunit integration tests run locally in container #2711
  docker install scripts #2771 added to bin
  #2771 delete old docker env

# Conflicts:
#	package-lock.json
  • Loading branch information
Josh Pollock committed Oct 18, 2018
2 parents 296e6bc + 9429337 commit a7f60d4
Show file tree
Hide file tree
Showing 627 changed files with 54,456 additions and 233 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ npm-debug.log
**/.DS_Store
includes/freemius/assets/img/caldera-forms.png
bin/caldera-forms

wordpress/*
wp-content/*
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ notifications:
on_failure: change


cache: false
cache:
directories:
- node_modules
- vendor

env:
- WP_VERSION=latest
Expand Down
26 changes: 0 additions & 26 deletions Dockerfile

This file was deleted.

46 changes: 37 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ This is the old stuff, built with grunt.
### Test Environment
All PHP tests are based off of the WordPress "unit" test suite, and therefore need a full WordPress test environment. The install script in '/bin' is pretty standard and should work with VVV or whatever.

Alternatively, because this, isn't 2014, you can use the provided Docker environment.
We provide a docker-based development environment. It is recommended that you use this environment because the setup is scripted and all of the tests can be run with it.

The local server is [http://localhost:8228](http://localhost:8228)


#### Requirements
* Docker
- [Installation documentation](https://docs.docker.com/install/)
Expand All @@ -69,18 +73,42 @@ Alternatively, because this, isn't 2014, you can use the provided Docker environ
* npm
- [Installation documentation](https://www.npmjs.com/get-npm)


#### Install Test Environment
* Make sure all dependencies are installed:
- `composer update && npm update`
* Install local development environment
- `composer wp:install
- Runs installer. Make sure Docker is running. May take awhile.
- `composer wp:activate`
- Activates Caldera Forms and Gutenberg and sets permalinks.
* Go to [http://localhost:8228](http://localhost:8228) and make sure you have a WordPress site and can login.
- Username: admin
- password: password

* Install the tests forms and pages for them.
- `composer wp:setup-tests`
- Adds forms needed for e2e tests and one page for each form. Useful for manual QA as well.

### Test Structures
* PHP tests go in /tests and are run using phpunit
* JavaScript tests go in clients/tests
- Unit tests go in clients/tests/unit and are run using [Jest](https://facebook.github.io/jest/docs/en/getting-started.html)
- Unit tests must have the word test in file name. For example, `formConfig.test.js`
- Integration tests, which require WordPress, are in tests. These used to be all the tests we have.
- Unit tests -- isolated tests that do NOT require WordPress -- go in `tests/Unit`.
- The trait `calderawp\calderaforms\Util\Traits` should have all of the factories used for integration and unit tests (aspirational.)
* JavaScript UNIT tests go in clients/tests
- Unit tests go in clients/tests/unit and are run using [Jest](https://facebook.github.io/jest/docs/en/getting-started.html)
- Unit tests must have the word test in file name. For example, `formConfig.test.js`
* End to end tests go in `cypress/integration` amd are written using [Cypress](https://cypress.io)
- See our [Cypress README for testing](./cypress/README.md)

#### Commands
* `composer wp-install` - Installs Docker-based test environment.
* `composer wp-start` - Starts Docker-based test environment.
* `composer wp-tests` - Runs phpunit inside of Docker container.
* `composer wp-stop` - Stops Docker-based test environment, without destroying containers.
* `composer wp-remove` - Stops Docker-based test environment and destroys containers.
* `composer wp:install` - Installs Docker-based test environment.
* `composer wp:start` - Starts Docker-based test environment.
* `composer wp:activate` - Activate plugins in Docker-based environment.
* `composer wp:tests` - Runs the PHP integration tests using phpunit inside Docker-based environment .
* `composer wp:stop` - Stops Docker-based test environment, without destroying containers.
* `composer wp:destroy` - Removes (including the database) the test environment and destroys containers.
* `composer wp:setup-tests` - Adds test forms and puts them on pages.
* `npm test` - Run JavaScript test watcher
* `npm run test:once` - Run JavaScript unit tests once

Expand Down
16 changes: 16 additions & 0 deletions bin/activate-plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
docker-compose run --rm cli wp plugin activate caldera-forms
docker-compose run --rm cli wp plugin activate gutenberg
exit 0;
# Install test form importer/Ghost Inspector runner
docker-compose run --rm cli wp plugin activate ghost-runner/plugin
cd wp-content/plugins/ghost-runner
if [ ! -d wp-content/plugins/ghost-runner/vendor ]
then
composer install
fi

if [ -d wp-content/plugins/ghost-runner/vendor ]
then
composer update --no-dev
fi
71 changes: 71 additions & 0 deletions bin/install-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash

#Set WordPress version
WP_VERSION=${1-latest}

# Exit if any command fails
set -e

# Include useful functions
. "$(dirname "$0")/includes.sh"

# Check that Docker is installed
if ! command_exists "docker"; then
echo -e $(error_message "Docker doesn't seem to be installed. Please head on over to the Docker site to download it: $(action_format "https://www.docker.com/community-edition#/download")")
exit 1
fi

# Check that Docker is running
if ! docker info >/dev/null 2>&1; then
echo -e $(error_message "Docker isn't running. Please check that you've started your Docker app, and see it in your system tray.")
exit 1
fi

# Stop existing containers
echo -e $(status_message "Stopping Docker containers...")
docker-compose down --remove-orphans >/dev/null 2>&1

# Download image updates
echo -e $(status_message "Downloading Docker image updates...")
docker-compose pull --parallel

# Launch the containers
echo -e $(status_message "Starting Docker containers...")
docker-compose up -d >/dev/null

HOST_PORT=$(docker-compose port wordpress 80 | awk -F : '{printf $2}')

# Wait until the docker containers are setup properely
echo -en $(status_message "Attempting to connect to wordpress...")
until $(curl -L http://localhost:$HOST_PORT -so - 2>&1 | grep -q "WordPress"); do
echo -n '.'
sleep 3
done
echo ''

# Install WordPress
echo -e $(status_message "Installing WordPress...")
docker-compose run --rm -u 33 cli core install --url=localhost:$HOST_PORT --title=TestSite --admin_user=admin --admin_password=password [email protected] >/dev/null
# Check for WordPress updates, just in case the WordPress image isn't up to date.
docker-compose run --rm -u 33 cli core update >/dev/null

# If the 'wordpress' volume wasn't during the down/up earlier, but the post port has changed, we need to update it.
CURRENT_URL=$(docker-compose run -T --rm cli option get siteurl)
if [ "$CURRENT_URL" != "http://localhost:$HOST_PORT" ]; then
docker-compose run --rm cli option update home "http://localhost:$HOST_PORT" >/dev/null
docker-compose run --rm cli option update siteurl "http://localhost:$HOST_PORT" >/dev/null
fi
echo -e $(status_message "Server is running at:")
echo -e $(status_message "http://localhost:$HOST_PORT")

# Install Composer
echo -e $(status_message "Installing and updating Composer modules...")
docker-compose run --rm composer install

# Install the PHPUnit test scaffolding
echo -e $(status_message "Installing PHPUnit test scaffolding...")
docker-compose run --rm wordpress_phpunit /app/bin/install-wp-tests.sh wordpress_test root example mysql "${WP_VERSION}" false >/dev/null
echo -e $(status_message "Completed installing tests")



3 changes: 3 additions & 0 deletions bin/setup-test-forms.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
docker-compose run --rm cli wp cf import-test-forms
docker-compose run --rm cli wp cf create-test-pages
58 changes: 1 addition & 57 deletions caldera-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,76 +119,20 @@ function caldera_forms_load()
* @since 1.3.5.3
*/
do_action('caldera_forms_includes_complete');
caldera_forms_freemius()->add_filter('plugin_icon', 'caldera_forms_freemius_icon_path');
}

add_action('plugins_loaded', array('Caldera_Forms', 'get_instance'));
add_action('plugins_loaded', array('Caldera_Forms_Tracking', 'get_instance'));


// Admin & Admin Ajax stuff.
// Admin & Admin Ajax stuff.
if (is_admin() || defined('DOING_AJAX')) {
add_action('plugins_loaded', array('Caldera_Forms_Admin', 'get_instance'));
add_action('plugins_loaded', array('Caldera_Forms_Support', 'get_instance'));
include_once CFCORE_PATH . 'includes/plugin-page-banner.php';
}


/**
* Get the Caldera Forms Freemius instance
*
* @since 1.6.0
*
* @return Freemius
* @throws Freemius_Exception
*/
function caldera_forms_freemius()
{
global $caldera_forms_freemius;
if (!isset($caldera_forms_freemius)) {
// Include Freemius SDK.
require_once CFCORE_PATH . 'includes/freemius/start.php';
$caldera_forms_freemius = fs_dynamic_init(array(
'id' => '1767',
'slug' => 'caldera-forms',
'type' => 'plugin',
'public_key' => 'pk_d8e6325777a98c1b3e0d8cdbfad1e',
'is_premium' => false,
'has_addons' => false,
'has_paid_plans' => false,
'menu' => array(
'slug' => 'caldera-forms',
'account' => false,
'support' => false,
'contact' => false,
),
));
/**
* Runs after Freemius loads
*
* @since 1.6.0
*
* @param Freemius $caldera_forms_freemius
*/
do_action('caldera_forms_freemius_init', $caldera_forms_freemius);
}
return $caldera_forms_freemius;
}

//Load freemius
caldera_forms_freemius();

/**
* Get the path for the icon used by Caldera Forms
*
* @since 1.6.0
*
* @return string
*/
function caldera_forms_freemius_icon_path()
{
return CFCORE_PATH . 'assets/build/images/new-icon.png';
}

}

Expand Down
48 changes: 39 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,58 @@
"role": "Contributing Developer"
}
],
"repositories": [
{
"type": "git",
"url": "https://github.com/CalderaWP/caldera-interop"
},
{
"type": "git",
"url": "https://github.com/CalderaWP/caldera-ghost-runner"
},
{
"type":"composer",
"url":"https://wpackagist.org"
}
],
"homepage": "http://calderaforms.com",
"require": {
"php": ">=5.6.0",
"inpsyde/wonolog": "^1.0",
"calderawp/caldera-forms-query" : "dev-master",
"calderawp/caldera-containers": "^0.2.0"
"calderawp/caldera-containers": "^0.2.0",
"composer/installers": "^1.6"
},
"autoload": {
"psr-4": {
"calderawp\\calderaforms\\pro\\": "includes/cf-pro-client/classes/"
}
},
"autoload-dev": {
"psr-4": {
"calderawp\\calderaforms\\Tests\\Unit\\": "tests/Unit/",
"calderawp\\calderaforms\\Tests\\Util\\": "tests/Util/",
"calderawp\\calderaforms\\Tests\\Util\\Traits\\": "tests/Util/Traits/"
},
"files" : [
"./tests/testing-cli.php"
]
},
"require-dev": {
"phpunit/phpunit":"~5.5.0"
"phpunit/phpunit":"~5.5.0",
"wpackagist-plugin/gutenberg":"*",
"johnpbloch/wordpress" : "*",
"brain/monkey": "^2.2",
"mockery/mockery": ">=0.9 <2"
},
"scripts" : {
"wp-install" : "docker-compose up --build -d",
"wp-tests" : "composer wp-install && composer wp-unit-test",
"wp-unit-test" : "docker-compose run wordpress vendor/bin/phpunit",
"wp-start" : "docker-compose up",
"wp-stop" : "docker-compose stop",
"wp-remove": "docker-compose down"

"wp:install": "bash ./bin/install-docker.sh && composer wp:config",
"wp:activate": "bash ./bin/activate-plugin.sh",
"wp:setup-tests": "bash ./bin/setup-test-forms.sh",
"wp:config": "docker-compose run --rm cli wp rewrite structure '/%postname%/'",
"wp:start": "docker-compose up -d",
"wp:tests": "docker-compose run --rm wordpress_phpunit phpunit --configuration phpunit-integration.xml.dist",
"wp:destroy": "docker-compose rm --stop --force",
"test:unit": "phpunit --configuration phpunit-unit.xml.dist"
}
}
Loading

0 comments on commit a7f60d4

Please sign in to comment.