Skip to content

Commit b9001af

Browse files
Merge branch '3.4.0' of https://github.com/codeinwp/visualizer into issue-214
2 parents a840cf5 + 9c86ea9 commit b9001af

37 files changed

+1406
-223
lines changed

.distignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ composer.lock
2020
package-lock.json
2121
key.enc
2222
vendor/phpoffice/phpexcel/Examples
23-
vendor/phpoffice/phpexcel/unitTests
23+
vendor/phpoffice/phpexcel/unitTests
24+
cypress
25+
docker-compose.travis.yml
26+
cypress.env.json.template
27+
cypress.json

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ vendor
77
composer.lock
88
bin/
99
package-lock.json
10+
cypress/integration/examples
11+
cypress/integration/localhost*
12+
cypress/plugins
13+
cypress.env.json

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
language: php
22
sudo: false
33
dist: trusty
4+
services:
5+
- docker
46
matrix:
57
fast_finish: true
68
include:
@@ -14,6 +16,14 @@ matrix:
1416
before_script: chmod +x bin/wraith.sh
1517
env: TEST_SUITE=Wraith_Visual_Regression_Testing WRAITH_FAIL=5
1618
script: "./bin/wraith.sh"
19+
- name: Cypress
20+
if: branch = development
21+
language: node_js
22+
node_js:
23+
- 10.8
24+
script:
25+
- docker-compose -f docker-compose.travis.yml up -d
26+
- chmod +x ./bin/run-e2e-tests.sh ./bin/wp-init.sh && ./bin/wp-init.sh && ./bin/run-e2e-tests.sh
1727
allow_failures:
1828
- env: TEST_SUITE=Wraith_Visual_Regression_Testing WRAITH_FAIL=5
1929
branches:

Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = function (grunt) {
77
var loader = require( 'load-project-config' ),
88
config = require( 'grunt-plugin-fleet' );
99
config = config();
10+
config.files.js.push( '!cypress/**/*.js' );
1011
// jshint ignore: start
1112
config.taskMap['faq_builder'] = 'grunt-helpscout-faq';
1213
// jshint ignore: end

bin/kill-and-create-all.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# to be executed from the plugin main directory (visualizer-pro)
2+
docker kill $(docker ps -q)
3+
docker system prune -a
4+
5+
windows=`echo $OSTYPE | grep -i -e "win" -e "msys" -e "cygw" | wc -l`
6+
if [[ $windows -gt 0 ]]; then
7+
docker-machine start default
8+
fi
9+
10+
docker-compose -f docker-compose.travis.yml up -d
11+
./bin/wp-init.sh
12+
./bin/run-e2e-tests.sh

bin/mysql/init-db.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
grant all privileges on *.* to 'wordpress'@'%' identified by 'wordpress';

bin/run-e2e-tests.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ "$TRAVIS" == "true" ]]; then
4+
npm install --only=dev --prefix ./cypress/
5+
composer install --no-dev
6+
fi
7+
8+
wp_host='localhost'
9+
windows=`echo $OSTYPE | grep -i -e "win" -e "msys" -e "cygw" | wc -l`
10+
args='-it';
11+
if [[ $windows -gt 0 ]]; then
12+
wp_host=`docker-machine ip`
13+
args=''
14+
fi
15+
16+
# exit on error
17+
set -e
18+
19+
export CYPRESS_HOST=$wp_host
20+
21+
# test free - lifecycle
22+
export CYPRESS_SPEC_TO_RUN="free-lifecycle.js"
23+
npm run cypress:run
24+
25+
# test free - sources
26+
export CYPRESS_SPEC_TO_RUN="free-sources.js"
27+
npm run cypress:run

bin/wp-init.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
3+
# if on windows, find out the IP using `docker-machine ip` and provide the IP as the host.
4+
wp_host='localhost'
5+
windows=`echo $OSTYPE | grep -i -e "win" -e "msys" -e "cygw" | wc -l`
6+
args='-it';
7+
if [[ $windows -gt 0 ]]; then
8+
wp_host=`docker-machine ip`
9+
args=''
10+
fi
11+
12+
# sleep for sometime till WP initializes successfully
13+
sleep_time=15
14+
if [[ $windows -gt 0 ]]; then
15+
sleep_time=30
16+
fi
17+
echo "Sleeping for $sleep_time..."
18+
sleep $sleep_time
19+
20+
# install WP
21+
docker exec $args visualizer_wordpress wp --quiet core install --url="http://$wp_host:8888/" --admin_user="wordpress" --admin_password="wordpress" --admin_email="[email protected]" --title="test" --skip-email
22+
23+
# install required external plugins
24+
docker exec $args visualizer_wordpress chown -R www-data:www-data /var/www/html/
25+
docker exec $args visualizer_wordpress wp plugin install classic-editor --activate
26+
27+
# so that debug.log is created
28+
docker exec $args visualizer_wordpress chmod 0777 -R /var/www/html/wp-content
29+
30+
# install visualizer free
31+
docker exec $args visualizer_wordpress git clone https://github.com/Codeinwp/visualizer /var/www/html/wp-content/plugins/visualizer
32+
33+
# activate
34+
docker exec $args visualizer_wordpress wp --quiet plugin activate visualizer
35+
36+
# set this constant so that the license is not checked
37+
docker exec $args visualizer_wordpress wp --quiet config set TI_UNIT_TESTING true --raw
38+
39+
# set this constant so that the specific hooks are loaded
40+
docker exec $args visualizer_wordpress wp --quiet config set TI_CYPRESS_TESTING true --raw
41+
42+
# debugging
43+
docker exec $args visualizer_wordpress wp --quiet config set WP_DEBUG true --raw
44+
docker exec $args visualizer_wordpress wp --quiet config set WP_DEBUG_LOG true --raw
45+
docker exec $args visualizer_wordpress wp --quiet config set WP_DEBUG_DISPLAY false --raw
46+

