Skip to content

Commit 3eeb3cb

Browse files
authored
Merge pull request #151 from contactashish13/issue-142
phpunit more tests #142
2 parents 1cb2994 + 07a37a9 commit 3eeb3cb

File tree

14 files changed

+442
-152
lines changed

14 files changed

+442
-152
lines changed

.travis.yml

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
language: php
2-
3-
## PHP versions to test against
42
php:
53
- "7.0"
64
- "5.6"
@@ -9,27 +7,58 @@ php:
97
- "5.3"
108
- "5.2"
119
sudo: false
10+
branches:
11+
except:
12+
- "/^*-v[0-9]/"
1213
env:
13-
- WP_VERSION=latest WP_MULTISITE=0
14+
matrix:
15+
- WP_VERSION=latest WP_MULTISITE=0
16+
global:
17+
- MASTER_BRANCH=production UPSTREAM_REPO=Codeinwp/visualizer STORE_URL=https://themeisle.com
1418
install:
15-
- . $HOME/.nvm/nvm.sh
16-
- nvm install stable
17-
- nvm use stable
18-
- npm install
19-
- npm install grunt-cli -g
20-
## install PHPCS and Wordpress standards
21-
- pear install pear/PHP_CodeSniffer
22-
- mkdir $TRAVIS_BUILD_DIR/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
23-
- phpenv rehash
24-
- phpcs --config-set installed_paths $TRAVIS_BUILD_DIR/wordpress-coding-standards
25-
- phpenv rehash
26-
before_script:
27-
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
28-
- export PATH="$HOME/.composer/vendor/bin:$PATH"
29-
- |
30-
if [[ ${TRAVIS_PHP_VERSION:0:2} == "7." ]]; then
31-
composer global require "phpunit/phpunit=5.7.*"
32-
fi
33-
- phpenv rehash
19+
- chmod +x bin/install-dependencies.sh
20+
- ". ./bin/install-dependencies.sh"
3421
script:
35-
grunt travis
22+
- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then grunt travis; fi;
23+
before_deploy:
24+
- chmod +x bin/prepare-deploy.sh
25+
- ". ./bin/prepare-deploy.sh"
26+
deploy:
27+
- provider: s3
28+
access_key_id: "$AWS_ACCESS_KEY"
29+
secret_access_key: "$AWS_SECRET_KEY"
30+
bucket: "$AWS_BUCKET"
31+
skip_cleanup: true
32+
acl: public_read
33+
overwrite: true
34+
local-dir: artifact/
35+
upload-dir: "$AWS_PRODUCTS_FOLDER/$THEMEISLE_REPO/latest"
36+
on:
37+
branch: "$MASTER_BRANCH"
38+
repo: "$UPSTREAM_REPO"
39+
condition: $TRAVIS_PHP_VERSION = "7.0"
40+
- provider: s3
41+
access_key_id: "$AWS_ACCESS_KEY"
42+
secret_access_key: "$AWS_SECRET_KEY"
43+
bucket: "$AWS_BUCKET"
44+
skip_cleanup: true
45+
acl: public_read
46+
overwrite: true
47+
local-dir: artifact/
48+
upload-dir: "$AWS_PRODUCTS_FOLDER/$THEMEISLE_REPO/$THEMEISLE_VERSION"
49+
on:
50+
repo: "$UPSTREAM_REPO"
51+
branch: "$MASTER_BRANCH"
52+
condition: $TRAVIS_PHP_VERSION = "7.0"
53+
- provider: releases
54+
api_key: "$GITHUB_TOKEN"
55+
file: artifact/$THEMEISLE_REPO.zip
56+
skip_cleanup: true
57+
on:
58+
tags: false
59+
repo: "$UPSTREAM_REPO"
60+
branch: "$MASTER_BRANCH"
61+
condition: $TRAVIS_PHP_VERSION = "7.0"
62+
after_deploy:
63+
- chmod +x bin/deploy.sh
64+
- ". ./bin/deploy.sh"

