From fcfb02c2b773da90745f4ec3eb9a79f80262d795 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Fri, 26 May 2017 20:55:45 +0200 Subject: [PATCH 01/33] added tests for getFormatterDefault(), fixing bug in compact design --- js/test.js | 34 ++++++++++++++++++++++++++++++++++ tpl/bootstrap.php | 11 +++++++++++ 2 files changed, 45 insertions(+) diff --git a/js/test.js b/js/test.js index 3f24a2e..c1eec7e 100644 --- a/js/test.js +++ b/js/test.js @@ -595,6 +595,40 @@ describe('Model', function () { ); }); + describe('getFormatDefault', function () { + before(function () { + $.PrivateBin.Model.reset(); + cleanup(); + }); + + jsc.property( + 'returns the contents of the element with id "pasteFormatter"', + 'array asciinestring', + 'string', + 'small nat', + function (keys, value, key) { + keys = keys.map($.PrivateBin.Helper.htmlEntities); + value = $.PrivateBin.Helper.htmlEntities(value); + var content = keys.length > key ? keys[key] : (keys.length > 0 ? keys[0] : 'null'), + contents = ''; + $('body').html(contents); + var result = $.PrivateBin.Helper.htmlEntities( + $.PrivateBin.Model.getFormatDefault() + ); + $.PrivateBin.Model.reset(); + return content === result; + } + ); + }); + describe('getPasteId', function () { before(function () { $.PrivateBin.Model.reset(); diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 6fc01bd..8933ea6 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -230,6 +230,17 @@ if ($isCpct): ?> Date: Fri, 26 May 2017 21:52:00 +0200 Subject: [PATCH 02/33] added tests for getCipherData(), hasCipherData() & getTemplate() --- js/test.js | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/js/test.js b/js/test.js index c1eec7e..f0a4c47 100644 --- a/js/test.js +++ b/js/test.js @@ -629,6 +629,48 @@ describe('Model', function () { ); }); + describe('hasCipherData', function () { + before(function () { + $.PrivateBin.Model.reset(); + cleanup(); + }); + + jsc.property( + 'checks if the element with id "cipherdata" contains any data', + 'asciistring', + function (value) { + value = $.PrivateBin.Helper.htmlEntities(value).trim(); + $('body').html('
' + value + '
'); + $.PrivateBin.Model.init(); + var result = $.PrivateBin.Model.hasCipherData(); + $.PrivateBin.Model.reset(); + return (value.length > 0) === result; + } + ); + }); + + describe('getCipherData', function () { + before(function () { + $.PrivateBin.Model.reset(); + cleanup(); + }); + + jsc.property( + 'returns the contents of the element with id "cipherdata"', + 'asciistring', + function (value) { + value = $.PrivateBin.Helper.htmlEntities(value).trim(); + $('body').html('
' + value + '
'); + $.PrivateBin.Model.init(); + var result = $.PrivateBin.Helper.htmlEntities( + $.PrivateBin.Model.getCipherData() + ); + $.PrivateBin.Model.reset(); + return value === result; + } + ); + }); + describe('getPasteId', function () { before(function () { $.PrivateBin.Model.reset(); @@ -738,4 +780,33 @@ describe('Model', function () { } ); }); + + describe('getTemplate', function () { + before(function () { + $.PrivateBin.Model.reset(); + cleanup(); + }); + + jsc.property( + 'returns the contents of the element with id "[name]template"', + jsc.nearray(jsc.elements(alnumString)), + jsc.nearray(jsc.elements(a2zString)), + jsc.nearray(jsc.elements(alnumString)), + function (id, element, value) { + id = id.join(''); + element = element.join(''); + value = value.join('').trim(); + $('body').html( + '
<' + element + ' id="' + id + + 'template">' + value + '
' + ); + $.PrivateBin.Model.init(); + var template = '<' + element + ' id="' + id + '">' + value + + '', + result = $.PrivateBin.Model.getTemplate(id).wrap('

').parent().html(); + $.PrivateBin.Model.reset(); + return template === result; + } + ); + }); }); From ba0ff3545d4b4ef4c50d4c20da60bdef9580a4dc Mon Sep 17 00:00:00 2001 From: El RIDO Date: Wed, 13 Sep 2017 07:23:56 +0200 Subject: [PATCH 03/33] started work on UiHelper tests --- js/test.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/js/test.js b/js/test.js index f0a4c47..fce63c6 100644 --- a/js/test.js +++ b/js/test.js @@ -2,6 +2,7 @@ var jsc = require('jsverify'), jsdom = require('jsdom-global'), cleanup = jsdom(), + EventEmitter = require('events'), a2zString = ['a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z'], @@ -810,3 +811,32 @@ describe('Model', function () { ); }); }); + +describe('UiHelper', function () { + describe('historyChange', function () { + before(function () { + $.PrivateBin.Helper.reset(); + }); + + jsc.property( + 'returns the URL without query & fragment', + jsc.elements(schemas), + jsc.nearray(jsc.elements(a2zString)), + jsc.array(jsc.elements(queryString)), + 'string', + function (schema, address, query, fragment) { + var expected = schema + '://' + address.join('') + '/', + clean = jsdom('', {url: expected + '?' + query.join('') + '#' + fragment}), + emitter = new EventEmitter(); + + $.PrivateBin.UiHelper.init(); + emitter.emit('popstate'); + var result = window.location.href; + clean(); + console.log(expected, result); + return expected === result; + } + ); + }); +}); + From 6dbb098d7aca1783e5117aefb81712e429009c89 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 22 Oct 2017 09:56:44 +0200 Subject: [PATCH 04/33] had to introduce a mock function to test the historyChange state --- js/privatebin.js | 15 ++++++++++++++- js/test.js | 9 ++++----- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index 9e626e9..3d8ddd1 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -866,7 +866,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { { var currentLocation = Helper.baseUri(); if (event.originalEvent.state === null && // no state object passed - event.originalEvent.target.location.href === currentLocation && // target location is home page + event.target.location.href === currentLocation && // target location is home page window.location.href === currentLocation // and we are not already on the home page ) { // redirect to home page @@ -958,6 +958,19 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { }); } + /** + * trigger a history (pop) state change + * + * used to test the UiHelper.historyChange private function + * + * @name UiHelper.mockHistoryChange + * @function + */ + me.mockHistoryChange = function() + { + historyChange($.Event('popstate', {originalEvent: new PopStateEvent('popstate', {state: null}), target: window})); + } + /** * initialize * diff --git a/js/test.js b/js/test.js index bedcd4a..66752db 100644 --- a/js/test.js +++ b/js/test.js @@ -2,7 +2,6 @@ var jsc = require('jsverify'), jsdom = require('jsdom-global'), cleanup = jsdom(), - EventEmitter = require('events'), a2zString = ['a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z'], @@ -824,6 +823,8 @@ describe('UiHelper', function () { $.PrivateBin.Helper.reset(); }); + // TODO: As per https://github.com/tmpvar/jsdom/issues/1565 there is no navigation support in jsdom, yet. + // for now we use a mock function to trigger the event jsc.property( 'returns the URL without query & fragment', jsc.elements(schemas), @@ -832,11 +833,9 @@ describe('UiHelper', function () { 'string', function (schema, address, query, fragment) { var expected = schema + '://' + address.join('') + '/', - clean = jsdom('', {url: expected + '?' + query.join('') + '#' + fragment}), - emitter = new EventEmitter(); + clean = jsdom('', {url: expected + '?' + query.join('') + '#' + fragment}); - $.PrivateBin.UiHelper.init(); - emitter.emit('popstate'); + $.PrivateBin.UiHelper.mockHistoryChange(); var result = window.location.href; clean(); console.log(expected, result); diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index c3e1ba4..b6e7560 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -69,7 +69,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index 81d7c1a..d774d05 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -47,7 +47,7 @@ if ($MARKDOWN): - + From 414693fa90d4326aff1ea4a5ed9ddcfd26ae909e Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 22 Oct 2017 10:39:18 +0200 Subject: [PATCH 05/33] testing both cases of the logic required for #167 --- .gitattributes | 2 -- js/privatebin.js | 8 ++++++-- js/test.js | 30 ++++++++++++++++++++++-------- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/.gitattributes b/.gitattributes index daef8b1..3c39546 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,8 +2,6 @@ doc/ export-ignore tst/ export-ignore js/.istanbul.yml export-ignore js/test.js export-ignore -js/mocha-3.2.0.js export-ignore -css/mocha-3.2.0.css export-ignore .codeclimate.yml export-ignore .csslintrc export-ignore .dockerignore export-ignore diff --git a/js/privatebin.js b/js/privatebin.js index 3d8ddd1..3db3fae 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -965,10 +965,14 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { * * @name UiHelper.mockHistoryChange * @function + * @param {string} state (optional) state to mock */ - me.mockHistoryChange = function() + me.mockHistoryChange = function(state) { - historyChange($.Event('popstate', {originalEvent: new PopStateEvent('popstate', {state: null}), target: window})); + if (typeof state === 'undefined') { + state = null; + } + historyChange($.Event('popstate', {originalEvent: new PopStateEvent('popstate', {state: state}), target: window})); } /** diff --git a/js/test.js b/js/test.js index 66752db..044c6c6 100644 --- a/js/test.js +++ b/js/test.js @@ -818,27 +818,41 @@ describe('Model', function () { }); describe('UiHelper', function () { + // TODO: As per https://github.com/tmpvar/jsdom/issues/1565 there is no navigation support in jsdom, yet. + // for now we use a mock function to trigger the event describe('historyChange', function () { before(function () { $.PrivateBin.Helper.reset(); }); - // TODO: As per https://github.com/tmpvar/jsdom/issues/1565 there is no navigation support in jsdom, yet. - // for now we use a mock function to trigger the event jsc.property( - 'returns the URL without query & fragment', + 'redirects to home, when the state is null', jsc.elements(schemas), jsc.nearray(jsc.elements(a2zString)), - jsc.array(jsc.elements(queryString)), - 'string', - function (schema, address, query, fragment) { + function (schema, address) { var expected = schema + '://' + address.join('') + '/', - clean = jsdom('', {url: expected + '?' + query.join('') + '#' + fragment}); + clean = jsdom('', {url: expected}); $.PrivateBin.UiHelper.mockHistoryChange(); var result = window.location.href; clean(); - console.log(expected, result); + return expected === result; + } + ); + + jsc.property( + 'does not redirect to home, when a new paste is created', + jsc.elements(schemas), + jsc.nearray(jsc.elements(a2zString)), + jsc.array(jsc.elements(queryString)), + jsc.nearray(jsc.elements(base64String)), + function (schema, address, query, fragment) { + var expected = schema + '://' + address.join('') + '/' + '?' + query.join('') + '#' + fragment.join(''), + clean = jsdom('', {url: expected}); + + $.PrivateBin.UiHelper.mockHistoryChange([{type: 'newpaste'}, '', expected]); + var result = window.location.href; + clean(); return expected === result; } ); diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index b6e7560..4fbd6c0 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -69,7 +69,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index d774d05..2fa90ce 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -47,7 +47,7 @@ if ($MARKDOWN): - + From 4cb21350a09be5fc2df91a5a3ae6f49ea80a1c81 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 22 Oct 2017 10:45:41 +0200 Subject: [PATCH 06/33] TravisCI can be a bit slow (locally this test takes 386ms) --- js/test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/test.js b/js/test.js index 044c6c6..dde1874 100644 --- a/js/test.js +++ b/js/test.js @@ -821,6 +821,7 @@ describe('UiHelper', function () { // TODO: As per https://github.com/tmpvar/jsdom/issues/1565 there is no navigation support in jsdom, yet. // for now we use a mock function to trigger the event describe('historyChange', function () { + this.timeout(30000); before(function () { $.PrivateBin.Helper.reset(); }); From cbcc26ec37964478bd765858c69210f9af894810 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 22 Oct 2017 10:55:28 +0200 Subject: [PATCH 07/33] fixing false positive with RNG state 0bc96fe3b8d170254a --- js/test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/js/test.js b/js/test.js index dde1874..6ac4210 100644 --- a/js/test.js +++ b/js/test.js @@ -802,6 +802,12 @@ describe('Model', function () { id = id.join(''); element = element.join(''); value = value.join('').trim(); + + //
tags can't contain strings, so test with a

instead + if (element == 'br') { + element = 'p'; + } + $('body').html( '

<' + element + ' id="' + id + 'template">' + value + '
' From 4410ddcd840388707ebfd89cff4abd4486cd519a Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 22 Oct 2017 13:39:23 +0200 Subject: [PATCH 08/33] adding tests for UiHelper.reloadHome, making UiHelper unit testable and handling JSVerify RNG states 846932d5afb10ce748 & 012c1f9483adb6e750 --- js/privatebin.js | 6 ++---- js/test.js | 46 ++++++++++++++++++++++++++++++++++++++++++++-- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index 3db3fae..74db28c 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -845,11 +845,9 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { * everything directly UI-related, which fits nowhere else * * @name UiHelper - * @param {object} window - * @param {object} document * @class */ - var UiHelper = (function (window, document) { + var UiHelper = (function () { var me = {}; /** @@ -990,7 +988,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { } return me; - })(window, document); + })(); /** * Alert/error manager diff --git a/js/test.js b/js/test.js index 6ac4210..e14cdde 100644 --- a/js/test.js +++ b/js/test.js @@ -803,8 +803,8 @@ describe('Model', function () { element = element.join(''); value = value.join('').trim(); - //
tags can't contain strings, so test with a

instead - if (element == 'br') { + //
tags can't contain strings, table tags can't be alone, so test with a

instead + if (['br', 'tr', 'td', 'th'].indexOf(element) >= 0) { element = 'p'; } @@ -840,7 +840,13 @@ describe('UiHelper', function () { var expected = schema + '://' + address.join('') + '/', clean = jsdom('', {url: expected}); + // make window.location.href writable + Object.defineProperty(window.location, 'href', { + writable: true, + value: window.location.href + }); $.PrivateBin.UiHelper.mockHistoryChange(); + $.PrivateBin.Helper.reset(); var result = window.location.href; clean(); return expected === result; @@ -857,7 +863,43 @@ describe('UiHelper', function () { var expected = schema + '://' + address.join('') + '/' + '?' + query.join('') + '#' + fragment.join(''), clean = jsdom('', {url: expected}); + // make window.location.href writable + Object.defineProperty(window.location, 'href', { + writable: true, + value: window.location.href + }); $.PrivateBin.UiHelper.mockHistoryChange([{type: 'newpaste'}, '', expected]); + $.PrivateBin.Helper.reset(); + var result = window.location.href; + clean(); + return expected === result; + } + ); + }); + + describe('reloadHome', function () { + this.timeout(30000); + before(function () { + $.PrivateBin.Helper.reset(); + }); + + jsc.property( + 'redirects to home', + jsc.elements(schemas), + jsc.nearray(jsc.elements(a2zString)), + jsc.array(jsc.elements(queryString)), + jsc.nearray(jsc.elements(base64String)), + function (schema, address, query, fragment) { + var expected = schema + '://' + address.join('') + '/', + clean = jsdom('', {url: expected + '?' + query.join('') + '#' + fragment.join('')}); + + // make window.location.href writable + Object.defineProperty(window.location, 'href', { + writable: true, + value: window.location.href + }); + $.PrivateBin.UiHelper.reloadHome(); + $.PrivateBin.Helper.reset(); var result = window.location.href; clean(); return expected === result; diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 4fbd6c0..609ccb7 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -69,7 +69,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index 2fa90ce..8b8fcad 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -47,7 +47,7 @@ if ($MARKDOWN): - + From ef6b6816b0fc576e1aa43b91cfb8c4cd3f2feef3 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 22 Oct 2017 16:26:41 +0200 Subject: [PATCH 09/33] implemented test, but again not supported yet by jsdom --- js/test.js | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/js/test.js b/js/test.js index e14cdde..50fe2ed 100644 --- a/js/test.js +++ b/js/test.js @@ -860,7 +860,8 @@ describe('UiHelper', function () { jsc.array(jsc.elements(queryString)), jsc.nearray(jsc.elements(base64String)), function (schema, address, query, fragment) { - var expected = schema + '://' + address.join('') + '/' + '?' + query.join('') + '#' + fragment.join(''), + var expected = schema + '://' + address.join('') + '/' + '?' + + query.join('') + '#' + fragment.join(''), clean = jsdom('', {url: expected}); // make window.location.href writable @@ -868,7 +869,9 @@ describe('UiHelper', function () { writable: true, value: window.location.href }); - $.PrivateBin.UiHelper.mockHistoryChange([{type: 'newpaste'}, '', expected]); + $.PrivateBin.UiHelper.mockHistoryChange([ + {type: 'newpaste'}, '', expected + ]); $.PrivateBin.Helper.reset(); var result = window.location.href; clean(); @@ -891,7 +894,9 @@ describe('UiHelper', function () { jsc.nearray(jsc.elements(base64String)), function (schema, address, query, fragment) { var expected = schema + '://' + address.join('') + '/', - clean = jsdom('', {url: expected + '?' + query.join('') + '#' + fragment.join('')}); + clean = jsdom('', { + url: expected + '?' + query.join('') + '#' + fragment.join('') + }); // make window.location.href writable Object.defineProperty(window.location, 'href', { @@ -906,5 +911,29 @@ describe('UiHelper', function () { } ); }); + + describe('isVisible', function () { + before(function () { + $.PrivateBin.Helper.reset(); + }); + + jsc.property( + 'detect visible elements', + jsc.nearray(jsc.elements(alnumString)), + jsc.nearray(jsc.elements(a2zString)), + function (id, element) { + id = id.join(''); + element = element.join(''); + var clean = jsdom( + '<' + element + ' id="' + id + '">' + ); + // TODO As per https://github.com/tmpvar/jsdom/issues/1048 there is no layout support in jsdom, yet. + // remove the "true || " below, once it is supported or a workaround is found + var result = true || $.PrivateBin.UiHelper.isVisible($('#' + id)); + clean(); + return result; + } + ); + }); }); From d75cea856ae458acb3297362ca319d1c9c9a6420 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Mon, 23 Oct 2017 05:34:55 +0200 Subject: [PATCH 10/33] concluding UiHelper tests that are possible in headless jsdom at this time --- js/test.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/js/test.js b/js/test.js index 50fe2ed..6a67972 100644 --- a/js/test.js +++ b/js/test.js @@ -913,6 +913,9 @@ describe('UiHelper', function () { }); describe('isVisible', function () { + // TODO As per https://github.com/tmpvar/jsdom/issues/1048 there is no layout support in jsdom, yet. + // once it is supported or a workaround is found, uncomment the section below + /* before(function () { $.PrivateBin.Helper.reset(); }); @@ -927,13 +930,16 @@ describe('UiHelper', function () { var clean = jsdom( '<' + element + ' id="' + id + '">' ); - // TODO As per https://github.com/tmpvar/jsdom/issues/1048 there is no layout support in jsdom, yet. - // remove the "true || " below, once it is supported or a workaround is found - var result = true || $.PrivateBin.UiHelper.isVisible($('#' + id)); + var result = $.PrivateBin.UiHelper.isVisible($('#' + id)); clean(); return result; } ); + */ + }); + + describe('scrollTo', function () { + // TODO Did not find a way to test that, see isVisible test above }); }); From 9c6aec86c42bdd248c21088014acd72e5d665e1a Mon Sep 17 00:00:00 2001 From: El RIDO Date: Mon, 23 Oct 2017 21:33:07 +0200 Subject: [PATCH 11/33] making Alert class resetable and adding first tests for it --- js/privatebin.js | 14 ++++---- js/test.js | 90 +++++++++++++++++++++++++++++++++++++++++++++++ tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 4 files changed, 100 insertions(+), 8 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index 74db28c..f818b98 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -1004,12 +1004,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { $statusMessage, $remainingTime; - var currentIcon = [ - 'glyphicon-time', // loading icon - 'glyphicon-info-sign', // status icon - '', // resevered for warning, not used yet - 'glyphicon-alert' // error icon - ]; + var currentIcon; var alertType = [ 'loading', // not in bootstrap, but using a good value here @@ -1253,6 +1248,13 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { $loadingIndicator = $('#loadingindicator'); $statusMessage = $('#status'); $remainingTime = $('#remainingtime'); + + currentIcon = [ + 'glyphicon-time', // loading icon + 'glyphicon-info-sign', // status icon + '', // reserved for warning, not used yet + 'glyphicon-alert' // error icon + ]; } return me; diff --git a/js/test.js b/js/test.js index 6a67972..63b6ba4 100644 --- a/js/test.js +++ b/js/test.js @@ -943,3 +943,93 @@ describe('UiHelper', function () { }); }); +describe('Alert', function () { + describe('showStatus', function () { + before(function () { + cleanup(); + }); + + jsc.property( + 'shows a status message', + jsc.array(jsc.elements(alnumString)), + jsc.array(jsc.elements(alnumString)), + function (icon, message) { + icon = icon.join(''); + message = message.join(''); + var expected = '

'; + $('body').html( + '' + ); + $.PrivateBin.Alert.init(); + $.PrivateBin.Alert.showStatus(message, icon); + var result = $('body').html(); + return expected === result; + } + ); + }); + + describe('showError', function () { + before(function () { + cleanup(); + }); + + jsc.property( + 'shows an error message', + jsc.array(jsc.elements(alnumString)), + jsc.array(jsc.elements(alnumString)), + function (icon, message) { + icon = icon.join(''); + message = message.join(''); + var expected = ''; + $('body').html( + '' + ); + $.PrivateBin.Alert.init(); + $.PrivateBin.Alert.showError(message, icon); + var result = $('body').html(); + return expected === result; + } + ); + }); + + describe('showRemaining', function () { + before(function () { + cleanup(); + }); + + jsc.property( + 'shows remaining time', + jsc.array(jsc.elements(alnumString)), + jsc.array(jsc.elements(alnumString)), + 'integer', + function (message, string, number) { + message = message.join(''); + string = string.join(''); + var expected = ''; + $('body').html( + '' + ); + $.PrivateBin.Alert.init(); + $.PrivateBin.Alert.showRemaining(['%s' + message + '%d', string, number]); + var result = $('body').html(); + return expected === result; + } + ); + }); +}); + diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 609ccb7..036452e 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -69,7 +69,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index 8b8fcad..1cae6b3 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -47,7 +47,7 @@ if ($MARKDOWN): - + From 751731414e15fc079dfab12a61ce230878ec1b51 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Mon, 30 Oct 2017 06:53:15 +0100 Subject: [PATCH 12/33] adding test for loading indicator --- js/test.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/js/test.js b/js/test.js index 63b6ba4..bd0fb02 100644 --- a/js/test.js +++ b/js/test.js @@ -1031,5 +1031,40 @@ describe('Alert', function () { } ); }); + + describe('showLoading', function () { + before(function () { + cleanup(); + }); + + jsc.property( + 'shows a loding message', + jsc.array(jsc.elements(alnumString)), + jsc.array(jsc.elements(alnumString)), + 'integer', + function (icon, message, number) { + icon = icon.join(''); + message = message.join(''); + var default_message = 'Loading…'; + if (message.length == 0) { + message = default_message; + } + var expected = ''; + $('body').html( + '' + ); + $.PrivateBin.Alert.init(); + $.PrivateBin.Alert.showLoading(message, number, icon); + var result = $('body').html(); + return expected === result; + } + ); + }); }); From 29419d03cd645c7ce2949e6d11738543bb534d89 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Mon, 30 Oct 2017 07:04:59 +0100 Subject: [PATCH 13/33] avoid logs polluting the unit test output --- js/privatebin.js | 16 ++++++++-------- js/test.js | 4 ++-- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index f818b98..c9ff5a8 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -414,7 +414,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { var orgArguments = arguments; $(document).on(languageLoadedEvent, function () { // log to show that the previous error could be mitigated - console.log('Fix missing translation of \'' + messageId + '\' with now loaded language ' + language); + console.warn('Fix missing translation of \'' + messageId + '\' with now loaded language ' + language); // re-execute this function me.translate.apply(this, orgArguments); }); @@ -1100,7 +1100,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { */ me.showStatus = function(message, icon, dismissable, autoclose) { - console.log('status shown: ', message); + console.info('status shown: ', message); // @TODO: implement dismissable // @TODO: implement autoclose @@ -1143,7 +1143,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { */ me.showRemaining = function(message) { - console.log('remaining message shown: ', message); + console.info('remaining message shown: ', message); handleNotification(1, $remainingTime, message); } @@ -1161,7 +1161,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { me.showLoading = function(message, percentage, icon) { if (typeof message !== 'undefined' && message !== null) { - console.log('status changed: ', message); + console.info('status changed: ', message); } // default message text @@ -2656,7 +2656,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { me.showViewButtons = function() { if (viewButtonsDisplayed) { - console.log('showViewButtons: view buttons are already displayed'); + console.warn('showViewButtons: view buttons are already displayed'); return; } @@ -2676,7 +2676,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { me.hideViewButtons = function() { if (!viewButtonsDisplayed) { - console.log('hideViewButtons: view buttons are already hidden'); + console.warn('hideViewButtons: view buttons are already hidden'); return; } @@ -2708,7 +2708,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { me.showCreateButtons = function() { if (createButtonsDisplayed) { - console.log('showCreateButtons: create buttons are already displayed'); + console.warn('showCreateButtons: create buttons are already displayed'); return; } @@ -2733,7 +2733,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { me.hideCreateButtons = function() { if (!createButtonsDisplayed) { - console.log('hideCreateButtons: create buttons are already hidden'); + console.warn('hideCreateButtons: create buttons are already hidden'); return; } diff --git a/js/test.js b/js/test.js index bd0fb02..03b817b 100644 --- a/js/test.js +++ b/js/test.js @@ -25,8 +25,8 @@ global.RawDeflate.inflate = require('./rawinflate-0.3').RawDeflate.inflate; require('./privatebin'); // redirect console messages to log file -console.warn = console.error = function (msg) { - logFile.write(msg + '\n'); +console.info = console.warn = console.error = function () { + logFile.write(Array.prototype.slice.call(arguments).join('') + '\n'); } describe('Helper', function () { diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 036452e..3695fd2 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -69,7 +69,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index 1cae6b3..1f75a60 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -47,7 +47,7 @@ if ($MARKDOWN): - + From 1fd13981d4d18e6a9eef3bee7e9187c25766d6a8 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sat, 4 Nov 2017 07:40:26 +0100 Subject: [PATCH 14/33] adding test for hiding loading indicator --- js/test.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/js/test.js b/js/test.js index 03b817b..2462cc2 100644 --- a/js/test.js +++ b/js/test.js @@ -1038,7 +1038,7 @@ describe('Alert', function () { }); jsc.property( - 'shows a loding message', + 'shows a loading message', jsc.array(jsc.elements(alnumString)), jsc.array(jsc.elements(alnumString)), 'integer', @@ -1066,5 +1066,28 @@ describe('Alert', function () { } ); }); + + describe('hideLoading', function () { + before(function () { + cleanup(); + }); + + it( + 'hides the loading message', + function() { + $('body').html( + '' + ); + $('body').addClass('loading'); + $.PrivateBin.Alert.init(); + $.PrivateBin.Alert.hideLoading(); + return !$('body').hasClass('loading') && + $('#loadingindicator').hasClass('hidden'); + } + ); + }); }); From c6e0f2d22347ae7f9b45482c65c2b307d20e2586 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sat, 4 Nov 2017 07:44:42 +0100 Subject: [PATCH 15/33] adding test for hiding messages --- js/test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/js/test.js b/js/test.js index 2462cc2..f5100af 100644 --- a/js/test.js +++ b/js/test.js @@ -1089,5 +1089,29 @@ describe('Alert', function () { } ); }); + + describe('hideMessages', function () { + before(function () { + cleanup(); + }); + + it( + 'hides all messages', + function() { + $('body').html( + '' + + '' + ); + $.PrivateBin.Alert.init(); + $.PrivateBin.Alert.hideMessages(); + return $('#statusmessage').hasClass('hidden') && + $('#errormessage').hasClass('hidden'); + } + ); + }); }); From 01a6c0142a1a4b4f099a13a585b0bef576fe09b7 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sat, 4 Nov 2017 08:59:31 +0100 Subject: [PATCH 16/33] adding test for alert handler --- js/test.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/js/test.js b/js/test.js index f5100af..78eeb5e 100644 --- a/js/test.js +++ b/js/test.js @@ -1113,5 +1113,53 @@ describe('Alert', function () { } ); }); + + describe('setCustomHandler', function () { + before(function () { + cleanup(); + }); + + jsc.property( + 'calls a given handler function', + 'nat 3', + jsc.array(jsc.elements(alnumString)), + function (trigger, message) { + message = message.join(''); + var handlerCalled = false, + default_message = 'Loading…', + functions = [ + $.PrivateBin.Alert.showStatus, + $.PrivateBin.Alert.showError, + $.PrivateBin.Alert.showRemaining, + $.PrivateBin.Alert.showLoading + ]; + if (message.length == 0) { + message = default_message; + } + $('body').html( + '' + + '' + + '' + + '' + ); + $.PrivateBin.Alert.init(); + $.PrivateBin.Alert.setCustomHandler(function(id, $element) { + handlerCalled = true; + return true; + }); + functions[trigger](message); + return handlerCalled; + } + ); + }); }); From 9af4a4e2f5581642177dd961d0bf7e5b4dd954e1 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sat, 4 Nov 2017 09:02:05 +0100 Subject: [PATCH 17/33] handling JSVerify RNG states 08a8fd9e23076415bc & 8623a0cde74fb19568 --- js/test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/test.js b/js/test.js index 78eeb5e..cf28b40 100644 --- a/js/test.js +++ b/js/test.js @@ -803,8 +803,8 @@ describe('Model', function () { element = element.join(''); value = value.join('').trim(); - //
tags can't contain strings, table tags can't be alone, so test with a

instead - if (['br', 'tr', 'td', 'th'].indexOf(element) >= 0) { + //
,


and tags can't contain strings, table tags can't be alone, so test with a

instead + if (['br', 'hr', 'tr', 'td', 'th', 'wbr'].indexOf(element) >= 0) { element = 'p'; } From e51aa7c80fc46b90bf42e3c56f9c8b4f08638b85 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Mon, 13 Nov 2017 20:44:11 +0100 Subject: [PATCH 18/33] increasing coverage (by three lines) --- js/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/test.js b/js/test.js index cf28b40..3ae74c0 100644 --- a/js/test.js +++ b/js/test.js @@ -1154,7 +1154,7 @@ describe('Alert', function () { $.PrivateBin.Alert.init(); $.PrivateBin.Alert.setCustomHandler(function(id, $element) { handlerCalled = true; - return true; + return jsc.random(0, 1) ? true : $element; }); functions[trigger](message); return handlerCalled; From 6c8f57f91f00b727d2079d616eeaf72d8972d4f6 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Mon, 13 Nov 2017 21:57:49 +0100 Subject: [PATCH 19/33] making PasteStatus testable, adding test for paste creation notification --- js/privatebin.js | 9 +++------ js/test.js | 37 +++++++++++++++++++++++++++++++++++++ tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index c9ff5a8..b673b3c 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -124,7 +124,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { range = document.body.createTextRange(); range.moveToElementText(element); range.select(); - } else if (window.getSelection){ + } else if (window.getSelection) { selection = window.getSelection(); range = document.createRange(); range.selectNodeContents(element); @@ -302,8 +302,6 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { * internationalization module * * @name I18n - * @param {object} window - * @param {object} document * @class */ var I18n = (function () { @@ -1264,10 +1262,9 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { * handles paste status/result * * @name PasteStatus - * @param {object} window * @class */ - var PasteStatus = (function (window) { + var PasteStatus = (function () { var me = {}; var $pasteSuccess, @@ -1410,7 +1407,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { } return me; - })(window); + })(); /** * password prompt diff --git a/js/test.js b/js/test.js index 3ae74c0..316b1a3 100644 --- a/js/test.js +++ b/js/test.js @@ -1163,3 +1163,40 @@ describe('Alert', function () { }); }); +describe('PasteStatus', function () { + describe('createPasteNotification', function () { + this.timeout(30000); + before(function () { + cleanup(); + }); + + jsc.property( + 'creates a notification after a successfull paste upload', + jsc.elements(schemas), + jsc.nearray(jsc.elements(a2zString)), + jsc.array(jsc.elements(queryString)), + 'string', + jsc.elements(schemas), + jsc.nearray(jsc.elements(a2zString)), + jsc.array(jsc.elements(queryString)), + function ( + schema1, address1, query1, fragment1, + schema2, address2, query2 + ) { + var expected1 = schema1 + '://' + address1.join('') + '/?' + + encodeURI(query1.join('') + '#' + fragment1), + expected2 = schema2 + '://' + address2.join('') + '/?' + + encodeURI(query2.join('')), + clean = jsdom(); + $('body').html('

'); + $.PrivateBin.PasteStatus.init(); + $.PrivateBin.PasteStatus.createPasteNotification(expected1, expected2); + var result1 = $('#pasteurl')[0].href, + result2 = $('#deletelink a')[0].href; + clean(); + return result1 == expected1 && result2 == expected2; + } + ); + }); +}); + diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 3695fd2..8c6958b 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -69,7 +69,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index 1f75a60..dc15e28 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -47,7 +47,7 @@ if ($MARKDOWN): - + From 0cfb0196157594841b6028fccdedf94aa6cd6932 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Mon, 13 Nov 2017 22:00:26 +0100 Subject: [PATCH 20/33] handling JSVerify RNG state 0b2b38c4ef690d1a57 --- js/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/test.js b/js/test.js index 316b1a3..73962dc 100644 --- a/js/test.js +++ b/js/test.js @@ -804,7 +804,7 @@ describe('Model', function () { value = value.join('').trim(); //
,
and tags can't contain strings, table tags can't be alone, so test with a

instead - if (['br', 'hr', 'tr', 'td', 'th', 'wbr'].indexOf(element) >= 0) { + if (['br', 'col', 'hr', 'tr', 'td', 'th', 'wbr'].indexOf(element) >= 0) { element = 'p'; } From 478cf288b4869df5d5dd3a60347d30f296aacb7d Mon Sep 17 00:00:00 2001 From: El RIDO Date: Mon, 13 Nov 2017 22:05:29 +0100 Subject: [PATCH 21/33] implementing StyleCI recommendations --- tst/ConfigurationTest.php | 2 +- tst/I18nTest.php | 4 ++-- tst/PrivateBinWithDbTest.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tst/ConfigurationTest.php b/tst/ConfigurationTest.php index 66acece..15b7fd2 100644 --- a/tst/ConfigurationTest.php +++ b/tst/ConfigurationTest.php @@ -142,7 +142,7 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase public function testHandleConfigFileRename() { - $options = $this->_options; + $options = $this->_options; Helper::createIniFile(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini.sample', $options); $options['main']['opendiscussion'] = true; diff --git a/tst/I18nTest.php b/tst/I18nTest.php index c7ded0e..de16349 100644 --- a/tst/I18nTest.php +++ b/tst/I18nTest.php @@ -150,8 +150,8 @@ class I18nTest extends PHPUnit_Framework_TestCase $dir = dir(PATH . 'i18n'); while (false !== ($file = $dir->read())) { if (strlen($file) === 7) { - $language = substr($file, 0, 2); - $languageMessageIds = array_keys( + $language = substr($file, 0, 2); + $languageMessageIds = array_keys( json_decode( file_get_contents(PATH . 'i18n' . DIRECTORY_SEPARATOR . $file), true diff --git a/tst/PrivateBinWithDbTest.php b/tst/PrivateBinWithDbTest.php index a438d4c..25e6082 100644 --- a/tst/PrivateBinWithDbTest.php +++ b/tst/PrivateBinWithDbTest.php @@ -35,7 +35,7 @@ class PrivateBinWithDbTest extends PrivateBinTest $options['model'] = array( 'class' => 'Database', ); - $options['model_options'] = $this->_options; + $options['model_options'] = $this->_options; Helper::createIniFile(CONF, $options); } } From 4652b5af7bf1b7132a50026f4d2cde575f73b702 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Mon, 13 Nov 2017 22:12:31 +0100 Subject: [PATCH 22/33] preferring pre-increment StyleCI recommendation --- .styleci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.styleci.yml b/.styleci.yml index 0c7ba38..8a62bd5 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -3,10 +3,11 @@ preset: recommended risky: false enabled: - - no_empty_comment - align_equals - - long_array_syntax - concat_with_spaces + - long_array_syntax + - no_empty_comment + - pre_increment disabled: - blank_line_after_opening_tag @@ -23,6 +24,7 @@ disabled: - phpdoc_separation - phpdoc_single_line_var_spacing - phpdoc_summary + - post_increment - short_array_syntax - single_line_after_imports - unalign_equals From 86ecdb1155f98019ef88be5ba3cd1096abb8491c Mon Sep 17 00:00:00 2001 From: El RIDO Date: Mon, 13 Nov 2017 22:15:14 +0100 Subject: [PATCH 23/33] fixing post increment --- lib/Filter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Filter.php b/lib/Filter.php index 4c0a22e..302c84c 100644 --- a/lib/Filter.php +++ b/lib/Filter.php @@ -64,7 +64,7 @@ class Filter $i = 0; while (($size / 1024) >= 1) { $size = $size / 1024; - $i++; + ++$i; } return number_format($size, ($i ? 2 : 0), '.', ' ') . ' ' . I18n::_($iec[$i]); } @@ -82,7 +82,7 @@ class Filter public static function slowEquals($a, $b) { $diff = strlen($a) ^ strlen($b); - for ($i = 0; $i < strlen($a) && $i < strlen($b); $i++) { + for ($i = 0; $i < strlen($a) && $i < strlen($b); ++$i) { $diff |= ord($a[$i]) ^ ord($b[$i]); } return $diff === 0; From 73bc6851785e2880864b05213e99e8820a70424d Mon Sep 17 00:00:00 2001 From: El RIDO Date: Tue, 14 Nov 2017 06:52:12 +0100 Subject: [PATCH 24/33] fixing error message display revealed by testing remaining time display function --- js/privatebin.js | 4 ++-- js/test.js | 42 ++++++++++++++++++++++++++++++++++++++++++ tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index b673b3c..b130edd 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -1365,7 +1365,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { ]; Alert.showRemaining([expirationLabel, expiration[0]]); - $remainingTime.removeClass('foryoureyesonly') + $remainingTime.removeClass('foryoureyesonly'); } else { // never expires return; @@ -3982,7 +3982,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { Uploader.setUnencryptedData('deletetoken', deleteToken); Uploader.setFailure(function () { - Controller.showError(I18n._('Could not delete the paste, it was not stored in burn after reading mode.')); + Alert.showError(I18n._('Could not delete the paste, it was not stored in burn after reading mode.')); }) Uploader.run(); } diff --git a/js/test.js b/js/test.js index 73962dc..4d9b6eb 100644 --- a/js/test.js +++ b/js/test.js @@ -1198,5 +1198,47 @@ describe('PasteStatus', function () { } ); }); + + describe('showRemainingTime', function () { + this.timeout(30000); + before(function () { + cleanup(); + }); + + jsc.property( + 'shows burn after reading message or remaining time', + 'bool', + 'nat', + jsc.nearray(jsc.elements(a2zString)), + jsc.nearray(jsc.elements(a2zString)), + jsc.array(jsc.elements(queryString)), + 'string', + function ( + burnafterreading, remaining_time, + schema, address, query, fragment + ) { + var clean = jsdom('', { + url: schema.join('') + '://' + address.join('') + + '/?' + queryString + '#' + fragment + }); + $('body').html('

'); + $.PrivateBin.PasteStatus.init(); + $.PrivateBin.PasteStatus.showRemainingTime({ + 'burnafterreading': burnafterreading, + 'remaining_time': remaining_time, + 'expire_date': ((new Date()).getTime() / 1000) + remaining_time + }); + if (burnafterreading) { + var result = $('#remainingtime').hasClass('foryoureyesonly') && + !$('#remainingtime').hasClass('hidden'); + } else { + var result =!$('#remainingtime').hasClass('foryoureyesonly') && + !$('#remainingtime').hasClass('hidden'); + } + clean(); + return result; + } + ); + }); }); diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 8c6958b..f722ee8 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -69,7 +69,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index dc15e28..0c01437 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -47,7 +47,7 @@ if ($MARKDOWN): - + From b1e18788615c8eb8248e3026a3e48bd1af8d3f6a Mon Sep 17 00:00:00 2001 From: El RIDO Date: Thu, 16 Nov 2017 08:50:38 +0100 Subject: [PATCH 25/33] fully testing remaining time display function --- js/test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/js/test.js b/js/test.js index 4d9b6eb..dfbeb38 100644 --- a/js/test.js +++ b/js/test.js @@ -1226,14 +1226,17 @@ describe('PasteStatus', function () { $.PrivateBin.PasteStatus.showRemainingTime({ 'burnafterreading': burnafterreading, 'remaining_time': remaining_time, - 'expire_date': ((new Date()).getTime() / 1000) + remaining_time + 'expire_date': remaining_time ? ((new Date()).getTime() / 1000) + remaining_time : 0 }); if (burnafterreading) { var result = $('#remainingtime').hasClass('foryoureyesonly') && !$('#remainingtime').hasClass('hidden'); - } else { + } else if (remaining_time) { var result =!$('#remainingtime').hasClass('foryoureyesonly') && !$('#remainingtime').hasClass('hidden'); + } else { + var result = $('#remainingtime').hasClass('hidden') && + !$('#remainingtime').hasClass('foryoureyesonly'); } clean(); return result; From 9d1a9a0da7fdc97c9862ecf95e68a66b6c3f8f66 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Thu, 16 Nov 2017 08:57:08 +0100 Subject: [PATCH 26/33] fixing paste success message handling in page template --- js/privatebin.js | 2 +- tpl/bootstrap.php | 4 ++-- tpl/page.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index b130edd..60db54f 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -1397,7 +1397,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { */ me.init = function() { - $pasteSuccess = $('#pasteSuccess'); + $pasteSuccess = $('#pastesuccess'); // $pasteUrl is saved in me.createPasteNotification() after creation $remainingTime = $('#remainingtime'); $shortenButton = $('#shortenbutton'); diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index f722ee8..aa57490 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -69,7 +69,7 @@ if ($MARKDOWN): - + @@ -434,7 +434,7 @@ endif; Opera, Chrome… -