From a8c1605aca9d1bce361c54692184e84e506c305d Mon Sep 17 00:00:00 2001 From: Nate Wright Date: Thu, 8 Nov 2018 14:06:25 +0000 Subject: [PATCH] pkp/pkp-lib#3594 Fix tests - Fix JS validation errors - Do not use sudo when installing linter because npm is not available to sudo - Update help file validation to expect filenames without .md - Add WebTestCase method to set input values and trigger Vue data sync - Replace use of ->getSetting() method - Use faster method for checking tinyMCE initialization in tests - Restore ValidatorURI class used in metadata test --- classes/user/form/RegistrationForm.inc.php | 8 ++- classes/validation/ValidatorUri.inc.php | 53 +++++++++++++++++++ js/controllers/HelpPanelHandler.js | 3 +- js/controllers/SiteHandler.js | 8 +-- js/controllers/modal/ModalHandler.js | 22 +++++--- .../tab/workflow/WorkflowTabHandler.js | 1 + .../controllers/tab/workflow/editorial.tpl | 2 +- templates/controllers/tab/workflow/review.tpl | 2 +- .../controllers/tab/workflow/submission.tpl | 2 +- tests/WebTestCase.inc.php | 39 +++++++++++--- tools/checkHelp.sh | 4 +- tools/closure-externs.js | 4 +- tools/travis/validate-json.sh | 2 +- 13 files changed, 121 insertions(+), 29 deletions(-) create mode 100644 classes/validation/ValidatorUri.inc.php diff --git a/classes/user/form/RegistrationForm.inc.php b/classes/user/form/RegistrationForm.inc.php index fcf35877d2a..b2e1875d7e3 100644 --- a/classes/user/form/RegistrationForm.inc.php +++ b/classes/user/form/RegistrationForm.inc.php @@ -69,7 +69,7 @@ function __construct($site) { } $context = Application::getRequest()->getContext(); - if ($context && $context->getSetting('privacyStatement')) { + if ($context && $context->getData('privacyStatement')) { $this->addCheck(new FormValidator($this, 'privacyConsent', 'required', 'user.profile.form.privacyConsentRequired')); } @@ -106,7 +106,7 @@ function fetch($request, $template = null, $display = false) { 'source' =>$request->getUserVar('source'), 'minPasswordLength' => $site->getMinPasswordLength(), 'enableSiteWidePrivacyStatement' => Config::getVar('general', 'sitewide_privacy_statement'), - 'siteWidePrivacyStatement' => $site->getSetting('privacyStatement'), + 'siteWidePrivacyStatement' => $site->getData('privacyStatement'), )); return parent::fetch($request, $template, $display); @@ -167,7 +167,7 @@ function validate() { // group signups if we're in the site-wide registration form if (!$request->getContext()) { - if ($request->getSite()->getSetting('privacyStatement')) { + if ($request->getSite()->getData('privacyStatement')) { $privacyConsent = $this->getData('privacyConsent'); if (!is_array($privacyConsent) || !array_key_exists(CONTEXT_ID_NONE, $privacyConsent)) { $this->addError('privacyConsent[' . CONTEXT_ID_NONE . ']', __('user.register.form.missingSiteConsent')); @@ -343,5 +343,3 @@ function _setMailFrom($request, $mail) { } } } - - diff --git a/classes/validation/ValidatorUri.inc.php b/classes/validation/ValidatorUri.inc.php new file mode 100644 index 00000000000..65006ac4fe7 --- /dev/null +++ b/classes/validation/ValidatorUri.inc.php @@ -0,0 +1,53 @@ +allowedSchemes)) { + $isAllowed = false; + foreach ($this->allowedSchemes as $scheme) { + if (substr($value, 0, strlen($scheme)) === $scheme) { + $isAllowed = true; + break; + } + } + } + + return $isAllowed; + } +} diff --git a/js/controllers/HelpPanelHandler.js b/js/controllers/HelpPanelHandler.js index e968bc1cbac..728de144957 100644 --- a/js/controllers/HelpPanelHandler.js +++ b/js/controllers/HelpPanelHandler.js @@ -159,7 +159,8 @@ * @param {Event} event The event triggered on this handler * @param {{ * caller: jQueryObject, - * topic: string + * topic: string, + * section: string * }} options The options with which to open this handler */ $.pkp.controllers.HelpPanelHandler.prototype.openPanel_ = diff --git a/js/controllers/SiteHandler.js b/js/controllers/SiteHandler.js index 8722a6f9fb7..2214088a832 100644 --- a/js/controllers/SiteHandler.js +++ b/js/controllers/SiteHandler.js @@ -141,12 +141,14 @@ '/plugins/generic/tinymce/plugins/pkpWordcount/plugin.js'); - var contentCSS = $.pkp.app.tinyMceContentCSS; + var contentCSS = $.pkp.app.tinyMceContentCSS, + tinymceParams, + tinymceParamDefaults; if ($.pkp.app.cdnEnabled) { contentCSS = contentCSS + ', ' + $.pkp.app.tinyMceContentFont; } - var tinymceParams, tinymceParamDefaults = { + tinymceParamDefaults = { width: '100%', resize: 'both', entity_encoding: 'raw', @@ -646,7 +648,7 @@ */ $.pkp.controllers.SiteHandler.prototype.handleNotifyEvent = function(caller, settings) { - pnotify = new PNotify(settings); + var pnotify = new PNotify(settings); }; diff --git a/js/controllers/modal/ModalHandler.js b/js/controllers/modal/ModalHandler.js index ce574b12e2c..2c77232eafd 100644 --- a/js/controllers/modal/ModalHandler.js +++ b/js/controllers/modal/ModalHandler.js @@ -1,3 +1,4 @@ +/*global pkp */ /** * @defgroup js_controllers_modal */ @@ -44,7 +45,8 @@ // Merge user and default options. this.options = /** @type {{ canClose: boolean, title: string, - titleIcon: string }} */ (this.mergeOptions(internalOptions)); + titleIcon: string, closeCleanVueInstances: Array }} */ + (this.mergeOptions(internalOptions)); // Attach content to the modal $handledElement.html(this.modalBuild()[0].outerHTML); @@ -251,11 +253,17 @@ $modalElement.removeClass('is_visible'); this.trigger('pkpModalClose'); setTimeout(function() { - if (modalHandler.options.closeCleanVueInstances.length) { - for (var i = 0; i < modalHandler.options.closeCleanVueInstances.length; i++) { - var id = modalHandler.options.closeCleanVueInstances[i]; + var vueInstances = modalHandler.options.closeCleanVueInstances, + instance, + i, + id; + if (vueInstances.length) { + for (i = 0; i < vueInstances.length; i++) { + id = vueInstances[i]; if (typeof pkp.registry._instances[id] !== 'undefined') { - pkp.registry._instances[id].$destroy(); + instance = /** @type {{ $destroy: Function }} */ + pkp.registry._instances[id]; + instance.$destroy(); } } } @@ -328,8 +336,8 @@ * from a child form has been fired, and this form matches the config id * * @param {Object} source The Vue.js component which fired the event - * @param {Object} data Data attached to the event, which will include the - * form id. + * @param {Object} formId The form component's id prop + * @private */ $.pkp.controllers.modal.ModalHandler.prototype.onFormSuccess_ = function(source, formId) { diff --git a/js/controllers/tab/workflow/WorkflowTabHandler.js b/js/controllers/tab/workflow/WorkflowTabHandler.js index f1a590897a3..fbc65b0d630 100644 --- a/js/controllers/tab/workflow/WorkflowTabHandler.js +++ b/js/controllers/tab/workflow/WorkflowTabHandler.js @@ -20,6 +20,7 @@ $.pkp.controllers.tab = $.pkp.controllers.tab || {}; + /** @type {Object} */ $.pkp.controllers.tab.workflow = $.pkp.controllers.tab.workflow || {}; diff --git a/templates/controllers/tab/workflow/editorial.tpl b/templates/controllers/tab/workflow/editorial.tpl index c182088990e..8d098c17a13 100644 --- a/templates/controllers/tab/workflow/editorial.tpl +++ b/templates/controllers/tab/workflow/editorial.tpl @@ -12,7 +12,7 @@ {include file="controllers/notification/inPlaceNotification.tpl" notificationId="editingNotification_"|concat:$submission->getId() requestOptions=$editingNotificationRequestOptions refreshOn="stageStatusUpdated"} {* Help Link *} - {help file="editorial-workflow/copyediting.md" class="pkp_help_tab"} + {help file="editorial-workflow/copyediting" class="pkp_help_tab"}
{capture assign=copyeditingEditorDecisionsUrl}{url router=$smarty.const.ROUTE_PAGE page="workflow" op="editorDecisionActions" submissionId=$submission->getId() stageId=$stageId escape=false}{/capture} diff --git a/templates/controllers/tab/workflow/review.tpl b/templates/controllers/tab/workflow/review.tpl index 04bd96ffe1b..31ea538dd7f 100644 --- a/templates/controllers/tab/workflow/review.tpl +++ b/templates/controllers/tab/workflow/review.tpl @@ -9,7 +9,7 @@ *} {* Help tab *} -{help file="editorial-workflow/review.md" class="pkp_help_tab"} +{help file="editorial-workflow/review" class="pkp_help_tab"}