bin/deploy.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
# We run this just one time, for a first job from the buid and just at once after_deploy hook.
4+
if ! [ $AFTER_DEPLOY_RUN ] && [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then
5+
6+
# Flag the run in order to not be trigged again on the next after_deploy.
7+
export AFTER_DEPLOY_RUN=1;
8+
echo " Started deploy script. ";
9+
10+
# Setup git username and email.
11+
12+
git config user.name "selul"
13+
git config user.email ${GITHUB_EMAIL}
14+
15+
# Send changelog changes to git.
16+
git checkout $MASTER_BRANCH
17+
git add -v .
18+
19+
# We use [skip ci] in message to prevent this commit to trigger the build.
20+
git commit -a -m "[AUTO][skip ci] Updating changelog for v"$THEMEISLE_VERSION
21+
git push --quiet "https://${GITHUB_TOKEN}@github.com/$UPSTREAM_REPO.git" HEAD:$MASTER_BRANCH
22+
23+
# Tag the new release.
24+
git tag -a "v$THEMEISLE_VERSION" -m "[AUTO] Release of $THEMEISLE_VERSION ";
25+
git push --quiet "https://${GITHUB_TOKEN}@github.com/$UPSTREAM_REPO.git" --tags ;
26+
sleep 5;
27+
28+
# Sends the api call for creating the release.
29+
# We use this as the travis release provider does not offer any way
30+
# to set the body of the release.
31+
API_JSON='{"tag_name": "v'$THEMEISLE_VERSION'","target_commitish": "'$MASTER_BRANCH'","name": "v'$THEMEISLE_VERSION'","body": "'$CHANGES'","draft": false,"prerelease": false}';
32+
curl -s --data "$API_JSON" "https://api.github.com/repos/$UPSTREAM_REPO/releases?access_token="$GITHUB_TOKEN > /dev/null;
33+
34+
# Send update to the store
35+
STORE_JSON='{"version": "'$THEMEISLE_VERSION'","id": "'$THEMEISLE_ID'","body": "'$CHANGES'"}';
36+
curl -s -H "Content-Type: application/json" -H "x-themeisle-auth: $THEMEISLE_AUTH" --data "$STORE_JSON" "$STORE_URL/wp-json/ti-endpoint/v1/update_changelog_new/" > /dev/null
37+
38+
# Send data to demo server.
39+
grunt sftp
40+
fi;

bin/install-dependencies.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
# We run this on PR or on push to MASTER_BRANCH.
4+
if [ "$TRAVIS_PULL_REQUEST" != "false" ] || ( [ "$TRAVIS_EVENT_TYPE" == "push" ] && [ "$TRAVIS_REPO_SLUG" == "$UPSTREAM_REPO" ] && [ "$TRAVIS_BRANCH" == "$MASTER_BRANCH" ] ) ; then
5+
6+
. $HOME/.nvm/nvm.sh
7+
nvm install stable
8+
nvm use stable
9+
10+
npm install
11+
npm install grunt-cli -g
12+
13+
phpenv local 5.6
14+
15+
composer selfupdate 1.0.0 --no-interaction
16+
composer install --no-interaction
17+
phpenv local --unset
18+
19+
fi;
20+
# We dont install PHPCS if is not a PR.
21+
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
22+
23+
# Install PHPCS.
24+
pear install pear/PHP_CodeSniffer
25+
26+
# Install WPCS standards.
27+
git clone -b master --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git $HOME/wordpress-coding-standards
28+
phpenv rehash
29+
phpcs --config-set installed_paths $HOME/wordpress-coding-standards
30+
phpenv rehash
31+
32+
# Install wordpress for testing.
33+
bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
34+
export PATH="$HOME/.composer/vendor/bin:$PATH"
35+
36+
# Use phpunit 5.7 as WP dont support 6.
37+
if [[ ${TRAVIS_PHP_VERSION:0:2} == "7." ]]; then
38+
composer global require "phpunit/phpunit=5.7.*" ;
39+
fi;
40+
fi;

bin/prepare-deploy.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
#We make sure we run this just at one before_deploy hook.
4+
if ! [ $BEFORE_DEPLOY_RUN ] && [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then
5+
6+
echo " Preparing deploy. ";
7+
8+
# Flag the run.
9+
export BEFORE_DEPLOY_RUN=1;
10+
11+
# Parse the name of the repo.
12+
export THEMEISLE_REPO=$(node -pe "require('./package.json').name")
13+
14+
# Parse the version of the product.
15+
16+
export THEMEISLE_VERSION=$(node -pe "require('./package.json').version")
17+
18+
# Parse product category.
19+
export THEMEISLE_CATEGORY=$(node -pe "require('./package.json').category")
20+
21+
export DEMO_THEMEISLE_PATH="/sites/demo.themeisle.com/wp-content/$THEMEISLE_CATEGORY/$THEMEISLE_REPO";
22+
23+
# Build changelog based on commit message description.
24+
CHANGELOG="\n ### v$THEMEISLE_VERSION - "$(date +'%Y-%m-%d')" \n **Changes:** \n";
25+
26+
# Remove first line from the commit as is it used as commit title.
27+
NORMALIZED_MESSAGE=$(sed "1d" <<< "$TRAVIS_COMMIT_MESSAGE");
28+
29+
# Save changes list in a sepparately variable as we use it in the release body.
30+
export CHANGES="";
31+
while read -r line; do
32+
if ! [ -z $line ]; then
33+
line=$(echo "${line//[$'\r\n']}");
34+
export CHANGES=$CHANGES'- '$line'\n';
35+
fi;
36+
done <<< "$NORMALIZED_MESSAGE"
37+
38+
# Concat changes and changelog title and prepend to the changelog file.
39+
40+
CHANGELOG="$CHANGELOG $CHANGES";
41+
echo -e "$CHANGELOG $(cat CHANGELOG.md)" > CHANGELOG.md
42+
43+
# Run the prepare deployment action
44+
45+
grunt deploy
46+
fi;

classes/Visualizer/Module/Admin.php

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,55 @@ public function setupMediaViewStrings( $strings ) {
135135
*/
136136
public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darray = false ) {
137137
$types = array(
138-
'pie' => array( 'name' => esc_html__( 'Pie', 'visualizer' ), 'enabled' => true ),
139-
'line' => array( 'name' => esc_html__( 'Line', 'visualizer' ), 'enabled' => true ),
140-
'area' => array( 'name' => esc_html__( 'Area', 'visualizer' ), 'enabled' => true ),
141-
'geo' => array( 'name' => esc_html__( 'Geo', 'visualizer' ), 'enabled' => true ),
142-
'bar' => array( 'name' => esc_html__( 'Bar', 'visualizer' ), 'enabled' => true ),
143-
'column' => array( 'name' => esc_html__( 'Column', 'visualizer' ), 'enabled' => true ),
144-
'gauge' => array( 'name' => esc_html__( 'Gauge', 'visualizer' ), 'enabled' => true ),
145-
'scatter' => array( 'name' => esc_html__( 'Scatter', 'visualizer' ), 'enabled' => true ),
146-
'candlestick' => array( 'name' => esc_html__( 'Candlestick', 'visualizer' ), 'enabled' => true ),
138+
'pie' => array(
139+
'name' => esc_html__( 'Pie', 'visualizer' ),
140+
'enabled' => true,
141+
),
142+
'line' => array(
143+
'name' => esc_html__( 'Line', 'visualizer' ),
144+
'enabled' => true,
145+
),
146+
'area' => array(
147+
'name' => esc_html__( 'Area', 'visualizer' ),
148+
'enabled' => true,
149+
),
150+
'geo' => array(
151+
'name' => esc_html__( 'Geo', 'visualizer' ),
152+
'enabled' => true,
153+
),
154+
'bar' => array(
155+
'name' => esc_html__( 'Bar', 'visualizer' ),
156+
'enabled' => true,
157+
),
158+
'column' => array(
159+
'name' => esc_html__( 'Column', 'visualizer' ),
160+
'enabled' => true,
161+
),
162+
'gauge' => array(
163+
'name' => esc_html__( 'Gauge', 'visualizer' ),
164+
'enabled' => true,
165+
),
166+
'scatter' => array(
167+
'name' => esc_html__( 'Scatter', 'visualizer' ),
168+
'enabled' => true,
169+
),
170+
'candlestick' => array(
171+
'name' => esc_html__( 'Candlestick', 'visualizer' ),
172+
'enabled' => true,
173+
),
147174
// pro types
148-
'table' => array( 'name' => esc_html__( 'Table', 'visualizer' ), 'enabled' => false ),
149-
'timeline' => array( 'name' => esc_html__( 'Timeline', 'visualizer' ), 'enabled' => false ),
150-
'combo' => array( 'name' => esc_html__( 'Combo', 'visualizer' ), 'enabled' => false ),
175+
'table' => array(
176+
'name' => esc_html__( 'Table', 'visualizer' ),
177+
'enabled' => false,
178+
),
179+
'timeline' => array(
180+
'name' => esc_html__( 'Timeline', 'visualizer' ),
181+
'enabled' => false,
182+
),
183+
'combo' => array(
184+
'name' => esc_html__( 'Combo', 'visualizer' ),
185+
'enabled' => false,
186+
),
151187
);
152188

153189
$types = apply_filters( 'visualizer_pro_chart_types', $types );

classes/Visualizer/Module/Chart.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ public function deleteChart() {
171171
$nonce = wp_verify_nonce( filter_input( $input_method, 'nonce' ) );
172172
$capable = current_user_can( 'delete_posts' );
173173
if ( $nonce && $capable ) {
174-
$chart_id = filter_input( $input_method, 'chart', FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1 ) ) );
174+
$chart_id = filter_input( $input_method, 'chart', FILTER_VALIDATE_INT, array(
175+
'options' => array(
176+
'min_range' => 1,
177+
),
178+
) );
175179
if ( $chart_id ) {
176180
$chart = get_post( $chart_id );
177181
$success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
@@ -183,7 +187,9 @@ public function deleteChart() {
183187
}
184188

185189
if ( $is_post ) {
186-
self::_sendResponse( array( 'success' => $success ) );
190+
self::_sendResponse( array(
191+
'success' => $success,
192+
) );
187193
}
188194

189195
wp_redirect( wp_get_referer() );
@@ -222,11 +228,13 @@ public function renderChartPages() {
222228
add_post_meta( $chart_id, Visualizer_Plugin::CF_DEFAULT_DATA, 1 );
223229
add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
224230
add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
225-
add_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, array( 'focusTarget' => 'datum' ) );
231+
add_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, array(
232+
'focusTarget' => 'datum',
233+
) );
226234
}
227235

228236
wp_redirect( add_query_arg( 'chart', (int) $chart_id ) );
229-
wp_die();
237+
defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
230238
}
231239

232240
// enqueue and register scripts and styles
@@ -497,7 +505,11 @@ public function cloneChart() {
497505
$nonce = wp_verify_nonce( filter_input( INPUT_GET, 'nonce' ), Visualizer_Plugin::ACTION_CLONE_CHART );
498506
$capable = current_user_can( 'edit_posts' );
499507
if ( $nonce && $capable ) {
500-
$chart_id = filter_input( INPUT_GET, 'chart', FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1 ) ) );
508+
$chart_id = filter_input( INPUT_GET, 'chart', FILTER_VALIDATE_INT, array(
509+
'options' => array(
510+
'min_range' => 1,
511+
),
512+
) );
501513
if ( $chart_id ) {
502514
$chart = get_post( $chart_id );
503515
$success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
@@ -545,7 +557,11 @@ public function exportData() {
545557
$chart_id = $success = false;
546558
$capable = current_user_can( 'edit_posts' );
547559
if ( $capable ) {
548-
$chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 1 ) ) ) : '';
560+
$chart_id = isset( $_GET['chart'] ) ? filter_var( $_GET['chart'], FILTER_VALIDATE_INT, array(
561+
'options' => array(
562+
'min_range' => 1,
563+
),
564+
) ) : '';
549565
if ( $chart_id ) {
550566
$chart = get_post( $chart_id );
551567
$success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;

classes/Visualizer/Module/Frontend.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ public function renderChart( $atts ) {
151151

152152
// enqueue visualizer render and update render localizations
153153
wp_enqueue_script( 'visualizer-render' );
154-
wp_localize_script( 'visualizer-render', 'visualizer', array( 'charts' => $this->_charts ) );
154+
wp_localize_script( 'visualizer-render', 'visualizer', array(
155+
'charts' => $this->_charts,
156+
) );
155157

156158
// return placeholder div
157159
return '<div id="' . $id . '"' . $class . '></div>';

classes/Visualizer/Render/Library.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ private function _renderLibrary() {
9696
echo '<ul class="subsubsub">';
9797
foreach ( $this->types as $type => $array ) {
9898
$label = $array['name'];
99-
$link = '<a class=" " href="' . esc_url( add_query_arg( array( 'type' => $type, 'vpage' => false ) ) ) . '">';
99+
$link = '<a class=" " href="' . esc_url( add_query_arg( array(
100+
'type' => $type,
101+
'vpage' => false,
102+
) ) ) . '">';
100103
if ( ! $array['enabled'] ) {
101104
$link = "<a class=' visualizer-pro-only' href='" . Visualizer_Plugin::PRO_TEASER_URL . "' target='_blank'>";
102105
}

classes/Visualizer/Render/Page/Update.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ protected function _toHTML() {
5656
global $Visualizer_Pro;
5757
$Visualizer_Pro->_addUpdateHook( $this->series, $this->data );
5858
}
59-
// Added by Ash/Upwork
6059
} else {
6160
echo 'alert("', $this->message, '");';
6261
}

0 commit comments

Comments
 (0)