Merge branch 'js-unit-testing'

pull/173/head
El RIDO 7 years ago
commit 177c9d7114
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92

4
.gitattributes vendored

@ -1,5 +1,9 @@
doc/ export-ignore doc/ export-ignore
tst/ 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 .codeclimate.yml export-ignore
.csslintrc export-ignore .csslintrc export-ignore
.dockerignore export-ignore .dockerignore export-ignore

1
.gitignore vendored

@ -24,6 +24,7 @@ vendor/**/build_phar.php
!vendor/**/*.php !vendor/**/*.php
# Ignore unit testing logs, api docs and eclipse project files # Ignore unit testing logs, api docs and eclipse project files
js/node_modules/
tst/log/ tst/log/
.settings .settings
.buildpath .buildpath

@ -0,0 +1,7 @@
---
instrumentation:
excludes:
- jquery-3.1.1.js
baseline-file: ../tst/log/js-coverage-baseline.json
reporting:
dir: ../tst/log/js-coverage-report

@ -83,7 +83,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
var parameterString = ''; var parameterString = '';
for (var key in hashMap) for (var key in hashMap)
{ {
if(parameterString === '') if (parameterString === '')
{ {
parameterString = encodeURIComponent(key); parameterString = encodeURIComponent(key);
parameterString += '=' + encodeURIComponent(hashMap[key]); parameterString += '=' + encodeURIComponent(hashMap[key]);
@ -95,7 +95,10 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
} }
} }
// padding for URL shorteners // padding for URL shorteners
parameterString += '&p=p'; if (parameterString.length > 0) {
parameterString += '&';
}
parameterString += 'p=p';
return parameterString; return parameterString;
}, },
@ -112,14 +115,15 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
{ {
var parameterHash = {}; var parameterHash = {};
var parameterArray = parameterString.split('&'); var parameterArray = parameterString.split('&');
for (var i = 0; i < parameterArray.length; i++) if (parameterArray[0] != '') {
{ for (var i = 0; i < parameterArray.length; i++)
var pair = parameterArray[i].split('='); {
var key = decodeURIComponent(pair[0]); var pair = parameterArray[i].split('=');
var value = decodeURIComponent(pair[1]); var key = decodeURIComponent(pair[0]);
parameterHash[key] = value; var value = decodeURIComponent(pair[1]);
parameterHash[key] = value;
}
} }
return parameterHash; return parameterHash;
}, },
@ -602,14 +606,14 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* PrivateBin logic * PrivateBin logic
* *
* @name privatebin * @name controller
* @class * @class
*/ */
var privatebin = { var controller = {
/** /**
* headers to send in AJAX requests * headers to send in AJAX requests
* *
* @name privatebin.headers * @name controller.headers
* @enum {Object} * @enum {Object}
*/ */
headers: {'X-Requested-With': 'JSONHttpRequest'}, headers: {'X-Requested-With': 'JSONHttpRequest'},
@ -617,7 +621,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* URL shortners create address * URL shortners create address
* *
* @name privatebin.shortenerUrl * @name controller.shortenerUrl
* @prop {string} * @prop {string}
*/ */
shortenerUrl: '', shortenerUrl: '',
@ -625,7 +629,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* URL of newly created paste * URL of newly created paste
* *
* @name privatebin.createdPasteUrl * @name controller.createdPasteUrl
* @prop {string} * @prop {string}
*/ */
createdPasteUrl: '', createdPasteUrl: '',
@ -634,7 +638,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
* get the current script location (without search or hash part of the URL), * get the current script location (without search or hash part of the URL),
* eg. http://example.com/zero/?aaaa#bbbb --> http://example.com/zero/ * eg. http://example.com/zero/?aaaa#bbbb --> http://example.com/zero/
* *
* @name privatebin.scriptLocation * @name controller.scriptLocation
* @function * @function
* @return {string} current script location * @return {string} current script location
*/ */
@ -654,7 +658,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
* get the pastes unique identifier from the URL, * get the pastes unique identifier from the URL,
* eg. http://example.com/zero/?c05354954c49a487#c05354954c49a487 returns c05354954c49a487 * eg. http://example.com/zero/?c05354954c49a487#c05354954c49a487 returns c05354954c49a487
* *
* @name privatebin.pasteID * @name controller.pasteID
* @function * @function
* @return {string} unique identifier * @return {string} unique identifier
*/ */
@ -666,7 +670,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* return the deciphering key stored in anchor part of the URL * return the deciphering key stored in anchor part of the URL
* *
* @name privatebin.pageKey * @name controller.pageKey
* @function * @function
* @return {string} key * @return {string} key
*/ */
@ -703,7 +707,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* ask the user for the password and set it * ask the user for the password and set it
* *
* @name privatebin.requestPassword * @name controller.requestPassword
* @function * @function
*/ */
requestPassword: function() requestPassword: function()
@ -729,7 +733,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* use given format on paste, defaults to plain text * use given format on paste, defaults to plain text
* *
* @name privatebin.formatPaste * @name controller.formatPaste
* @function * @function
* @param {string} format * @param {string} format
* @param {string} text * @param {string} text
@ -789,7 +793,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* show decrypted text in the display area, including discussion (if open) * show decrypted text in the display area, including discussion (if open)
* *
* @name privatebin.displayMessages * @name controller.displayMessages
* @function * @function
* @param {Object} [paste] - (optional) object including comments to display (items = array with keys ('data','meta')) * @param {Object} [paste] - (optional) object including comments to display (items = array with keys ('data','meta'))
*/ */
@ -893,7 +897,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
headers: this.headers headers: this.headers
}) })
.fail(function() { .fail(function() {
privatebin.showError(i18n._('Could not delete the paste, it was not stored in burn after reading mode.')); controller.showError(i18n._('Could not delete the paste, it was not stored in burn after reading mode.'));
}); });
helper.setMessage(this.remainingTime, i18n._( helper.setMessage(this.remainingTime, i18n._(
'FOR YOUR EYES ONLY. Don\'t close this window, this message can\'t be displayed again.' 'FOR YOUR EYES ONLY. Don\'t close this window, this message can\'t be displayed again.'
@ -970,7 +974,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* open the comment entry when clicking the "Reply" button of a comment * open the comment entry when clicking the "Reply" button of a comment
* *
* @name privatebin.openReply * @name controller.openReply
* @function * @function
* @param {Event} event * @param {Event} event
*/ */
@ -999,7 +1003,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* send a reply in a discussion * send a reply in a discussion
* *
* @name privatebin.sendComment * @name controller.sendComment
* @function * @function
* @param {Event} event * @param {Event} event
*/ */
@ -1040,51 +1044,51 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
{ {
if (data.status === 0) if (data.status === 0)
{ {
privatebin.showStatus(i18n._('Comment posted.')); controller.showStatus(i18n._('Comment posted.'));
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: privatebin.scriptLocation() + '?' + privatebin.pasteID(), url: controller.scriptLocation() + '?' + controller.pasteID(),
dataType: 'json', dataType: 'json',
headers: privatebin.headers, headers: controller.headers,
success: function(data) success: function(data)
{ {
if (data.status === 0) if (data.status === 0)
{ {
privatebin.displayMessages(data); controller.displayMessages(data);
} }
else if (data.status === 1) else if (data.status === 1)
{ {
privatebin.showError(i18n._('Could not refresh display: %s', data.message)); controller.showError(i18n._('Could not refresh display: %s', data.message));
} }
else else
{ {
privatebin.showError(i18n._('Could not refresh display: %s', i18n._('unknown status'))); controller.showError(i18n._('Could not refresh display: %s', i18n._('unknown status')));
} }
} }
}) })
.fail(function() { .fail(function() {
privatebin.showError(i18n._('Could not refresh display: %s', i18n._('server error or not responding'))); controller.showError(i18n._('Could not refresh display: %s', i18n._('server error or not responding')));
}); });
} }
else if (data.status === 1) else if (data.status === 1)
{ {
privatebin.showError(i18n._('Could not post comment: %s', data.message)); controller.showError(i18n._('Could not post comment: %s', data.message));
} }
else else
{ {
privatebin.showError(i18n._('Could not post comment: %s', i18n._('unknown status'))); controller.showError(i18n._('Could not post comment: %s', i18n._('unknown status')));
} }
} }
}) })
.fail(function() { .fail(function() {
privatebin.showError(i18n._('Could not post comment: %s', i18n._('server error or not responding'))); controller.showError(i18n._('Could not post comment: %s', i18n._('server error or not responding')));
}); });
}, },
/** /**
* send a new paste to server * send a new paste to server
* *
* @name privatebin.sendData * @name controller.sendData
* @function * @function
* @param {Event} event * @param {Event} event
*/ */
@ -1128,7 +1132,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
reader.onload = (function(theFile) reader.onload = (function(theFile)
{ {
return function(e) { return function(e) {
privatebin.sendDataContinue( controller.sendDataContinue(
randomkey, randomkey,
filter.cipher(randomkey, password, e.target.result), filter.cipher(randomkey, password, e.target.result),
filter.cipher(randomkey, password, theFile.name) filter.cipher(randomkey, password, theFile.name)
@ -1154,7 +1158,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* send a new paste to server, step 2 * send a new paste to server, step 2
* *
* @name privatebin.sendDataContinue * @name controller.sendDataContinue
* @function * @function
* @param {string} randomkey * @param {string} randomkey
* @param {string} cipherdata_attachment * @param {string} cipherdata_attachment
@ -1187,49 +1191,49 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
success: function(data) success: function(data)
{ {
if (data.status === 0) { if (data.status === 0) {
privatebin.stateExistingPaste(); controller.stateExistingPaste();
var url = privatebin.scriptLocation() + '?' + data.id + '#' + randomkey; var url = controller.scriptLocation() + '?' + data.id + '#' + randomkey;
var deleteUrl = privatebin.scriptLocation() + '?pasteid=' + data.id + '&deletetoken=' + data.deletetoken; var deleteUrl = controller.scriptLocation() + '?pasteid=' + data.id + '&deletetoken=' + data.deletetoken;
privatebin.showStatus(''); controller.showStatus('');
privatebin.errorMessage.addClass('hidden'); controller.errorMessage.addClass('hidden');
$('#pastelink').html( $('#pastelink').html(
i18n._( i18n._(
'Your paste is <a id="pasteurl" href="%s">%s</a> <span id="copyhint">(Hit [Ctrl]+[c] to copy)</span>', 'Your paste is <a id="pasteurl" href="%s">%s</a> <span id="copyhint">(Hit [Ctrl]+[c] to copy)</span>',
url, url url, url
) + privatebin.shortenUrl(url) ) + controller.shortenUrl(url)
); );
var shortenButton = $('#shortenbutton'); var shortenButton = $('#shortenbutton');
if (shortenButton) { if (shortenButton) {
shortenButton.click($.proxy(privatebin.sendToShortener, privatebin)); shortenButton.click($.proxy(controller.sendToShortener, controller));
} }
$('#deletelink').html('<a href="' + deleteUrl + '">' + i18n._('Delete data') + '</a>'); $('#deletelink').html('<a href="' + deleteUrl + '">' + i18n._('Delete data') + '</a>');
privatebin.pasteResult.removeClass('hidden'); controller.pasteResult.removeClass('hidden');
// we pre-select the link so that the user only has to [Ctrl]+[c] the link // we pre-select the link so that the user only has to [Ctrl]+[c] the link
helper.selectText('pasteurl'); helper.selectText('pasteurl');
privatebin.showStatus(''); controller.showStatus('');
privatebin.formatPaste(data_to_send.formatter, privatebin.message.val()); controller.formatPaste(data_to_send.formatter, controller.message.val());
} }
else if (data.status === 1) else if (data.status === 1)
{ {
privatebin.showError(i18n._('Could not create paste: %s', data.message)); controller.showError(i18n._('Could not create paste: %s', data.message));
} }
else else
{ {
privatebin.showError(i18n._('Could not create paste: %s', i18n._('unknown status'))); controller.showError(i18n._('Could not create paste: %s', i18n._('unknown status')));
} }
} }
}) })
.fail(function() .fail(function()
{ {
privatebin.showError(i18n._('Could not create paste: %s', i18n._('server error or not responding'))); controller.showError(i18n._('Could not create paste: %s', i18n._('server error or not responding')));
}); });
}, },
/** /**
* check if a URL shortener was defined and create HTML containing a link to it * check if a URL shortener was defined and create HTML containing a link to it
* *
* @name privatebin.shortenUrl * @name controller.shortenUrl
* @function * @function
* @param {string} url * @param {string} url
* @return {string} html * @return {string} html
@ -1248,7 +1252,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* put the screen in "New paste" mode * put the screen in "New paste" mode
* *
* @name privatebin.stateNewPaste * @name controller.stateNewPaste
* @function * @function
*/ */
stateNewPaste: function() stateNewPaste: function()
@ -1278,7 +1282,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* put the screen in "Existing paste" mode * put the screen in "Existing paste" mode
* *
* @name privatebin.stateExistingPaste * @name controller.stateExistingPaste
* @function * @function
* @param {boolean} [preview=false] - (optional) tell if the preview tabs should be displayed, defaults to false * @param {boolean} [preview=false] - (optional) tell if the preview tabs should be displayed, defaults to false
*/ */
@ -1318,7 +1322,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* when "burn after reading" is checked, disable discussion * when "burn after reading" is checked, disable discussion
* *
* @name privatebin.changeBurnAfterReading * @name controller.changeBurnAfterReading
* @function * @function
*/ */
changeBurnAfterReading: function() changeBurnAfterReading: function()
@ -1338,7 +1342,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* when discussion is checked, disable "burn after reading" * when discussion is checked, disable "burn after reading"
* *
* @name privatebin.changeOpenDisc * @name controller.changeOpenDisc
* @function * @function
*/ */
changeOpenDisc: function() changeOpenDisc: function()
@ -1358,7 +1362,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* forward to URL shortener * forward to URL shortener
* *
* @name privatebin.sendToShortener * @name controller.sendToShortener
* @function * @function
* @param {Event} event * @param {Event} event
*/ */
@ -1371,7 +1375,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* reload the page * reload the page
* *
* @name privatebin.reloadPage * @name controller.reloadPage
* @function * @function
* @param {Event} event * @param {Event} event
*/ */
@ -1384,7 +1388,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* return raw text * return raw text
* *
* @name privatebin.rawText * @name controller.rawText
* @function * @function
* @param {Event} event * @param {Event} event
*/ */
@ -1407,7 +1411,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* clone the current paste * clone the current paste
* *
* @name privatebin.clonePaste * @name controller.clonePaste
* @function * @function
* @param {Event} event * @param {Event} event
*/ */
@ -1435,7 +1439,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* set the expiration on bootstrap templates * set the expiration on bootstrap templates
* *
* @name privatebin.setExpiration * @name controller.setExpiration
* @function * @function
* @param {Event} event * @param {Event} event
*/ */
@ -1450,7 +1454,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* set the format on bootstrap templates * set the format on bootstrap templates
* *
* @name privatebin.setFormat * @name controller.setFormat
* @function * @function
* @param {Event} event * @param {Event} event
*/ */
@ -1469,7 +1473,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* set the language in a cookie and reload the page * set the language in a cookie and reload the page
* *
* @name privatebin.setLanguage * @name controller.setLanguage
* @function * @function
* @param {Event} event * @param {Event} event
*/ */
@ -1482,7 +1486,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* support input of tab character * support input of tab character
* *
* @name privatebin.supportTabs * @name controller.supportTabs
* @function * @function
* @param {Event} event * @param {Event} event
*/ */
@ -1508,7 +1512,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* view the editor tab * view the editor tab
* *
* @name privatebin.viewEditor * @name controller.viewEditor
* @function * @function
* @param {Event} event * @param {Event} event
*/ */
@ -1524,7 +1528,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* view the preview tab * view the preview tab
* *
* @name privatebin.viewPreview * @name controller.viewPreview
* @function * @function
* @param {Event} event * @param {Event} event
*/ */
@ -1541,7 +1545,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* create a new paste * create a new paste
* *
* @name privatebin.newPaste * @name controller.newPaste
* @function * @function
*/ */
newPaste: function() newPaste: function()
@ -1556,7 +1560,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* removes an attachment * removes an attachment
* *
* @name privatebin.removeAttachment * @name controller.removeAttachment
* @function * @function
*/ */
removeAttachment: function() removeAttachment: function()
@ -1572,7 +1576,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* decrypt using the password from the modal dialog * decrypt using the password from the modal dialog
* *
* @name privatebin.decryptPasswordModal * @name controller.decryptPasswordModal
* @function * @function
*/ */
decryptPasswordModal: function() decryptPasswordModal: function()
@ -1584,7 +1588,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* submit a password in the modal dialog * submit a password in the modal dialog
* *
* @name privatebin.submitPasswordModal * @name controller.submitPasswordModal
* @function * @function
* @param {Event} event * @param {Event} event
*/ */
@ -1598,7 +1602,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
* display an error message, * display an error message,
* we use the same function for paste and reply to comments * we use the same function for paste and reply to comments
* *
* @name privatebin.showError * @name controller.showError
* @function * @function
* @param {string} message - text to display * @param {string} message - text to display
*/ */
@ -1631,7 +1635,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
* display a status message, * display a status message,
* we use the same function for paste and reply to comments * we use the same function for paste and reply to comments
* *
* @name privatebin.showStatus * @name controller.showStatus
* @function * @function
* @param {string} message - text to display * @param {string} message - text to display
* @param {boolean} [spin=false] - (optional) tell if the "spinning" animation should be displayed, defaults to false * @param {boolean} [spin=false] - (optional) tell if the "spinning" animation should be displayed, defaults to false
@ -1665,7 +1669,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* bind events to DOM elements * bind events to DOM elements
* *
* @name privatebin.bindEvents * @name controller.bindEvents
* @function * @function
*/ */
bindEvents: function() bindEvents: function()
@ -1698,7 +1702,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
/** /**
* main application * main application
* *
* @name privatebin.init * @name controller.init
* @function * @function
*/ */
init: function() init: function()
@ -1782,17 +1786,16 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
} }
} }
/**
* main application start, called when DOM is fully loaded and
* runs controller initalization after translations are loaded
*/
$(i18n.loadTranslations($.proxy(controller.init, controller)));
return { return {
helper: helper, helper: helper,
i18n: i18n, i18n: i18n,
filter: filter, filter: filter,
privatebin: privatebin controller: controller
}; };
}(jQuery, sjcl, Base64, RawDeflate); }(jQuery, sjcl, Base64, RawDeflate);
/**
* main application start, called when DOM is fully loaded
* runs privatebin when translations were loaded
*/
jQuery(jQuery.PrivateBin.i18n.loadTranslations(jQuery.proxy(jQuery.PrivateBin.privatebin.init, jQuery.PrivateBin.privatebin)));

