Skip to content

Commit cc00a4a

Browse files
author
Edwin Siebel
committed
Add: OpenPub base
1 parent fb833a8 commit cc00a4a

File tree

69 files changed

+7546
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+7546
-0
lines changed

.gitignore

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# -----------------------------------------------------------------
2+
# .gitignore for WordPress
3+
# Bare Minimum Git
4+
# http://ironco.de/bare-minimum-git/
5+
# ver 20150227
6+
#
7+
# This file is tailored for a WordPress project
8+
# using the default directory structure
9+
#
10+
# This file specifies intentionally untracked files to ignore
11+
# http://git-scm.com/docs/gitignore
12+
#
13+
# NOTES:
14+
# The purpose of gitignore files is to ensure that certain files not
15+
# tracked by Git remain untracked.
16+
#
17+
# To ignore uncommitted changes in a file that is already tracked,
18+
# use `git update-index --assume-unchanged`.
19+
#
20+
# To stop tracking a file that is currently tracked,
21+
# use `git rm --cached`
22+
#
23+
# Change Log:
24+
# 20150227 Ignore hello.php plugin. props @damienfa
25+
# 20150227 Change theme ignore to wildcard twenty*. props @Z33
26+
# 20140606 Add .editorconfig as a tracked file
27+
# 20140404 Ignore database, compiled, and packaged files
28+
# 20140404 Header Information Updated
29+
# 20140402 Initially Published
30+
#
31+
# -----------------------------------------------------------------
32+
33+
# ignore all files starting with .
34+
.*
35+
36+
# track this file .gitignore (i.e. do NOT ignore it)
37+
!.gitignore
38+
39+
# Eslint
40+
!.eslintrc
41+
!.eslintignore
42+
43+
# track .editorconfig file (i.e. do NOT ignore it)
44+
!.editorconfig
45+
46+
# track readme.md in the root (i.e. do NOT ignore it)
47+
!readme.md
48+
49+
# ignore all files that start with ~
50+
~*
51+
52+
# ignore OS generated files
53+
ehthumbs.db
54+
Thumbs.db
55+
56+
# ignore Editor files
57+
*.sublime-project
58+
*.sublime-workspace
59+
*.komodoproject
60+
61+
# ignore log files and databases
62+
*.log
63+
*.sql
64+
*.sqlite
65+
66+
# ignore compiled files
67+
*.com
68+
*.class
69+
*.dll
70+
*.exe
71+
*.o
72+
*.so
73+
74+
# ignore packaged files
75+
*.7z
76+
*.dmg
77+
*.gz
78+
*.iso
79+
*.jar
80+
*.rar
81+
*.tar
82+
*.zip
83+
84+
# ignore node/grunt dependency directories
85+
node_modules/
86+
87+
# bower
88+
bower_components
89+
90+
code-coverage
91+
92+
# no map files
93+
*.map
94+
95+
vendor
96+
!/src/vendor
97+
98+
tests/coverage

autoloader.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace OWC\OpenPub\Base;
4+
5+
class Autoloader
6+
{
7+
8+
/**
9+
* Autoloader constructor.
10+
* PSR autoloader
11+
*/
12+
public function __construct()
13+
{
14+
spl_autoload_register(function ($className) {
15+
$baseDir = __DIR__.'/src/';
16+
$namespace = str_replace("\\", "/", __NAMESPACE__);
17+
$className = str_replace("\\", "/", $className);
18+
$class = $baseDir.(empty($namespace) ? "" : $namespace."/").$className.'.php';
19+
$class = str_replace('/OWC/OpenPub/Base/OWC/OpenPub/Base/', '/Base/', $class);
20+
if (file_exists($class)) {
21+
require_once($class);
22+
}
23+
});
24+
}
25+
}