classes/Visualizer/Module.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,24 @@ public function __construct( Visualizer_Plugin $plugin ) {
6767
$this->_addFilter( Visualizer_Plugin::FILTER_UNDO_REVISIONS, 'undoRevisions', 10, 2 );
6868
$this->_addFilter( Visualizer_Plugin::FILTER_HANDLE_REVISIONS, 'handleExistingRevisions', 10, 2 );
6969
$this->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_DATA_AS, 'getDataAs', 10, 3 );
70+
register_shutdown_function( array($this, 'onShutdown') );
7071

7172
}
7273

74+
/**
75+
* Register a shutdown hook to catch fatal errors.
76+
*
77+
* @since ?
78+
*
79+
* @access public
80+
*/
81+
public function onShutdown() {
82+
$error = error_get_last();
83+
if ( $error['type'] === E_ERROR && false !== strpos( $error['file'], 'Visualizer/' ) ) {
84+
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Critical error %s', print_r( $error, true ) ), 'error', __FILE__, __LINE__ );
85+
}
86+
}
87+
7388
/**
7489
* Registers an action hook.
7590
*
@@ -640,4 +655,16 @@ public static function is_pro_older_than( $version ) {
640655
return version_compare( VISUALIZER_PRO_VERSION, $version, '<' );
641656
}
642657

658+
/**
659+
* Gets the features for the provided license type.
660+
*/
661+
public static final function get_features_for_license( $plan ) {
662+
switch ( $plan ) {
663+
case 1:
664+
return array( 'import-wp', 'db-query' );
665+
case 2:
666+
return array( 'schedule-chart', 'chart-permissions' );
667+
}
668+
}
669+
643670
}

classes/Visualizer/Module/Admin.php

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,67 @@ public function __construct( Visualizer_Plugin $plugin ) {
6868
$this->_addAction( '_wp_put_post_revision', 'addRevision', null, 10, 1 );
6969
$this->_addAction( 'wp_restore_post_revision', 'restoreRevision', null, 10, 2 );
7070

71+
$this->_addAction( 'visualizer_chart_schedules_spl', 'addSplChartSchedules', null, 10, 3 );
72+
7173
$this->_addAction( 'admin_init', 'init' );
7274
}
7375

76+
77+
/**
78+
* Add disabled `optgroup` schedules to the drop downs.
79+
*
80+
* @since ?
81+
*
82+
* @access public
83+
*
84+
* @param string $feature The feature for which to add schedules.
85+
* @param int $chart_id The chart ID.
86+
* @param int $plan The plan number.
87+
*/
88+
public function addSplChartSchedules( $feature, $chart_id, $plan ) {
89+
if ( apply_filters( 'visualizer_is_business', false ) ) {
90+
return;
91+
}
92+
93+
$license = __( 'PRO', 'visualizer' );
94+
switch ( $plan ) {
95+
case 2:
96+
$license = __( 'Developer', 'visualizer' );
97+
break;
98+
}
99+
100+
$hours = array(
101+
'0' => __( 'Live', 'visualizer' ),
102+
'1' => __( 'Each hour', 'visualizer' ),
103+
'12' => __( 'Each 12 hours', 'visualizer' ),
104+
'24' => __( 'Each day', 'visualizer' ),
105+
'72' => __( 'Each 3 days', 'visualizer' ),
106+
);
107+
108+
switch ( $feature ) {
109+
case 'json':
110+
// no more schedules if pro is already active.
111+
if ( Visualizer_Module::is_pro() ) {
112+
return;
113+
}
114+
break;
115+
case 'wp':
116+
// fall-through.
117+
case 'db':
118+
// fall-through.
119+
case 'csv':
120+
break;
121+
default:
122+
return;
123+
}
124+
125+
echo '<optgroup disabled label="' . sprintf( __( 'More in the %s version', 'visualizer' ), $license ) . '">';
126+
foreach ( $hours as $hour => $desc ) {
127+
echo '<option disabled>' . $desc . '</option>';
128+
}
129+
echo '</optgroup>';
130+
}
131+
74132
/**
75133
* No limits on revisions.
76134
*/
@@ -726,7 +784,10 @@ public function renderLibraryPage() {
726784
$settings = apply_filters( $atts['settings'], $settings, $chart->ID, $type );
727785
}
728786

729-
unset( $settings['height'], $settings['width'], $settings['chartArea'] );
787+
if ( $settings ) {
788+
unset( $settings['height'], $settings['width'], $settings['chartArea'] );
789+
}
790+
730791
$series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type );
731792
$data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( html_entity_decode( $chart->post_content ) ), $chart->ID, $type );
732793

0 commit comments

Comments
 (0)