Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit d199fbe

Browse files
authored
Merge pull request #22 from spacedmonkey/v2
Menu and menu item endpoints.
2 parents b0cf078 + 670e451 commit d199fbe

16 files changed

+1416
-463
lines changed

.phpcs.xml.dist

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="WordPress Coding Standards based custom ruleset for your plugin">
3+
<description>Generally-applicable sniffs for WordPress plugins.</description>
4+
5+
<!-- What to scan -->
6+
<file>.</file>
7+
<exclude-pattern>/vendor/</exclude-pattern>
8+
<exclude-pattern>/node_modules/</exclude-pattern>
9+
<exclude-pattern>/tests/</exclude-pattern>
10+
<exclude-pattern>/lib/class-wp-rest-widgets-controller.php</exclude-pattern>
11+
12+
<!-- How to scan -->
13+
<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
14+
<!-- Annotated ruleset: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
15+
<arg value="sp"/> <!-- Show sniff and progress -->
16+
<arg name="basepath" value="./"/><!-- Strip the file paths down to the relevant bit -->
17+
<arg name="colors"/>
18+
<arg name="extensions" value="php"/>
19+
<arg name="parallel" value="8"/><!-- Enables parallel processing when available for faster results. -->
20+
21+
<!-- Rules: WordPress Coding Standards -->
22+
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards -->
23+
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties -->
24+
<config name="minimum_supported_wp_version" value="5.2"/>
25+
<rule ref="WordPress">
26+
</rule>
27+
<rule ref="WordPress.WhiteSpace.ControlStructureSpacing">
28+
<properties>
29+
<property name="blank_line_check" value="true"/>
30+
</properties>
31+
</rule>
32+
</ruleset>

.travis.yml

Lines changed: 44 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,60 @@
1-
# Travis CI Configuration File
1+
sudo: false
2+
dist: trusty
23

3-
# Tell Travis CI we're using PHP
44
language: php
55

6-
sudo: false
6+
notifications:
7+
email:
8+
on_success: never
9+
on_failure: change
710

8-
matrix:
9-
include:
10-
- php: 5.6
11-
env: WP_TRAVISCI=travis:phpunit WP_VERSION=nightly
12-
- php: 5.6
13-
env: WP_TRAVISCI=travis:phpunit WP_VERSION=latest
14-
- php: 5.6
15-
env: WP_TRAVISCI=travis:phpvalidate
16-
- php: 5.5
17-
env: WP_TRAVISCI=travis:phpunit WP_VERSION=nightly
18-
- php: 5.4
19-
env: WP_TRAVISCI=travis:phpunit WP_VERSION=nightly
20-
- php: 5.3
21-
env: WP_TRAVISCI=travis:phpunit WP_VERSION=nightly
22-
- php: 5.2
23-
env: WP_TRAVISCI=travis:phpunit WP_VERSION=nightly
24-
- php: hhvm
25-
env: WP_TRAVISCI=travis:phpunit WP_VERSION=nightly
26-
- php: 7.0
27-
env: WP_TRAVISCI=travis:phpunit WP_VERSION=nightly
28-
allow_failures:
29-
- php: hhvm
30-
fast_finish: true
11+
branches:
12+
only:
13+
- master
3114

3215
cache:
3316
directories:
34-
- vendor
35-
- $HOME/.composer/cache
36-
- node_modules
17+
- $HOME/.composer/cache
3718

38-
before_install:
39-
# set up WP install
40-
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
41-
# prepare for running the tests
42-
- cd $TRAVIS_BUILD_DIR
43-
- npm install -g npm
44-
- npm install -g grunt-cli
45-
- npm install
46-
- node --version
47-
- npm --version
48-
- grunt --version
19+
matrix:
20+
include:
21+
- php: 7.3
22+
env: WP_VERSION=latest
23+
- php: 7.2
24+
env: WP_VERSION=latest
25+
- php: 7.1
26+
env: WP_VERSION=latest
27+
- php: 7.0
28+
env: WP_VERSION=latest
29+
- php: 5.6
30+
env: WP_VERSION=latest
31+
- php: 5.6
32+
env: WP_VERSION=trunk
33+
- php: 5.6
34+
env: WP_TRAVISCI=phpcs
35+
dist: precise
4936

