From db693f74bbc7e9c1fcb2b26e663a3c4b02208fec Mon Sep 17 00:00:00 2001
From: GabrielJenik
Date: Tue, 29 Dec 2020 12:21:11 -0300
Subject: [PATCH 1/2] Fixed issue #16474: Remote control import_group broken
Fixed and Added test case
---
.../remotecontrol/remotecontrol_handle.php | 2 +-
tests/TestHelper.php | 2 +-
.../data/file_upload/limesurvey_group_472.lsg | 530 ++++++++++++++++++
.../limesurvey_survey_251297_import_group.lss | 294 ++++++++++
tests/unit/helpers/RemoteControlTest.php | 62 ++
5 files changed, 888 insertions(+), 2 deletions(-)
create mode 100644 tests/data/file_upload/limesurvey_group_472.lsg
create mode 100644 tests/data/surveys/limesurvey_survey_251297_import_group.lss
diff --git a/application/helpers/remotecontrol/remotecontrol_handle.php b/application/helpers/remotecontrol/remotecontrol_handle.php
index 15d94f55ffa..287fc8f8948 100644
--- a/application/helpers/remotecontrol/remotecontrol_handle.php
+++ b/application/helpers/remotecontrol/remotecontrol_handle.php
@@ -1123,7 +1123,7 @@ public function import_group($sSessionKey, $iSurveyID, $sImportData, $sImportDat
libxml_disable_entity_loader($bOldEntityLoaderState); // Put back entity loader to its original state, to avoid contagion to other applications on the server
return array('status' => 'Error: Invalid LimeSurvey group structure XML ');
}
- $aImportResults = XMLImportGroup($sFullFilePath, $iSurveyID);
+ $aImportResults = XMLImportGroup($sFullFilePath, $iSurveyID, true);
} else {
return array('status' => 'Invalid extension');
}
diff --git a/tests/TestHelper.php b/tests/TestHelper.php
index 896d17a7c56..cb2eaf70c0f 100644
--- a/tests/TestHelper.php
+++ b/tests/TestHelper.php
@@ -26,7 +26,7 @@ public function importAll()
\Yii::import('application.helpers.common_helper', true);
\Yii::import('application.helpers.replacements_helper', true);
\Yii::import('application.helpers.surveytranslator_helper', true);
- \Yii::import('application.helpers.admin.import_helper', true);
+ \Yii::app()->loadHelper('admin/import');
\Yii::import('application.helpers.expressions.em_manager_helper', true);
\Yii::import('application.helpers.expressions.em_manager_helper', true);
\Yii::import('application.helpers.qanda_helper', true);
diff --git a/tests/data/file_upload/limesurvey_group_472.lsg b/tests/data/file_upload/limesurvey_group_472.lsg
new file mode 100644
index 00000000000..3544bf2b43e
--- /dev/null
+++ b/tests/data/file_upload/limesurvey_group_472.lsg
@@ -0,0 +1,530 @@
+
+
+ Group
+ 435
+
+ en
+
+
+
+ gid
+ sid
+ group_order
+ randomization_group
+ grelevance
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id
+ gid
+ group_name
+ description
+ language
+ sid
+ group_order
+ randomization_group
+ grelevance
+
+
+
+
+
+
+ This is an imported group
]]>
+
+
+
+
+
+
+
+
+
+
+ qid
+ parent_qid
+ sid
+ gid
+ type
+ title
+ preg
+ other
+ mandatory
+ question_order
+ scale_id
+ same_default
+ relevance
+ modulename
+ encrypted
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id
+ qid
+ question
+ help
+ language
+ script
+
+
+
+
+
+ First question]]>
+
+
+
+
+
+
+
+ Second question]]>
+
+
+
+
+
+
+
+
+ qid
+ attribute
+ value
+ language
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/data/surveys/limesurvey_survey_251297_import_group.lss b/tests/data/surveys/limesurvey_survey_251297_import_group.lss
new file mode 100644
index 00000000000..aea0af0f65c
--- /dev/null
+++ b/tests/data/surveys/limesurvey_survey_251297_import_group.lss
@@ -0,0 +1,294 @@
+
+
+ Survey
+ 435
+
+ en
+
+
+
+ sid
+ gsid
+ admin
+ expires
+ startdate
+ adminemail
+ anonymized
+ faxto
+ format
+ savetimings
+ template
+ language
+ additional_languages
+ datestamp
+ usecookie
+ allowregister
+ allowsave
+ autonumber_start
+ autoredirect
+ allowprev
+ printanswers
+ ipaddr
+ refurl
+ showsurveypolicynotice
+ publicstatistics
+ publicgraphs
+ listpublic
+ htmlemail
+ sendconfirmation
+ tokenanswerspersistence
+ assessments
+ usecaptcha
+ usetokens
+ bounce_email
+ attributedescriptions
+ emailresponseto
+ emailnotificationto
+ tokenlength
+ showxquestions
+ showgroupinfo
+ shownoanswer
+ showqnumcode
+ bouncetime
+ bounceprocessing
+ bounceaccounttype
+ bounceaccounthost
+ bounceaccountpass
+ bounceaccountencryption
+ bounceaccountuser
+ showwelcome
+ showprogress
+ questionindex
+ navigationdelay
+ nokeyboard
+ alloweditaftercompletion
+ googleanalyticsstyle
+ googleanalyticsapikey
+ tokenencryptionoptions
+ ipanonymize
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ surveyls_survey_id
+ surveyls_language
+ surveyls_title
+ surveyls_description
+ surveyls_welcometext
+ surveyls_endtext
+ surveyls_policy_notice
+ surveyls_policy_error
+ surveyls_policy_notice_label
+ surveyls_url
+ surveyls_urldescription
+ surveyls_email_invite_subj
+ surveyls_email_invite
+ surveyls_email_remind_subj
+ surveyls_email_remind
+ surveyls_email_register_subj
+ surveyls_email_register
+ surveyls_email_confirm_subj
+ surveyls_email_confirm
+ surveyls_dateformat
+ surveyls_attributecaptions
+ email_admin_notification_subj
+ email_admin_notification
+ email_admin_responses_subj
+ email_admin_responses
+ surveyls_numberformat
+ attachments
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 251297
+ vanilla
+
+ inherit
+
+
+
+
+
+ 251297
+ vanilla
+
+
+ off
+ on
+ on
+ off
+ ./files/logo.png
+ noto
+
+
+
+
+
diff --git a/tests/unit/helpers/RemoteControlTest.php b/tests/unit/helpers/RemoteControlTest.php
index f425af6f788..21cde7ae0fc 100644
--- a/tests/unit/helpers/RemoteControlTest.php
+++ b/tests/unit/helpers/RemoteControlTest.php
@@ -285,4 +285,66 @@ public function testGetGroupProperties()
$this->assertEquals('Das Deutsch title', $result['group_name']);
}
+ /**
+ * Test the import_group API call.
+ */
+ public function testImportGroup()
+ {
+ \Yii::import('application.helpers.remotecontrol.remotecontrol_handle', true);
+ \Yii::import('application.helpers.viewHelper', true);
+ \Yii::import('application.libraries.BigData', true);
+ $dbo = \Yii::app()->getDb();
+
+ // Make sure the Authdb is in database (might not be the case if no browser login attempt has been made).
+ $plugin = \Plugin::model()->findByAttributes(array('name'=>'Authdb'));
+ if (!$plugin) {
+ $plugin = new \Plugin();
+ $plugin->name = 'Authdb';
+ $plugin->active = 1;
+ $plugin->save();
+ } else {
+ $plugin->active = 1;
+ $plugin->save();
+ }
+ App()->getPluginManager()->loadPlugin('Authdb', $plugin->id);
+ // Clear login attempts.
+ $query = sprintf('DELETE FROM {{failed_login_attempts}}');
+ $dbo->createCommand($query)->execute();
+
+ // Import survey
+ $filename = self::$surveysFolder . '/limesurvey_survey_251297_import_group.lss';
+ self::importSurvey($filename);
+
+ // Create handler.
+ $admin = new \AdminController('dummyid');
+ $handler = new \remotecontrol_handle($admin);
+
+ // Get session key.
+ $sessionKey = $handler->get_session_key(
+ self::$username,
+ self::$password
+ );
+ $this->assertNotEquals(['status' => 'Invalid user name or password'], $sessionKey);
+
+ $groupFileName = BASEPATH . '../tests/data/file_upload/limesurvey_group_472.lsg';
+ $groupData = base64_encode(file_get_contents($groupFileName));
+
+ $result = $handler->import_group(
+ $sessionKey,
+ self::$surveyId,
+ $groupData,
+ 'lsg',
+ );
+
+ $this->assertIsNumeric($result, '$result = ' . json_encode($result));
+
+ $oGroup = \QuestionGroup::model()->findByPk($result);
+
+ $this->assertNotEmpty($oGroup, "Imported group not found");
+
+ // Cleanup
+ self::$testSurvey->delete();
+ self::$testSurvey = null;
+ }
+
}
From 775a27bc97028e26ab778d58f8f9002a48df3083 Mon Sep 17 00:00:00 2001
From: GabrielJenik
Date: Tue, 29 Dec 2020 15:54:53 -0300
Subject: [PATCH 2/2] Fixed issue #16474: Remote control import_group broken
Changed how to load library to avoid duplicated: Rollback on TestHelper and Updated on RemoteControl Handle.
---
application/helpers/remotecontrol/remotecontrol_handle.php | 2 +-
tests/TestHelper.php | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/application/helpers/remotecontrol/remotecontrol_handle.php b/application/helpers/remotecontrol/remotecontrol_handle.php
index 287fc8f8948..3a755321dc1 100644
--- a/application/helpers/remotecontrol/remotecontrol_handle.php
+++ b/application/helpers/remotecontrol/remotecontrol_handle.php
@@ -1109,7 +1109,7 @@ public function import_group($sSessionKey, $iSurveyID, $sImportData, $sImportDat
return array('status' => 'Invalid extension');
}
libxml_use_internal_errors(true);
- Yii::app()->loadHelper('admin/import');
+ Yii::app()->loadHelper('admin.import');
// First save the data to a temporary file
$sFullFilePath = Yii::app()->getConfig('tempdir').DIRECTORY_SEPARATOR.randomChars(40).'.'.$sImportDataType;
file_put_contents($sFullFilePath, base64_decode(chunk_split($sImportData)));
diff --git a/tests/TestHelper.php b/tests/TestHelper.php
index cb2eaf70c0f..896d17a7c56 100644
--- a/tests/TestHelper.php
+++ b/tests/TestHelper.php
@@ -26,7 +26,7 @@ public function importAll()
\Yii::import('application.helpers.common_helper', true);
\Yii::import('application.helpers.replacements_helper', true);
\Yii::import('application.helpers.surveytranslator_helper', true);
- \Yii::app()->loadHelper('admin/import');
+ \Yii::import('application.helpers.admin.import_helper', true);
\Yii::import('application.helpers.expressions.em_manager_helper', true);
\Yii::import('application.helpers.expressions.em_manager_helper', true);
\Yii::import('application.helpers.qanda_helper', true);