Skip to content

Commit 7d05014

Browse files
authored
Merge pull request #36 from octalmage/PHP-185
PHP-185 - Display stats for results.
2 parents baaf250 + c246da1 commit 7d05014

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/js/run.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,28 @@ function displayReport( response ) {
131131
resetDisplay();
132132
var $ = jQuery;
133133
var compatible = 1;
134+
// Keep track of the number of failed plugins/themes.
135+
var failedCount = 0;
134136
var errorsRegex = /(\d*) ERRORS?/g;
135137
var warningRegex = /(\d*) WARNINGS?/g;
136138
var updateVersionRegex = /e: (.*?);/g;
137139
var currentVersionRegex = /n: (.*?);/g;
140+
// Grab and compile our template.
141+
var source = $( '#result-template' ).html();
142+
var template = Handlebars.compile( source );
138143
$( '#runButton' ).removeClass( 'button-primary-disabled' );
139144
$( '.spinner' ).hide();
140145
$( '#testResults' ).text( response );
141146
$( '#footer' ).show();
142147
$( '#runButton' ).val( 'Re-run' );
143148
// Separate plugins/themes.
144149
var plugins = response.replace( /^\s+|\s+$/g, '' ).split( 'Name: ' );
150+
151+
// Remove the first item, it's empty.
152+
plugins.shift();
153+
145154
// Loop through them.
146155
for ( var x in plugins ) {
147-
if ( '' === plugins[x].trim() ) {
148-
continue;
149-
}
150156
var updateVersion;
151157
var updateAvailable = 0;
152158
var passed = 1;
@@ -166,6 +172,7 @@ function displayReport( response ) {
166172
if ( parseInt( errors ) > 0 ) {
167173
compatible = 0;
168174
passed = 0;
175+
failedCount++;
169176
}
170177
// Trim whitespace and newlines from report.
171178
log = log.replace( /^\s+|\s+$/g, '' );
@@ -174,8 +181,6 @@ function displayReport( response ) {
174181
skipped = 1;
175182
}
176183
// Use handlebars to build our template.
177-
var source = $( '#result-template' ).html();
178-
var template = Handlebars.compile( source );
179184
var context = {
180185
plugin_name: name,
181186
warnings: warnings,
@@ -189,10 +194,14 @@ function displayReport( response ) {
189194
var html = template( context );
190195
$('#standardMode').append( html );
191196
}
197+
192198
// Display global compatibility status.
193199
if ( compatible ) {
194200
$( '#standardMode' ).prepend( '<h3>Your WordPress install is PHP ' + test_version + ' compatible.</h3>' );
195201
} else {
202+
// Display scan stats.
203+
$( '#standardMode' ).prepend( '<p>' + failedCount + ' out of ' + plugins.length + ' plugins/themes are not compatible.</p>' );
204+
196205
$( '#standardMode' ).prepend( '<h3>Your WordPress install is not PHP ' + test_version + ' compatible.</h3>' );
197206
}
198-
}
207+
}

tests/qunit/test-run.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ QUnit.test( 'Render test pass', function( assert ) {
5959
assert.ok( $('.wpe-results-card').length == 2, 'There are 2 results.' );
6060
assert.ok( $('#standardMode').text().includes( 'Your WordPress install is PHP 5.5 compatible.' ), 'Test did pass.' );
6161
assert.ok( '#038103' === helpers.rgb2hex( $( ".wpe-results-card" ).eq( 0 ).css( 'border-left-color' ) ), 'First plugin marked as passed.' );
62+
assert.ok( ! $( '#standardMode' ).text().includes( '0 out of 2' ), 'No scan stats are shown.' );
6263
});
6364

6465
QUnit.test( 'Render test fail', function( assert ) {
@@ -79,6 +80,7 @@ QUnit.test( 'Render test fail', function( assert ) {
7980
assert.ok( ! $('#runButton').hasClass('button-primary-disabled'), "Run button isn't disabled" );
8081
assert.ok( $('.wpe-results-card').length == 7, 'There are 7 results.' );
8182
assert.ok( $('#standardMode').text().includes( 'Your WordPress install is not PHP 5.5 compatible.' ), 'Test did not pass.' );
83+
assert.ok( $( '#standardMode' ).text().includes( '1 out of 7' ), 'Scan stats are correct' );
8284
});
8385

8486
QUnit.test( 'Render test skip', function( assert ) {

0 commit comments

Comments
 (0)