5037
before_script:
51-
# Setup Coveralls
38+
- export PATH="$HOME/.composer/vendor/bin:$PATH"
39+
- composer install
5240
- |
53-
if [[ "$WP_TRAVISCI" == "travis:phpvalidate" ]] ; then
54-
composer self-update
55-
composer install --no-interaction
41+
if [ -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ]; then
42+
phpenv config-rm xdebug.ini
43+
else
44+
echo "xdebug.ini does not exist"
5645
fi
57-
# Setup Coveralls
5846
- |
59-
if [[ "$WP_TRAVISCI" == "travis:codecoverage" ]] ; then
60-
composer self-update
61-
composer install --no-interaction
47+
if [[ ! -z "$WP_VERSION" ]] ; then
48+
bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
6249
fi
6350
6451
script:
65-
- grunt $WP_TRAVISCI
66-
67-
after_script:
68-
# Push coverage off to Codecov
69-
- |
70-
if [[ "$WP_TRAVISCI" == "travis:codecoverage" ]] ; then
71-
bash <(curl -s https://codecov.io/bash)
72-
fi
73-
74-
git:
75-
depth: 1
76-
77-
branches:
78-
only:
79-
- master
80-
- develop
81-
82-
notifications:
83-
email:
84-
on_success: never
85-
on_failure: change
52+
- |
53+
if [[ ! -z "$WP_VERSION" ]] ; then
54+
vendor/bin/phpunit
55+
WP_MULTISITE=1 vendor/bin/phpunit
56+
fi
57+
- |
58+
if [[ "$WP_TRAVISCI" == "phpcs" ]] ; then
59+
vendor/bin/phpcs
60+
fi

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@
22

33
Feature plugin for Nav Menus and Widgets Endpoints
44

5+
6+
Endpoints to define for menus:
7+
8+
```
9+
GET /menus
10+
POST /menus
11+
GET /menus/:id
12+
POST /menus/:id
13+
DELETE /menus/:id
14+
```
15+
16+
Endpoints to define for menu items:
17+
18+
```
19+
GET /menu-items
20+
POST /menu-items
21+
GET /menu-items/:id
22+
POST /menu-items/:id
23+
DELETE /menu-items/:id
24+
```
25+
526
Endpoints to define for widgets:
627

728
```
@@ -11,4 +32,4 @@ POST /widgets/:type
1132
GET /widget-types
1233
GET /widgets/:type/:number
1334
PUT /widgets/:type/:number
14-
```
35+
```

bin/install-wp-tests.sh

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
if [ $# -lt 3 ]; then
4-
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
4+
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
55
exit 1
66
fi
77

@@ -10,9 +10,12 @@ DB_USER=$2
1010
DB_PASS=$3
1111
DB_HOST=${4-localhost}
1212
WP_VERSION=${5-latest}
13+
SKIP_DB_CREATE=${6-false}
1314

14-
WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
15-
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
15+
TMPDIR=${TMPDIR-/tmp}
16+
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
17+
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
18+
WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/}
1619

1720
download() {
1821
if [ `which curl` ]; then
@@ -22,8 +25,19 @@ download() {
2225
fi
2326
}
2427

25-
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
26-
WP_TESTS_TAG="tags/$WP_VERSION"
28+
if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+\-(beta|RC)[0-9]+$ ]]; then
29+
WP_BRANCH=${WP_VERSION%\-*}
30+
WP_TESTS_TAG="branches/$WP_BRANCH"
31+
32+
elif [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then
33+
WP_TESTS_TAG="branches/$WP_VERSION"
34+
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
35+
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
36+
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
37+
WP_TESTS_TAG="tags/${WP_VERSION%??}"
38+
else
39+
WP_TESTS_TAG="tags/$WP_VERSION"
40+
fi
2741
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
2842
WP_TESTS_TAG="trunk"
2943
else
@@ -37,7 +51,6 @@ else
3751
fi
3852
WP_TESTS_TAG="tags/$LATEST_VERSION"
3953
fi
40-
4154
set -ex
4255

4356
install_wp() {
@@ -49,31 +62,43 @@ install_wp() {
4962
mkdir -p $WP_CORE_DIR
5063

5164
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
52-
mkdir -p /tmp/wordpress-nightly
53-
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
54-
unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
55-
mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
65+
mkdir -p $TMPDIR/wordpress-nightly
66+
download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR/wordpress-nightly/wordpress-nightly.zip
67+
unzip -q $TMPDIR/wordpress-nightly/wordpress-nightly.zip -d $TMPDIR/wordpress-nightly/
68+
mv $TMPDIR/wordpress-nightly/wordpress/* $WP_CORE_DIR
5669
else
5770
if [ $WP_VERSION == 'latest' ]; then
5871
local ARCHIVE_NAME='latest'
72+
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then
73+
# https serves multiple offers, whereas http serves single.
74+
download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json
75+
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
76+
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
77+
LATEST_VERSION=${WP_VERSION%??}
78+
else
79+
# otherwise, scan the releases and get the most up to date minor version of the major release
80+
local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'`
81+
LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1)
82+
fi
83+
if [[ -z "$LATEST_VERSION" ]]; then
84+
local ARCHIVE_NAME="wordpress-$WP_VERSION"
85+
else
86+
local ARCHIVE_NAME="wordpress-$LATEST_VERSION"
87+
fi
5988
else
6089
local ARCHIVE_NAME="wordpress-$WP_VERSION"
6190
fi
62-
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
63-
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
91+
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz
92+
tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR
6493
fi
6594

