-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: change code structure, starts to add unit test (#41)
feat: adds uninstall feedback privacy policy info perf: refactor features into separate modules, allow module detaching perf: tag minimum php version to 5.4, fail safe if lower perf: group dashboard notifications under a notification manager which show one at a time build: adds phpunit test for all modules and test the sdk runtime for up to PHP 5.2 version build: adds semantic release support
- Loading branch information
Showing
64 changed files
with
14,136 additions
and
4,766 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,28 @@ | ||
.gitattributes export-ignore | ||
.gitignore export-ignore | ||
.travis.yml export-ignore | ||
phpcs.xml export-ignore | ||
README.md export-ignore | ||
Gruntfile.js export-ignore | ||
docker-compose.local.yml export-ignore | ||
.release.rc.json export-ignore | ||
.nvmrc export-ignore | ||
package.json export-ignore | ||
package-lock.json export-ignore | ||
phpcs.xml export-ignore | ||
phpunit.xml export-ignore | ||
README.md export-ignore | ||
tests export-ignore | ||
bin export-ignore | ||
README.md export-ignore | ||
# Set the default behavior for all files. | ||
* text=auto | ||
|
||
# Normalized and converts to | ||
# native line endings on checkout. | ||
*.php text | ||
|
||
# Convert to LF line endings on checkout. | ||
*.sh text eol=lf | ||
|
||
# Binary files. | ||
*.png binary | ||
*.jpg binary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea | ||
node_modules | ||
logs | ||
logs | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lts/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"plugins": [ | ||
"@semantic-release/commit-analyzer", | ||
[ | ||
"@semantic-release/release-notes-generator", | ||
{ | ||
"parserOpts": { | ||
"mergePattern": "^Merge pull request #(\\d+) from (.*)$", | ||
"mergeCorrespondence": [ | ||
"id", | ||
"source" | ||
] | ||
} | ||
} | ||
], | ||
[ | ||
"@semantic-release/changelog", | ||
{ | ||
"changelogFile": "CHANGELOG.md" | ||
} | ||
], | ||
[ | ||
"@semantic-release/exec", | ||
{ | ||
"prepareCmd": "grunt version::${nextRelease.version}" | ||
} | ||
], | ||
[ | ||
"@semantic-release/git", | ||
{ | ||
"assets": [ | ||
"CHANGELOG.md", | ||
"composer.json", | ||
"package-lock.json", | ||
"package.json", | ||
"load.php" | ||
] | ||
} | ||
], | ||
"@semantic-release/github" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,51 @@ | ||
language: php | ||
language: php | ||
dist: trusty | ||
env: | ||
- WP_VERSION=latest | ||
cache: | ||
directories: | ||
- $HOME/.composer/cache | ||
- $HOME/.npm | ||
jobs: | ||
include: | ||
- stage: test | ||
php: 7.0 | ||
name: "PHP Code sniffer lint." | ||
script: | ||
- composer install | ||
- composer run-script lint | ||
- php: 5.2 | ||
dist: precise | ||
script: | ||
- ./bin/run-unit-tests.sh | ||
- php: 5.3 | ||
dist: precise | ||
script: | ||
- ./bin/run-unit-tests.sh | ||
- php: 5.4 | ||
script: | ||
- ./bin/run-unit-tests.sh | ||
- php: 5.5 | ||
script: | ||
- ./bin/run-unit-tests.sh | ||
- php: 5.6 | ||
script: | ||
- ./bin/run-unit-tests.sh | ||
- php: 7.0 | ||
script: | ||
- ./bin/run-unit-tests.sh | ||
- php: 7.1 | ||
script: | ||
- ./bin/run-unit-tests.sh | ||
|
||
## PHP versions to test against | ||
php: | ||
- "7.1" | ||
- "7.0" | ||
- "5.6" | ||
- "5.5" | ||
- "5.4" | ||
- "5.3" | ||
sudo: false | ||
dist: precise | ||
install: | ||
- export WPCS=/tmp/wpcs/ | ||
- export PLUGIN_DIR=/tmp/plugin/ | ||
- export PATH="$HOME/.composer/vendor/bin:$PATH" | ||
- mkdir -p $PLUGIN_DIR | ||
- mkdir -p $WPCS | ||
- plugin_slug=$(basename $(pwd)) | ||
- cd .. | ||
- mv $plugin_slug $PLUGIN_DIR | ||
- cd $WPCS | ||
- composer global require "squizlabs/php_codesniffer=2.9.0" | ||
- mkdir wordpress-coding-standards && curl -L https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/archive/master.tar.gz | tar xz --strip-components=1 -C wordpress-coding-standards | ||
- phpenv rehash | ||
- phpcs --config-set installed_paths $WPCS/wordpress-coding-standards | ||
- phpenv rehash | ||
- cd $PLUGIN_DIR/$plugin_slug | ||
|
||
script: | ||
- find -L . -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l; | ||
- phpcs -p -s -v -n . --standard=phpcs.xml --extensions=php; | ||
- stage: deploy | ||
if: branch = master and type != "pull_request" | ||
before_install: | ||
- nvm install && nvm use | ||
- npm install npm -g | ||
script: | ||
- npm install || exit 1 | ||
- npm run semantic-release || exit 1 | ||
branches: | ||
only: | ||
- master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module.exports = function (grunt) { | ||
grunt.initConfig( | ||
{ | ||
version: { | ||
project: { | ||
src: [ | ||
'package.json' | ||
] | ||
}, | ||
composer: { | ||
src: [ | ||
'composer.json' | ||
] | ||
}, | ||
load_php: { | ||
options: { | ||
prefix: '\\.*themeisle_sdk_version\.*\\s=\.*\\s\'' | ||
}, | ||
src: [ | ||
'load.php' | ||
] | ||
}, | ||
}, | ||
} | ||
); | ||
grunt.loadNpmTasks( 'grunt-version' ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,32 @@ | ||
# themeisle-sdk | ||
ThemeIsle SDK library | ||
# Themeisle SDK | ||
|
||
ThemeIsle SDK used to register common features for products in the portfolio. | ||
|
||
Can be installed using composer: | ||
`composer require codeinwp/themeisle-sdk` | ||
and manually autoloading the load.php file in the composer.json file of your project: | ||
|
||
``` | ||
"autoload": { | ||
"files": [ | ||
"vendor/codeinwp/themeisle-sdk/load.php" | ||
] | ||
} | ||
``` | ||
|
||
|
||
### Features | ||
|
||
* Loads the most recent version of the library across all the products on the same wordpress instance. For instance if there is a theme which bundles v2.0.0 of the SDK and one plugin which bundles the v1.9.1, it will load on the most recent one, v2.0.0 for both products. | ||
* If there are two products using the same version, it will load the first one that register the SDK, unless it's explicitly overwritten. | ||
* Each functionality is bundled into modules, which are loaded based on the product type. Free/Pro, is available on wordpress or not. | ||
|
||
### How to register product | ||
|
||
* The library works out of the box by simply loading the autoloader into the plugin/theme files. | ||
* Some modules are loaded only if the product is not available on WordPress.org ( licenser/review ). You can define if the product is available on wordpress.org by adding this file header `WordPress Available: <yes|no>` where `<yes|no>` will be replaced with the proper status. | ||
* If the product requires is a premium one and requires a licesing mechanism, we can use `Requires License: <yes|no>` to specifically tell that the product requires license. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ $# -lt 3 ]; then | ||
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]" | ||
exit 1 | ||
fi | ||
|
||
DB_NAME=$1 | ||
DB_USER=$2 | ||
DB_PASS=$3 | ||
DB_HOST=${4-localhost} | ||
WP_VERSION=${5-latest} | ||
SKIP_DB_CREATE=${6-false} | ||
|
||
WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib} | ||
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/} | ||
|
||
command_exists() { | ||
type -t "$1" >/dev/null 2>&1 | ||
} | ||
download() { | ||
if command_exists "curl"; then | ||
curl -s -o "${2:--}" "$1" | ||
elif command_exists "wget"; then | ||
wget -nv -O "${2:--}" "$1" | ||
fi | ||
} | ||
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then | ||
WP_TESTS_TAG="tags/$WP_VERSION" | ||
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then | ||
WP_TESTS_TAG="trunk" | ||
else | ||
# http serves a single offer, whereas https serves multiple. we only want one | ||
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json | ||
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json | ||
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//') | ||
if [[ -z "$LATEST_VERSION" ]]; then | ||
echo "Latest WordPress version could not be found" | ||
exit 1 | ||
fi | ||
WP_TESTS_TAG="tags/$LATEST_VERSION" | ||
fi | ||
|
||
set -ex | ||
|
||
|
||
install_wp() { | ||
|
||
if [ -d $WP_CORE_DIR ]; then | ||
return; | ||
fi | ||
|
||
mkdir -p $WP_CORE_DIR | ||
|
||
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then | ||
mkdir -p /tmp/wordpress-nightly | ||
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip | ||
unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/ | ||
mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR | ||
else | ||
if [ $WP_VERSION == 'latest' ]; then | ||
local ARCHIVE_NAME='latest' | ||
else | ||
local ARCHIVE_NAME="wordpress-$WP_VERSION" | ||
fi | ||
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz | ||
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR | ||
fi | ||
|
||
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php | ||
} | ||
|
||
install_test_suite() { | ||
# portable in-place argument for both GNU sed and Mac OSX sed | ||
if [[ $(uname -s) == 'Darwin' ]]; then | ||
local ioption='-i .bak' | ||
else | ||
local ioption='-i' | ||
fi | ||
|
||
# set up testing suite if it doesn't yet exist | ||
if [ ! -d $WP_TESTS_DIR ]; then | ||
# set up testing suite | ||
mkdir -p $WP_TESTS_DIR | ||
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes | ||
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data | ||
fi | ||
|
||
if [ ! -f wp-tests-config.php ]; then | ||
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php | ||
# remove all forward slashes in the end | ||
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") | ||
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php | ||
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php | ||
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php | ||
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php | ||
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php | ||
fi | ||
|
||
} | ||
|
||
install_db() { | ||
|
||
if [ ${SKIP_DB_CREATE} = "true" ]; then | ||
return 0 | ||
fi | ||
|
||
# parse DB_HOST for port or socket references | ||
local PARTS=(${DB_HOST//\:/ }) | ||
local DB_HOSTNAME=${PARTS[0]}; | ||
local DB_SOCK_OR_PORT=${PARTS[1]}; | ||
local EXTRA="" | ||
|
||
if ! [ -z $DB_HOSTNAME ] ; then | ||
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then | ||
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" | ||
elif ! [ -z $DB_SOCK_OR_PORT ] ; then | ||
EXTRA=" --socket=$DB_SOCK_OR_PORT" | ||
elif ! [ -z $DB_HOSTNAME ] ; then | ||
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" | ||
fi | ||
fi | ||
|
||
# create database | ||
mysql --user="$DB_USER" --password="$DB_PASS"$EXTRA --execute "CREATE DATABASE IF NOT EXISTS $DB_NAME;" | ||
} | ||
|
||
install_wp | ||
install_test_suite | ||
install_db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
composer global require "phpunit/phpunit=4.8.*|5.7.*" | ||
bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION | ||
phpunit --version | ||
php -v | ||
phpunit || exit 1 | ||
WP_MULTISITE=1 phpunit || exit 1 |
Oops, something went wrong.