@ -0,0 +1,78 @@
'use strict';
var jsc = require('jsverify');
before(function () {
this.jsdom = require('jsdom-global')();
global.$ = global.jQuery = require('./jquery-3.1.1');
global.sjcl = require('./sjcl-1.0.4');
global.Base64 = require('./base64-2.1.9');
global.RawDeflate = require('./rawdeflate-0.5');
require('./rawinflate-0.3');
require('./privatebin');
})
after(function () {
this.jsdom();
})
describe('helper', function () {
describe('secondsToHuman', function () {
jsc.property('returns an array with a number and a word', 'integer', function (number) {
var result = $.PrivateBin.helper.secondsToHuman(number);
return Array.isArray(result) &&
result.length === 2 &&
result[0] === parseInt(result[0], 10) &&
typeof result[1] === 'string';
});
jsc.property('returns seconds on the first array position', 'integer 59', function (number) {
return $.PrivateBin.helper.secondsToHuman(number)[0] === number;
});
jsc.property('returns seconds on the second array position', 'integer 59', function (number) {
return $.PrivateBin.helper.secondsToHuman(number)[1] === 'second';
});
jsc.property('returns minutes on the first array position', 'integer 60 3599', function (number) {
return $.PrivateBin.helper.secondsToHuman(number)[0] === Math.floor(number / 60);
});
jsc.property('returns minutes on the second array position', 'integer 60 3599', function (number) {
return $.PrivateBin.helper.secondsToHuman(number)[1] === 'minute';
});
jsc.property('returns hours on the first array position', 'integer 3600 86399', function (number) {
return $.PrivateBin.helper.secondsToHuman(number)[0] === Math.floor(number / (60 * 60));
});
jsc.property('returns hours on the second array position', 'integer 3600 86399', function (number) {
return $.PrivateBin.helper.secondsToHuman(number)[1] === 'hour';
});
jsc.property('returns days on the first array position', 'integer 86400 5184000', function (number) {
return $.PrivateBin.helper.secondsToHuman(number)[0] === Math.floor(number / (60 * 60 * 24));
});
jsc.property('returns days on the second array position', 'integer 86400 5184000', function (number) {
return $.PrivateBin.helper.secondsToHuman(number)[1] === 'day';
});
// max safe integer as per http://ecma262-5.com/ELS5_HTML.htm#Section_8.5
jsc.property('returns months on the first array position', 'integer 5184000 9007199254740991', function (number) {
return $.PrivateBin.helper.secondsToHuman(number)[0] === Math.floor(number / (60 * 60 * 24 * 30));
});
jsc.property('returns months on the second array position', 'integer 5184000 9007199254740991', function (number) {
return $.PrivateBin.helper.secondsToHuman(number)[1] === 'month';
});
});
describe('hashToParameterString', function () {
jsc.property('returns strings', 'dict nestring', function (dict) {
return typeof $.PrivateBin.helper.hashToParameterString(dict) === 'string';
});
});
describe('parameterStringToHash', function () {
jsc.property('returns objects', 'string', function (string) {
return typeof $.PrivateBin.helper.parameterStringToHash(string) === 'object';
});
jsc.property('decodes hashes generated with hashToParameterString', 'dict nestring', function (dict) {
var result = $.PrivateBin.helper.parameterStringToHash($.PrivateBin.helper.hashToParameterString(dict));
// padding for URL shorteners
dict.p = 'p';
return JSON.stringify(result) === JSON.stringify(dict);
});
});
});