6695
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
6796
}
6897

69-
install_wp_api() {
70-
git clone https://github.com/WP-API/WP-API.git wp-api
71-
}
72-
7398
install_test_suite() {
7499
# portable in-place argument for both GNU sed and Mac OSX sed
75100
if [[ $(uname -s) == 'Darwin' ]]; then
76-
local ioption='-i .bak'
101+
local ioption='-i.bak'
77102
else
78103
local ioption='-i'
79104
fi
@@ -83,13 +108,14 @@ install_test_suite() {
83108
# set up testing suite
84109
mkdir -p $WP_TESTS_DIR
85110
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
111+
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
86112
fi
87113

88-
cd $WP_TESTS_DIR
89-
90114
if [ ! -f wp-tests-config.php ]; then
91115
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
92-
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" "$WP_TESTS_DIR"/wp-tests-config.php
116+
# remove all forward slashes in the end
117+
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
118+
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
93119
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
94120
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
95121
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
@@ -99,6 +125,11 @@ install_test_suite() {
99125
}
100126

101127
install_db() {
128+
129+
if [ ${SKIP_DB_CREATE} = "true" ]; then
130+
return 0
131+
fi
132+
102133
# parse DB_HOST for port or socket references
103134
local PARTS=(${DB_HOST//\:/ })
104135
local DB_HOSTNAME=${PARTS[0]};
@@ -120,6 +151,5 @@ install_db() {
120151
}
121152

122153
install_wp
123-
install_wp_api
124154
install_test_suite
125155
install_db

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
"composer/installers": "~1.0"
1919
},
2020
"require-dev": {
21-
"squizlabs/php_codesniffer": "2.3.4",
22-
"wp-coding-standards/wpcs": "0.8.0"
21+
"squizlabs/php_codesniffer": "^3.3.1",
22+
"wp-coding-standards/wpcs": "^2.1.1",
23+
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
24+
"phpcompatibility/phpcompatibility-wp": "^2.0",
25+
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
2326
},
2427
"extra": {
2528
"installer-name": "json-rest-api"

0 commit comments

Comments
 (0)