Skip to content

Commit 1bfbf38

Browse files
authored
Merge pull request #37 from stevenkword/PHP-160
[PHP-160] Allow leaving the test page during the scan.
2 parents 94ebac3 + b0d5e5f commit 1bfbf38

File tree

5 files changed

+126
-68
lines changed

5 files changed

+126
-68
lines changed

src/css/style.css

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
.wpe-results-card
33
{
44
background-color: #fff;
5-
border-bottom-color: rgb(221, 221, 221);
6-
border-bottom-style: solid;
7-
border-bottom-width: 1px;
8-
border-left-style: solid;
9-
border-left-width: 6px;
10-
width: 812px;
11-
padding-bottom: 14px;
12-
padding-left: 16px;
13-
padding-right: 16px;
14-
padding-top: 14px;
5+
border-bottom-color: rgb(221, 221, 221);
6+
border-bottom-style: solid;
7+
border-bottom-width: 1px;
8+
border-left-style: solid;
9+
border-left-width: 6px;
10+
width: 812px;
11+
padding-bottom: 14px;
12+
padding-left: 16px;
13+
padding-right: 16px;
14+
padding-top: 14px;
1515
margin-bottom: 10px;
1616
/*box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.12);*/
1717
}
1818

1919
.wpe-results-card .inner-left
2020
{
21-
display: inline-block;
21+
display: inline-block;
2222
letter-spacing: normal;
2323
text-rendering: auto;
2424
vertical-align: top;
@@ -29,7 +29,7 @@
2929
{
3030
color: rgb(51, 51, 51);
3131
display: inline-block;
32-
font-family: sans-serif;
32+
font-family: sans-serif;
3333
letter-spacing: normal;
3434
text-rendering: auto;
3535
vertical-align: top;
@@ -44,24 +44,24 @@
4444

4545
.wpe-results-card textarea
4646
{
47-
white-space: nowrap;
48-
width: 100%;
47+
white-space: nowrap;
48+
width: 100%;
4949
height: 400px;
5050
}
5151

5252
.wpe-results-card .view-details
5353
{
54-
font-size: 12px;
54+
font-size: 12px;
5555
color: #c0c0c0;
5656
cursor: pointer;
5757
}
5858

5959
.wpe-results-card .badge
6060
{
61-
display: inline-block;
62-
color: #fff;
63-
text-align: center;
64-
padding: 2px 10px;
61+
display: inline-block;
62+
color: #fff;
63+
text-align: center;
64+
padding: 2px 10px;
6565
}
6666

6767
.wpe-update a:link, .wpe-update a:visited, .wpe-update a:hover, .wpe-update a:active { color:#ffffff; cursor: pointer; text-decoration: none; }
@@ -91,4 +91,9 @@
9191
#progressbar .ui-progressbar-value
9292
{
9393
background: #0085ba;
94-
}
94+
}
95+
96+
#wpe-progress-count, #wpe-progress-active
97+
{
98+
display: inline;
99+
}

src/js/run.js

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ var test_version, only_active, timer;
33

44
jQuery( document ).ready(function($) {
55

6+
// Check the status immediately to reflect if tests are running.
7+
checkStatus();
8+
69
$( '#developermode' ).change(function() {
710
if ( $(this).is( ':checked' ) ) {
811
$( '#developerMode' ).show();
@@ -75,16 +78,44 @@ function checkStatus() {
7578
alert(e);
7679
return;
7780
}
81+
82+
/*
83+
* Status false: the test is not running and has not been run yet
84+
* Status 1: the test is currently running
85+
* Status 0: the test as completed but is not currently running
86+
*/
87+
if ( false === obj.results ) {
88+
jQuery( '#runButton' ).val( 'Run' );
89+
} else {
90+
jQuery( '#runButton' ).val( 'Re-run' );
91+
}
92+
93+
if ( '1' === obj.status ) {
94+
jQuery( '#runButton' ).addClass( 'button-primary-disabled' );
95+
jQuery( '.spinner' ).show();
96+
} else {
97+
jQuery( '#runButton' ).removeClass( 'button-primary-disabled' );
98+
jQuery( '.spinner' ).hide();
99+
}
100+
78101
if ( '0' !== obj.results ) {
79-
displayReport( obj.results );
102+
if( false !== obj.results ) {
103+
test_version = obj.version;
104+
displayReport( obj.results );
105+
}
80106
jQuery( '#wpe-progress' ).hide();
81107
} else {
82108
jQuery( '#progressbar' ).progressbar({
83109
value: obj.progress
84110
});
111+
jQuery( '#wpe-progress' ).show();
85112

86113
// Display the current plugin count.
87-
jQuery( '#wpe-progress-count' ).text( ( obj.total - obj.count ) + '/' + obj.total );
114+
jQuery( '#wpe-progress-count' ).text( ( obj.total - obj.count + 1 ) + '/' + obj.total );
115+
116+
// Display the object being scanned.
117+
jQuery( '#wpe-progress-active' ).text( obj.activeJob );
118+
88119
// Requeue the checkStatus call.
89120
timer = setTimeout(function() {
90121
checkStatus();
@@ -102,6 +133,7 @@ function resetDisplay() {
102133
jQuery( '#testResults' ).text('');
103134
jQuery( '#standardMode' ).html('');
104135
jQuery( '#wpe-progress-count' ).text('');
136+
jQuery( '#wpe-progress-active' ).text('');
105137
}
106138
/**
107139
* Loop through a string and count the total matches.
@@ -131,26 +163,27 @@ function displayReport( response ) {
131163
resetDisplay();
132164
var $ = jQuery;
133165
var compatible = 1;
166+
134167
// Keep track of the number of failed plugins/themes.
135168
var failedCount = 0;
136169
var errorsRegex = /(\d*) ERRORS?/g;
137170
var warningRegex = /(\d*) WARNINGS?/g;
138171
var updateVersionRegex = /e: (.*?);/g;
139172
var currentVersionRegex = /n: (.*?);/g;
173+
140174
// Grab and compile our template.
141175
var source = $( '#result-template' ).html();
142176
var template = Handlebars.compile( source );
143-
$( '#runButton' ).removeClass( 'button-primary-disabled' );
144-
$( '.spinner' ).hide();
177+
145178
$( '#testResults' ).text( response );
146179
$( '#footer' ).show();
147-
$( '#runButton' ).val( 'Re-run' );
180+
148181
// Separate plugins/themes.
149182
var plugins = response.replace( /^\s+|\s+$/g, '' ).split( 'Name: ' );
150-
183+
151184
// Remove the first item, it's empty.
152185
plugins.shift();
153-
186+
154187
// Loop through them.
155188
for ( var x in plugins ) {
156189
var updateVersion;
@@ -176,7 +209,7 @@ function displayReport( response ) {
176209
}
177210
// Trim whitespace and newlines from report.
178211
log = log.replace( /^\s+|\s+$/g, '' );
179-
212+
180213
if ( log.search('skipped') !== -1 ) {
181214
skipped = 1;
182215
}
@@ -201,7 +234,7 @@ function displayReport( response ) {
201234
} else {
202235
// Display scan stats.
203236
$( '#standardMode' ).prepend( '<p>' + failedCount + ' out of ' + plugins.length + ' plugins/themes are not compatible.</p>' );
204-
237+
205238
$( '#standardMode' ).prepend( '<h3>Your WordPress install is not PHP ' + test_version + ' compatible.</h3>' );
206239
}
207240
}

src/wpephpcompat.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ function __construct( $dir ) {
8888
public function start_test() {
8989

9090
$this->debug_log( 'startScan: ' . isset( $_POST['startScan'] ) );
91-
91+
9292
/**
9393
* Filters the scan timeout.
9494
*
95-
* Lets you change the timeout of the scan. The value is how long the scan
96-
* runs before dying and picking back up on a cron. You can set $timeout to
95+
* Lets you change the timeout of the scan. The value is how long the scan
96+
* runs before dying and picking back up on a cron. You can set $timeout to
9797
* 0 to disable the timeout and the cron.
9898
*
9999
* @since 1.0.4
@@ -102,23 +102,23 @@ public function start_test() {
102102
*/
103103
$timeout = apply_filters( 'wpephpcompat_scan_timeout', MINUTE_IN_SECONDS );
104104
$this->debug_log( 'timeout: ' . $timeout );
105-
105+
106106
// No reason to lock if there's no timeout.
107107
if ( 0 !== $timeout ) {
108108
// Try to lock.
109109
$lock_result = add_option( 'wpephpcompat.lock', time(), '', 'no' );
110-
110+
111111
$this->debug_log( 'lock: ' . $lock_result );
112-
112+
113113
if ( ! $lock_result ) {
114114
$lock_result = get_option( 'wpephpcompat.lock' );
115-
115+
116116
// Bail if we were unable to create a lock, or if the existing lock is still valid.
117117
if ( ! $lock_result || ( $lock_result > ( time() - $timeout ) ) ) {
118118
$this->debug_log( 'Process already running (locked), returning.' );
119-
119+
120120
$timestamp = wp_next_scheduled( 'wpephpcompat_start_test_cron' );
121-
121+
122122
if ( $timestamp == false ) {
123123
wp_schedule_single_event( time() + $timeout, 'wpephpcompat_start_test_cron' );
124124
}
@@ -133,6 +133,9 @@ public function start_test() {
133133
$this->debug_log( 'scan status: ' . $scan_status );
134134
if ( ! $scan_status ) {
135135

136+
// Clear the previous results.
137+
delete_option( 'wpephpcompat.scan_results' );
138+
136139
update_option( 'wpephpcompat.status', '1', false );
137140
update_option( 'wpephpcompat.test_version', $this->test_version, false );
138141
update_option( 'wpephpcompat.only_active', $this->only_active, false );
@@ -182,7 +185,7 @@ public function start_test() {
182185

183186
// Add the plugin/theme name to the results.
184187
$scan_results .= 'Name: ' . $directory->post_title . "\n\n";
185-
188+
186189
// Keep track of the number of times we've attempted to scan the plugin.
187190
$count = get_post_meta( $directory->ID, 'count', true ) ?: 1;
188191
$this->debug_log( 'Attempted scan count: ' . $count );
@@ -196,7 +199,7 @@ public function start_test() {
196199
continue;
197200
}
198201

199-
// Increment and save the count.
202+
// Increment and save the count.
200203
$count++;
201204
update_post_meta( $directory->ID, 'count', $count );
202205

@@ -256,7 +259,7 @@ public function process_file( $dir ) {
256259

257260
return $this->clean_report( $report );
258261
}
259-
262+
260263
/**
261264
* Generate a list of ignored files and directories.
262265
*
@@ -270,14 +273,14 @@ public function generate_ignored_list() {
270273
'*/node_modules/*', // Commonly used for development but not in production.
271274
'*/tmp/*', // Temporary files.
272275
);
273-
276+
274277
foreach ( $this->whitelist as $plugin => $version ) {
275278
// Check to see if the plugin is compatible with the tested version.
276279
if ( version_compare( $this->test_version, $version, '<=' ) ) {
277280
array_push( $ignored, $plugin );
278281
}
279282
}
280-
283+
281284
return $ignored;
282285
}
283286

@@ -356,13 +359,13 @@ public function generate_directory_list() {
356359

357360
$this->add_directory( $all_themes[$k]->Name, $theme_path );
358361
}
359-
362+
360363
// Add parent theme if the current theme is a child theme.
361364
if ( 'yes' === $this->only_active && is_child_theme() ) {
362365
$parent_theme_path = get_template_directory();
363366
$theme_data = wp_get_theme();
364367
$parent_theme_name = $theme_data->parent()->Name;
365-
368+
366369
$this->add_directory( $parent_theme_name, $parent_theme_path );
367370
}
368371
}
@@ -393,9 +396,6 @@ public function clean_after_scan() {
393396
// Delete options created during the scan.
394397
delete_option( 'wpephpcompat.lock' );
395398
delete_option( 'wpephpcompat.status' );
396-
delete_option( 'wpephpcompat.scan_results' );
397-
delete_option( 'wpephpcompat.test_version' );
398-
delete_option( 'wpephpcompat.only_active' );
399399
delete_option( 'wpephpcompat.numdirs' );
400400

401401
// Clear scheduled cron.

tests/qunit/test-run.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
/* jshint esversion: 6 */
2+
3+
// No document.ready event.
4+
$.holdReady( true );
5+
26
QUnit.module( 'findAll' );
37

48
QUnit.test( 'no matches', function( assert ) {
@@ -52,10 +56,7 @@ QUnit.test( 'Render test pass', function( assert ) {
5256
var displayedResults = $('#testResults').text();
5357

5458
assert.ok( helpers.passResults === displayedResults, 'Text results are correct' );
55-
assert.ok( ! $('.spinner').is(':visible'), 'Spinner is hidden' );
56-
assert.ok( 'Re-run' === $('#runButton').val(), 'Run button text is Re-run' );
5759
assert.ok( $('#footer').is(':visible'), 'Footer is visible' );
58-
assert.ok( ! $('#runButton').hasClass('button-primary-disabled'), "Run button isn't disabled" );
5960
assert.ok( $('.wpe-results-card').length == 2, 'There are 2 results.' );
6061
assert.ok( $('#standardMode').text().includes( 'Your WordPress install is PHP 5.5 compatible.' ), 'Test did pass.' );
6162
assert.ok( '#038103' === helpers.rgb2hex( $( ".wpe-results-card" ).eq( 0 ).css( 'border-left-color' ) ), 'First plugin marked as passed.' );
@@ -74,10 +75,7 @@ QUnit.test( 'Render test fail', function( assert ) {
7475
var displayedResults = $('#testResults').text();
7576

7677
assert.ok( helpers.failResults === displayedResults, 'Text results are correct' );
77-
assert.ok( ! $('.spinner').is(':visible'), 'Spinner is hidden' );
78-
assert.ok( 'Re-run' === $('#runButton').val(), 'Run button text is Re-run' );
7978
assert.ok( $('#footer').is(':visible'), 'Footer is visible' );
80-
assert.ok( ! $('#runButton').hasClass('button-primary-disabled'), "Run button isn't disabled" );
8179
assert.ok( $('.wpe-results-card').length == 7, 'There are 7 results.' );
8280
assert.ok( $('#standardMode').text().includes( 'Your WordPress install is not PHP 5.5 compatible.' ), 'Test did not pass.' );
8381
assert.ok( $( '#standardMode' ).text().includes( '1 out of 7' ), 'Scan stats are correct' );
@@ -120,7 +118,7 @@ QUnit.test( 'Test checkStatus progress', function( assert ) {
120118
return true;
121119
},
122120
onAfterComplete: function() { // Check the results of checkStatus();
123-
assert.ok( $( '#wpe-progress-count' ).text() === '16/17', 'Progress count is correct.' );
121+
assert.ok( $( '#wpe-progress-count' ).text() === '17/17', 'Progress count is correct.' );
124122
assert.ok( $( '#progressbar' ).progressbar( 'value' ) === 94.1176470588 , 'Progress bar is correct.' );
125123

126124
// Clear the next queued checkStatus call.

0 commit comments

Comments
 (0)