bin/install-wp-tests.sh

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/usr/bin/env bash
2+
3+
if [ $# -lt 3 ]; then
4+
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
5+
exit 1
6+
fi
7+
8+
DB_NAME=$1
9+
DB_USER=$2
10+
DB_PASS=$3
11+
DB_HOST=${4-localhost}
12+
WP_VERSION=${5-latest}
13+
SKIP_DB_CREATE=${6-false}
14+
15+
WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
16+
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
17+
18+
download() {
19+
if [ `which curl` ]; then
20+
curl -s "$1" > "$2";
21+
elif [ `which wget` ]; then
22+
wget -nv -O "$2" "$1"
23+
fi
24+
}
25+
26+
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
27+
WP_TESTS_TAG="$WP_VERSION"
28+
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
29+
WP_TESTS_TAG="trunk"
30+
else
31+
# http serves a single offer, whereas https serves multiple. we only want one
32+
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
33+
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
34+
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
35+
if [[ -z "$LATEST_VERSION" ]]; then
36+
echo "Latest WordPress version could not be found"
37+
exit 1
38+
fi
39+
WP_TESTS_TAG="$LATEST_VERSION"
40+
fi
41+
42+
set -ex
43+
44+
install_wp() {
45+
46+
if [ -d $WP_CORE_DIR ]; then
47+
return;
48+
fi
49+
50+
mkdir -p $WP_CORE_DIR
51+
52+
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
53+
mkdir -p /tmp/wordpress-nightly
54+
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
55+
unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
56+
mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
57+
else
58+
if [ $WP_VERSION == 'latest' ]; then
59+
local ARCHIVE_NAME='latest'
60+
else
61+
local ARCHIVE_NAME="wordpress-$WP_VERSION"
62+
fi
63+
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
64+
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
65+
fi
66+
67+
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
68+
}
69+
70+
install_test_suite() {
71+
# portable in-place argument for both GNU sed and Mac OSX sed
72+
if [[ $(uname -s) == 'Darwin' ]]; then
73+
local ioption='-i .bak'
74+
else
75+
local ioption='-i'
76+
fi
77+
78+
# set up testing suite if it doesn't yet exist
79+
if [ ! -d $WP_TESTS_DIR ]; then
80+
# set up testing suite
81+
mkdir -p $WP_TESTS_DIR
82+
git clone --depth=50 --branch="${WP_TESTS_TAG}" https://github.com/WordPress/wordpress-develop ${WP_TESTS_DIR}_2
83+
mv ${WP_TESTS_DIR}_2/tests/phpunit/includes/ ${WP_TESTS_DIR}/includes
84+
mv ${WP_TESTS_DIR}_2/tests/phpunit/data/ ${WP_TESTS_DIR}/data
85+
rm -rf ${WP_TESTS_DIR}_2/
86+
fi
87+
88+
if [ ! -f wp-tests-config.php ]; then
89+
download https://develop.svn.wordpress.org/tags/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
90+
# remove all forward slashes in the end
91+
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
92+
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
93+
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
94+
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
95+
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
96+
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
97+
fi
98+
99+
}
100+
101+
install_db() {
102+
103+
if [ ${SKIP_DB_CREATE} = "true" ]; then
104+
return 0
105+
fi
106+
107+
# parse DB_HOST for port or socket references
108+
local PARTS=(${DB_HOST//\:/ })
109+
local DB_HOSTNAME=${PARTS[0]};
110+
local DB_SOCK_OR_PORT=${PARTS[1]};
111+
local EXTRA=""
112+
113+
if ! [ -z $DB_HOSTNAME ] ; then
114+
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
115+
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
116+
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
117+
EXTRA=" --socket=$DB_SOCK_OR_PORT"
118+
elif ! [ -z $DB_HOSTNAME ] ; then
119+
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
120+
fi
121+
fi
122+
123+
# create database
124+
if [ ! -d /var/lib/mysql/${DB_NAME} ] ; then
125+
mysqladmin create ${DB_NAME} --user="${DB_USER}" --password="${DB_PASS}"${EXTRA}
126+
fi
127+
}
128+
129+
install_wp
130+
install_test_suite
131+
install_db

bitbucket-pipelines.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
image: oktupol/bitbucket-pipelines-php71
2+
3+
pipelines:
4+
branches:
5+
master:
6+
- step:
7+
name: unit test
8+
caches:
9+
- composer
10+
- vendor-directory
11+
script:
12+
- composer install --no-interaction --no-progress --prefer-dist --ignore-platform-reqs
13+
- ./vendor/bin/phpunit --testsuite "OWC OpenPub Base Plugin Test Suite"
14+
15+
definitions:
16+
caches:
17+
vendor-directory: vendor

composer.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "plugin/openpub-base",
3+
"description": "OpenPub base plugin",
4+
"authors": [
5+
{
6+
"name": "Edwin Siebel",
7+
"email": "[email protected]",
8+
"homepage": "https://www.yarddigital.nl"
9+
}
10+
],
11+
"type": "wordpress-plugin",
12+
"require": {
13+
"php": ">=7.0"
14+
},
15+
"require-dev": {
16+
"mockery/mockery": "1.0.*",
17+
"phpunit/phpunit": "~6.0",
18+
"10up/wp_mock": "dev-master",
19+
"phpmd/phpmd": "@stable"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"OWC\\OpenPub\\Base\\": "./src/Base",
24+
"OWC\\OpenPub\\Base\\Tests\\": "./tests"
25+
}
26+
}
27+
}
28+

0 commit comments

Comments
 (0)