@ -69,7 +69,7 @@ if ($MARKDOWN):
<?php <?php
endif; endif;
?> ?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-BQtm9WwSHdMAGNuJYDpAICZGADZxANQ2DkJ6cXnWHlemnTq3xtdL+7cYoB/0no9Aa+PnA7JLvNTQWa+g2hIawA==" crossorigin="anonymous"></script> <script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-QZEnEp9v6HlbXEk7sCcLLWxC9mkIaoK5LIX9bp5UxYQG7q/wDPZvcAP0nwr51BXlDTG4fAeSjVsLpSAxGNdBxw==" crossorigin="anonymous"></script>
<!--[if lt IE 10]> <!--[if lt IE 10]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style> <style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
<![endif]--> <![endif]-->

@ -47,7 +47,7 @@ if ($MARKDOWN):
<?php <?php
endif; endif;
?> ?>
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-BQtm9WwSHdMAGNuJYDpAICZGADZxANQ2DkJ6cXnWHlemnTq3xtdL+7cYoB/0no9Aa+PnA7JLvNTQWa+g2hIawA==" crossorigin="anonymous"></script> <script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-QZEnEp9v6HlbXEk7sCcLLWxC9mkIaoK5LIX9bp5UxYQG7q/wDPZvcAP0nwr51BXlDTG4fAeSjVsLpSAxGNdBxw==" crossorigin="anonymous"></script>
<!--[if lt IE 10]> <!--[if lt IE 10]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style> <style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
<![endif]--> <![endif]-->

