Skip to content

Commit

Permalink
#3594 Fix tests
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
NateWr committed Nov 8, 2018
1 parent 5093ea5 commit a8c1605
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 29 deletions.
8 changes: 3 additions & 5 deletions classes/user/form/RegistrationForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -343,5 +343,3 @@ function _setMailFrom($request, $mail) {
}
}
}


53 changes: 53 additions & 0 deletions classes/validation/ValidatorUri.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/**
* @file classes/validation/ValidatorUrI.inc.php
*
* Copyright (c) 2014-2018 Simon Fraser University
* Copyright (c) 2000-2018 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class ValidatorUrl
* @ingroup validation
* @see Validator
*
* @brief Validation check for URLs with an additional check for ipv4 syntax and
* the ability to restrict to specific schemes (ftp, etc)
*/

import ('lib.pkp.classes.validation.ValidatorUri');
import('lib.pkp.classes.validation.ValidatorFactory');

class ValidatorUrl extends ValidatorUri {
/** @var array */
public $allowedSchemes = [];

/**
* Constructor.
* @param $allowedSchemes array
*/
function __construct($allowedSchemes = null) {
parent::__construct(ValidatorUri::getRegexp($allowedSchemes));
}

/**
* @copydoc Validator::isValid()
*/
function isValid($value) {
if (!parent::isValid($value)) {
return false;
}

if (!empty($this->allowedSchemes)) {
$isAllowed = false;
foreach ($this->allowedSchemes as $scheme) {
if (substr($value, 0, strlen($scheme)) === $scheme) {
$isAllowed = true;
break;
}
}
}

return $isAllowed;
}
}
3 changes: 2 additions & 1 deletion js/controllers/HelpPanelHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_ =
Expand Down
8 changes: 5 additions & 3 deletions js/controllers/SiteHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -646,7 +648,7 @@
*/
$.pkp.controllers.SiteHandler.prototype.handleNotifyEvent =
function(caller, settings) {
pnotify = new PNotify(settings);
var pnotify = new PNotify(settings);
};


Expand Down
22 changes: 15 additions & 7 deletions js/controllers/modal/ModalHandler.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*global pkp */
/**
* @defgroup js_controllers_modal
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions js/controllers/tab/workflow/WorkflowTabHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
$.pkp.controllers.tab =
$.pkp.controllers.tab || {};


/** @type {Object} */
$.pkp.controllers.tab.workflow =
$.pkp.controllers.tab.workflow || {};
Expand Down
2 changes: 1 addition & 1 deletion templates/controllers/tab/workflow/editorial.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

<div class="pkp_context_sidebar">
{capture assign=copyeditingEditorDecisionsUrl}{url router=$smarty.const.ROUTE_PAGE page="workflow" op="editorDecisionActions" submissionId=$submission->getId() stageId=$stageId escape=false}{/capture}
Expand Down
2 changes: 1 addition & 1 deletion templates/controllers/tab/workflow/review.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

<script type="text/javascript">
// Attach the JS file tab handler.
Expand Down
2 changes: 1 addition & 1 deletion templates/controllers/tab/workflow/submission.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*}

{* Help Link *}
{help file="editorial-workflow/submission.md" class="pkp_help_tab"}
{help file="editorial-workflow/submission" class="pkp_help_tab"}

<div class="pkp_context_sidebar">
{capture assign=submissionEditorDecisionsUrl}{url router=$smarty.const.ROUTE_PAGE page="workflow" op="editorDecisionActions" submissionId=$submission->getId() stageId=$stageId contextId="submission" escape=false}{/capture}
Expand Down
39 changes: 33 additions & 6 deletions tests/WebTestCase.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,31 @@ protected function downloadFile($filename) {
* @param $value string Value to enter into control
*/
protected function typeTinyMCE($controlPrefix, $value) {
sleep(2); // Give TinyMCE a chance to load/init
$this->waitForElementPresent('css=iframe[id^="' . $controlPrefix . '"]'); // Wait for TinyMCE to init
$this->runScript("tinyMCE.get($('textarea[id^=\\'" . htmlspecialchars($controlPrefix) . "\\']').attr('id')).setContent('" . htmlspecialchars($value, ENT_QUOTES) . "');");
}

/**
* Set the value of an input field and fire the `input` event
*
* This is required to trigger the event listeners in Vue.js and support the
* data binding in form fields. Otherwise, selenium does not fire the event
* and the DOM is updated but Vue's data model is not synced.
*
* @param $selector string A CSS selector compatible with document.querySelector()
* @param $value string Value to enter into the control
*/
protected function setInputValue($selector, $value) {
$this->waitForElementPresent('css=' . $selector);
$this->type('css=' . $selector);
$this->runScript("
var el = document.querySelector('" . $selector . "');
el.value = " . json_encode($value) . ";
var e = new Event('input');
el.dispatchEvent(e);
");
}

/**
* Add a tag to a TagIt-enabled control
* @param $controlPrefix string Prefix of control name
Expand All @@ -330,16 +351,23 @@ protected function addTag($controlPrefix, $value) {
}

/**
* Click a link action with the specified name.
* @param $name string Name of link action.
* @param $waitFirst boolean True (default) to wait for the element first.
* Click a button with the specified text
* @param $text string
*/
protected function clickLinkActionNamed($name, $waitFirst = true) {
protected function clickButton($text) {
$selector = '//button[text()=\'' . $this->escapeJS($name) . '\']';
$this->waitForElementPresent($selector);
$this->click($selector);
}
/**
* Click a link action with the specified name.
* @param $name string Name of link action.
*/
protected function clickLinkActionNamed($name) {
$this->clickButton($name);
}
/**
* Wait for active JQuery requests to complete.
*/
Expand Down Expand Up @@ -386,4 +414,3 @@ protected function scrollPageDown() {
$this->runScript('scroll(0, document.body.scrollHeight()');
}
}

4 changes: 2 additions & 2 deletions tools/checkHelp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# Look for help filenames referred to in templates and check that they all exist (in English)
ERRORS=0
for filename in `find . -name \*.tpl -exec sed -n -e "s/.*{help[^}]file=\"\([^\"#]\+\)[#\"].*/\1/p" "{}" ";"`; do
if [ ! -f docs/manual/en/$filename ]; then
echo "Help file \"$filename\" referred to in template does not exist!"
if [ ! -f docs/manual/en/$filename.md ]; then
echo "Help file \"$filename.md\" referred to in template does not exist!"
ERRORS=1
fi
done
Expand Down
4 changes: 3 additions & 1 deletion tools/closure-externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ plupload.Uploader.prototype.removeFile = function(f) {};
plupload.Uploader.prototype.bind = function(eventName, f) {};

$.pkp.app = {
baseUrl: ''
baseUrl: '',
tinyMceContentCSS: '',
tinyMceContentFont: ''
};

$.pkp.locale = {
Expand Down
2 changes: 1 addition & 1 deletion tools/travis/validate-json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set -xe # Fail on first error
# Search for all JSON files in the current directory
REPOSITORY_DIR="."

sudo npm install jsonlint -g
npm install jsonlint -g
for name in `find $REPOSITORY_DIR -name \*.json | fgrep -v -f $REPOSITORY_DIR/tools/jsonlint-exclusions.txt`; do
jsonlint -q $name
done

0 comments on commit a8c1605

Please sign in to comment.