@ -1,20 +1,56 @@
Running unit tests Running PHP unit tests
================== ======================
In order to run these tests, you will need to install the following packages In order to run these tests, you will need to install the following packages
and its dependencies: and its dependencies:
* phpunit * phpunit
* php-gd * php-gd
* php-sqlite3 * php-sqlite3
* php-xdebug * php-xdebug (for code coverage reports)
Example for Debian and Ubuntu: Example for Debian and Ubuntu:
```sh ```console
$ sudo aptitude install phpunit php-gd php-sqlite php-xdebug $ sudo apt install phpunit php-gd php-sqlite php-xdebug
``` ```
To run the tests, just change into this directory and run phpunit: To run the tests, just change into this directory and run phpunit:
```sh ```console
$ cd PrivateBin/tst $ cd PrivateBin/tst
$ phpunit $ phpunit
``` ```
Running JavaScript unit tests
=============================
In order to run these tests, you will need to install the following packages
and its dependencies:
* npm
Then you can use the node package manager to install the latest stable release
of mocha and istanbul (for code coverage reports) globally and jsVerify, jsdom
and jsdom-global locally:
```console
$ npm install -g mocha istanbul
$ cd PrivateBin/js
$ npm install jsverify jsdom jsdom-global
```
Example for Debian and Ubuntu, including steps to allow current user to install
node modules globally:
```console
$ sudo apt install npm
$ sudo mkdir /usr/local/lib/node_modules
$ sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
$ ln -s /usr/bin/nodejs /usr/local/bin/node
$ npm install -g mocha istanbul
$ cd PrivateBin/js
$ npm install jsverify jsdom jsdom-global
```
To run the tests, just change into the `js` directory and run istanbul:
```console
$ cd PrivateBin/js
$ istanbul cover _mocha
```

@ -13,7 +13,7 @@
</filter> </filter>
<logging> <logging>
<log type="coverage-clover" target="log/coverage-clover.xml" /> <log type="coverage-clover" target="log/coverage-clover.xml" />
<log type="coverage-html" target="log/coverage-report" charset="UTF-8" yui="true" highlight="true" lowUpperBound="50" highLowerBound="80" /> <log type="coverage-html" target="log/php-coverage-report" charset="UTF-8" yui="true" highlight="true" lowUpperBound="50" highLowerBound="80" />
<log type="testdox-html" target="log/testdox.html" /> <log type="testdox-html" target="log/testdox.html" />
</logging> </logging>
</phpunit> </phpunit>

Loading…
Cancel
Save