diff --git a/CHANGELOG.md b/CHANGELOG.md
index be9c064..68280c6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,58 @@
+### Date: 2021-January-18
+### Release: v2021011801
+
+#### :zap: What's new
+
+---
+
+#### Support for Moodle 3.10
+
+You can now confidently use Turnitin with Moodle 3.10.
+
+#### Improved loading screen for the Turnitin Integrity Viewer
+
+We’ve improved the loading screen you see when you launch the Turnitin Integrity viewer. The new loading screen includes an animation to indicate that the viewer is still opening and will be ready soon.
+
+You can use this new animation to tell if something may have gone wrong and needs to be investigated.
+
+#### Styling and workflow improvements to the Turnitin EULA
+
+We haven’t made any changes to the EULA itself, but we have adjusted the styling of the box that is shown to ask you to review and accept it when a user first uses Turnitin. We’ve also taken the opportunity to fix a few bugs that could interrupt the intended EULA workflow
+
+#### Get Help in all of Turnitin’s supported languages
+
+Did you know we offer full step-by-step guidance for all Turnitin features? You’ll find direct links to the pages relevant for the language you view the Turnitin Integrity plugin in.
+
+#### Use Turnitin with older submissions
+
+If you enable Turnitin for an assignment after submissions have already been made, we will now queue these for report generation the next time you view the inbox in Moodle. These files will have the QUEUED status. If a student has not accepted the Turnitin EULA yet, we will instead show Awaiting EULA and will only process the file after the student has accepted it.
+
+#### :wrench: Fixes and enhancements
+
+---
+
+#### Assignment settings have the correct spacing
+
+The Turnitin settings configured when creating a Moodle assignment could have odd spacing. We’ve cleaned this up so the settings flow as they should.
+
+#### Feedback and Intro files will no longer be checked for similarity
+
+We no longer check any feedback or intro files you attach to an assignment for your students for similarity.
+
+#### Deleting a course module will now also delete any attached Turnitin submissions
+
+If a course module is deleted, along with its Moodle Assignments, we will now also delete any relevant Turnitin settings or entries in our database.
+
+#### dateformat now uses the correct format
+
+Thanks to our friends at OpenLMS who let us know that the download_as_dataformat() method was deprecated in Moodle 3.9. We’ve now updated this to the latest code to ensure everything works correctly for all users.
+
+#### Accept the Turnitin EULA once for all assignment types
+
+The EULA could show multiple times for each type of Moodle assignment. Now users only have to accept it once and we will remember this choice when generating Similarity Reports for Moodle Assignments, Workshops, Forums, and quizzes.
+
+---
+
### Date: 2020-September-23
### Release: v2020092301
diff --git a/README.md b/README.md
index 02cbbdb..3a82ffe 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@ Turnitin Integrity Plugin for Moodle
Description:
-
-Utilize **Turnitin Integrity’s** Similarity Report and Authorship investigating tools within Moodle’s assignment workflow by integrating with the Turnitin Integrity plugin. **Turnitin Integrity** is a commercial plagiarism and authorship detection system whose features depend on which paid license has been selected. This plugin is developed and maintained by Turnitin.
+Utilize **Turnitin Integrity’s** Similarity Report and Authorship investigating tools within Moodle's assignment workflow by integrating with the Turnitin Integrity plugin. **Turnitin Integrity** is a commercial plagiarism and authorship detection system whose features depend on which paid license has been selected. This plugin is developed and maintained by Turnitin.
Features:
-
@@ -19,8 +19,9 @@ Useful Links
Installation
-
+Before installing this plugin firstly make sure you are logged in as an Administrator and that you are using Moodle 3.5 or higher.
-To install, all you need to do is copy all the files into the plagiarism/turnitinsim directory on your moodle installation. You should then go to `"Site Administration" > "Notifications"` and follow the on screen instructions.
+To install, all you need to do is copy all the files into the plagiarism/turnitinsim directory on your Moodle installation. You should then go to `"Site Administration" > "Notifications"` and follow the on screen instructions.
Plagiarism plugins also need to be enabled before this plugin can be used. This should happen as part of the install process but if it doesn't then you can do this by going to `"Site Administration" > "Advanced Features"` and ticking the `"Enable plagiarism plugins"` checkbox before saving.
@@ -28,6 +29,8 @@ Configuring
-
To configure the plugin go to `"Site administration" > "Plugins" > "Plagiarism" > "Turnitin Integrity plagiarism plugin"` and enter your API key and API URL.
+Other options can also be set, such as which Moodle modules to enable the plugin for or logging. Logging can be useful in scenarios where there is a problem with your installation. Default settings for the plugin can also be enabled so that you don't have to configure every individual assignment each time.
+
Testing
-
This plugin contains a full suite of PHPUnit tests which can be run against your Moodle installation.
diff --git a/ajax/eula_response.php b/ajax/eula_response.php
index 205ff79..bdd982e 100644
--- a/ajax/eula_response.php
+++ b/ajax/eula_response.php
@@ -25,6 +25,7 @@
require_once(__DIR__."/../../../config.php");
require_once(__DIR__."/../lib.php");
+require_once(__DIR__."/../classes/eula.class.php");
require_login();
@@ -34,51 +35,12 @@
// Get any params passed in.
$action = required_param('action', PARAM_ALPHAEXT);
-$contextid = optional_param('contextid', 0, PARAM_INT);
-
-$tsrequest = new plagiarism_turnitinsim_request();
switch ($action) {
case "accept_eula":
- // Get current user record.
- $user = $DB->get_record('plagiarism_turnitinsim_users', array('userid' => $USER->id));
-
- // Update EULA accepted version and timestamp for user.
- $data = new stdClass();
- $data->id = $user->id;
- $data->lasteulaaccepted = get_config('plagiarism_turnitinsim', 'turnitin_eula_version');
- $data->lasteulaacceptedtime = time();
- $lang = $tsrequest->get_language();
- $data->lasteulaacceptedlang = $lang->localecode;
- $DB->update_record('plagiarism_turnitinsim_users', $data);
-
- // If we have a context id then this is an instructor. So we update current submissions.
- if (!empty($contextid)) {
+ $eula = new plagiarism_turnitinsim_eula();
- // Get all submissions in this context.
- $context = context::instance_by_id($contextid);
- $submissions = $DB->get_records(
- 'plagiarism_turnitinsim_sub',
- array(
- 'cm' => $context->instanceid,
- 'status' => TURNITINSIM_SUBMISSION_STATUS_EULA_NOT_ACCEPTED,
- 'submitter' => $USER->id
- )
- );
-
- // Set each paper in this module submitted by this user to queued.
- foreach ($submissions as $submission) {
- $data = new stdClass();
- $data->id = $submission->id;
- $data->status = TURNITINSIM_SUBMISSION_STATUS_QUEUED;
- $data->cm = $context->instanceid;
- $data->tiiattempts = 0;
- $data->tiiretrytime = 0;
-
- $DB->update_record('plagiarism_turnitinsim_sub', $data);
- }
- }
- echo json_encode(["success" => true]);
+ echo $eula->accept_eula();
break;
-}
+}
\ No newline at end of file
diff --git a/amd/build/cv_launch.min.js b/amd/build/cv_launch.min.js
index 273a4e6..fb3b5e8 100644
--- a/amd/build/cv_launch.min.js
+++ b/amd/build/cv_launch.min.js
@@ -1,2 +1,2 @@
-define ("plagiarism_turnitinsim/cv_launch",["jquery","core/str"],function(a,b){return{openCv:function openCv(){a(document).on("click",".or_score",function(){var c=a(this).parent().attr("class").split(/\s+/),d=0;a(c).each(function(a){if(c[a].match("^submission_")){d=c[a].split("_")[1]}});var e=window.open(),f="
");a.ajax({type:"GET",url:M.cfg.wwwroot+"/plagiarism/turnitinsim/ajax/cv.php",dataType:"json",data:{action:"request_cv_launch",submissionid:c,sesskey:M.cfg.sesskey},success:function success(a){e.location=a.viewer_url;this.checkDVClosed(e)},checkDVClosed:function checkDVClosed(a){var b=this;if(a.closed){window.location=window.location+""}else{setTimeout(function(){b.checkDVClosed(a)},500)}}})})}}});
//# sourceMappingURL=cv_launch.min.js.map
diff --git a/amd/build/cv_launch.min.js.map b/amd/build/cv_launch.min.js.map
index 6fa0b4b..9e10d1a 100644
--- a/amd/build/cv_launch.min.js.map
+++ b/amd/build/cv_launch.min.js.map
@@ -1 +1 @@
-{"version":3,"sources":["../src/cv_launch.js"],"names":["define","$","str","openCv","document","on","classList","parent","attr","split","submissionid","each","index","match","cvWindow","window","open","loading","icon","M","cfg","wwwroot","get_string","done","text","hide","html","fadeIn","body","ajax","type","url","dataType","data","action","sesskey","success","location","viewer_url","checkDVClosed","that","closed","setTimeout"],"mappings":"AA4BAA,OAAM,oCAAC,CAAC,QAAD,CAAW,UAAX,CAAD,CAAyB,SAASC,CAAT,CAAYC,CAAZ,CAAiB,CAC5C,MAAO,CACHC,MAAM,CAAE,iBAAW,CACfF,CAAC,CAACG,QAAD,CAAD,CAAYC,EAAZ,CAAe,OAAf,CAAwB,WAAxB,CAAqC,UAAW,IAGxCC,CAAAA,CAAS,CAAGL,CAAC,CAAC,IAAD,CAAD,CAAQM,MAAR,GAAiBC,IAAjB,CAAsB,OAAtB,EAA+BC,KAA/B,CAAqC,KAArC,CAH4B,CAIxCC,CAAY,CAAG,CAJyB,CAK5CT,CAAC,CAACK,CAAD,CAAD,CAAaK,IAAb,CAAkB,SAASC,CAAT,CAAgB,CAC9B,GAAIN,CAAS,CAACM,CAAD,CAAT,CAAiBC,KAAjB,CAAuB,cAAvB,CAAJ,CAA4C,CACxCH,CAAY,CAAGJ,CAAS,CAACM,CAAD,CAAT,CAAiBH,KAAjB,CAAuB,GAAvB,EAA4B,CAA5B,CAClB,CACJ,CAJD,EAL4C,GAYxCK,CAAAA,CAAQ,CAAGC,MAAM,CAACC,IAAP,EAZ6B,CAaxCC,CAAO,CAAG,6DAb8B,CAcxCC,CAAI,CAAGC,CAAC,CAACC,GAAF,CAAMC,OAAN,CAAgB,yCAdiB,CAe5CJ,CAAO,EAAI,cAAeC,CAAf,CAAsB,0CAAjC,CAEAhB,CAAG,CAACoB,UAAJ,CAAe,WAAf,CAA4B,wBAA5B,EAAsDC,IAAtD,CAA2D,SAASC,CAAT,CAAe,CACtEP,CAAO,EAAI,2DAA2DO,CAA3D,CAAkE,MAA7E,CACAvB,CAAC,CAAC,gBAAD,CAAD,CAAoBwB,IAApB,GAA2BC,IAA3B,CAAgCF,CAAhC,EAAsCG,MAAtC,EACH,CAHD,EAKAV,CAAO,EAAI,QAAX,CACAhB,CAAC,CAACa,CAAQ,CAACV,QAAT,CAAkBwB,IAAnB,CAAD,CAA0BF,IAA1B,CAA+BT,CAA/B,EAEAhB,CAAC,CAAC4B,IAAF,CAAO,CACHC,IAAI,CAAE,KADH,CAEHC,GAAG,CAAEZ,CAAC,CAACC,GAAF,CAAMC,OAAN,CAAgB,qCAFlB,CAGHW,QAAQ,CAAE,MAHP,CAIHC,IAAI,CAAE,CACFC,MAAM,CAAE,mBADN,CAEFxB,YAAY,CAAEA,CAFZ,CAGFyB,OAAO,CAAEhB,CAAC,CAACC,GAAF,CAAMe,OAHb,CAJH,CASHC,OAAO,CAAE,iBAASH,CAAT,CAAe,CAEpBnB,CAAQ,CAACuB,QAAT,CAAoBJ,CAAI,CAACK,UAAzB,CACA,KAAKC,aAAL,CAAmBzB,CAAnB,CACH,CAbE,CAcHyB,aAAa,CAAE,uBAASzB,CAAT,CAAmB,CAC9B,GAAI0B,CAAAA,CAAI,CAAG,IAAX,CACA,GAAI1B,CAAQ,CAAC2B,MAAb,CAAqB,CACjB1B,MAAM,CAACsB,QAAP,CAAkBtB,MAAM,CAACsB,QAC5B,CAFD,IAEO,CACHK,UAAU,CAAC,UAAW,CAClBF,CAAI,CAACD,aAAL,CAAmBzB,CAAnB,CACH,CAFS,CAEP,GAFO,CAGb,CACJ,CAvBE,CAAP,CAyBH,CAlDD,CAmDH,CArDE,CAuDV,CAxDK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Javascript controller for the Turnitin Cloud Viewer launch.\n *\n * @package plagiarism_turnitinsim\n * @copyright 2017 Turnitin\n * @author John McGettrick \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * @module plagiarism_turnitinsim/cv_launch\n */\n\ndefine(['jquery', 'core/str'], function($, str) {\n return {\n openCv: function() {\n $(document).on('click', '.or_score', function() {\n\n // Moodle forums strip ids from elements so we have to use classes.\n var classList = $(this).parent().attr('class').split(/\\s+/);\n var submissionid = 0;\n $(classList).each(function(index) {\n if (classList[index].match(\"^submission_\")) {\n submissionid = classList[index].split(\"_\")[1];\n }\n });\n\n // Launch the Cloud Viewer in a new window.\n var cvWindow = window.open();\n var loading = '
';\n $(cvWindow.document.body).html(loading);\n\n $.ajax({\n type: \"GET\",\n url: M.cfg.wwwroot + \"/plagiarism/turnitinsim/ajax/cv.php\",\n dataType: \"json\",\n data: {\n action: 'request_cv_launch',\n submissionid: submissionid,\n sesskey: M.cfg.sesskey\n },\n success: function(data) {\n // Redirect opened window to returned URL.\n cvWindow.location = data.viewer_url;\n this.checkDVClosed(cvWindow);\n },\n checkDVClosed: function(cvWindow) {\n var that = this;\n if (cvWindow.closed) {\n window.location = window.location;\n } else {\n setTimeout(function() {\n that.checkDVClosed(cvWindow);\n }, 500);\n }\n }\n });\n });\n }\n };\n});"],"file":"cv_launch.min.js"}
\ No newline at end of file
+{"version":3,"sources":["../src/cv_launch.js"],"names":["define","$","openCv","document","on","classList","parent","attr","split","submissionid","each","index","match","icon","M","cfg","wwwroot","cvWindow","window","open","write","body","html","ajax","type","url","dataType","data","action","sesskey","success","location","viewer_url","checkDVClosed","that","closed","setTimeout"],"mappings":"AA4BAA,OAAM,oCAAC,CAAC,QAAD,CAAD,CAAa,SAASC,CAAT,CAAY,CAC3B,MAAO,CACHC,MAAM,CAAE,iBAAW,CACfD,CAAC,CAACE,QAAD,CAAD,CAAYC,EAAZ,CAAe,OAAf,CAAwB,WAAxB,CAAqC,UAAW,IAGxCC,CAAAA,CAAS,CAAGJ,CAAC,CAAC,IAAD,CAAD,CAAQK,MAAR,GAAiBC,IAAjB,CAAsB,OAAtB,EAA+BC,KAA/B,CAAqC,KAArC,CAH4B,CAIxCC,CAAY,CAAG,CAJyB,CAK5CR,CAAC,CAACI,CAAD,CAAD,CAAaK,IAAb,CAAkB,SAASC,CAAT,CAAgB,CAC9B,GAAIN,CAAS,CAACM,CAAD,CAAT,CAAiBC,KAAjB,CAAuB,cAAvB,CAAJ,CAA4C,CACxCH,CAAY,CAAGJ,CAAS,CAACM,CAAD,CAAT,CAAiBH,KAAjB,CAAuB,GAAvB,EAA4B,CAA5B,CAClB,CACJ,CAJD,EAL4C,GAYxCK,CAAAA,CAAI,CAAGC,CAAC,CAACC,GAAF,CAAMC,OAAN,CAAgB,yCAZiB,CAaxCC,CAAQ,CAAGC,MAAM,CAACC,IAAP,EAb6B,CAe5CF,CAAQ,CAACd,QAAT,CAAkBiB,KAAlB,CAAwB,iEACKN,CAAC,CAACC,GAAF,CAAMC,OADX,qDAAxB,EAEAC,CAAQ,CAACd,QAAT,CAAkBiB,KAAlB,CAAwB,gBAAxB,EAYAnB,CAAC,CAACgB,CAAQ,CAACd,QAAT,CAAkBkB,IAAnB,CAAD,CAA0BC,IAA1B,CAVc,wFAEaT,CAFb,6MAUd,EAEAZ,CAAC,CAACsB,IAAF,CAAO,CACHC,IAAI,CAAE,KADH,CAEHC,GAAG,CAAEX,CAAC,CAACC,GAAF,CAAMC,OAAN,CAAgB,qCAFlB,CAGHU,QAAQ,CAAE,MAHP,CAIHC,IAAI,CAAE,CACFC,MAAM,CAAE,mBADN,CAEFnB,YAAY,CAAEA,CAFZ,CAGFoB,OAAO,CAAEf,CAAC,CAACC,GAAF,CAAMc,OAHb,CAJH,CASHC,OAAO,CAAE,iBAASH,CAAT,CAAe,CAEpBV,CAAQ,CAACc,QAAT,CAAoBJ,CAAI,CAACK,UAAzB,CACA,KAAKC,aAAL,CAAmBhB,CAAnB,CACH,CAbE,CAcHgB,aAAa,CAAE,uBAAShB,CAAT,CAAmB,CAC9B,GAAIiB,CAAAA,CAAI,CAAG,IAAX,CACA,GAAIjB,CAAQ,CAACkB,MAAb,CAAqB,CACjBjB,MAAM,CAACa,QAAP,CAAkBb,MAAM,CAACa,QAAP,CAAkB,EACvC,CAFD,IAEO,CACHK,UAAU,CAAC,UAAW,CAClBF,CAAI,CAACD,aAAL,CAAmBhB,CAAnB,CACH,CAFS,CAEP,GAFO,CAGb,CACJ,CAvBE,CAAP,CAyBH,CAxDD,CAyDH,CA3DE,CA6DV,CA9DK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Javascript controller for the Turnitin Cloud Viewer launch.\n *\n * @package plagiarism_turnitinsim\n * @copyright 2017 Turnitin\n * @author John McGettrick \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * @module plagiarism_turnitinsim/cv_launch\n */\n\ndefine(['jquery'], function($) {\n return {\n openCv: function() {\n $(document).on('click', '.or_score', function() {\n\n // Moodle forums strip ids from elements so we have to use classes.\n var classList = $(this).parent().attr('class').split(/\\s+/);\n var submissionid = 0;\n $(classList).each(function(index) {\n if (classList[index].match(\"^submission_\")) {\n submissionid = classList[index].split(\"_\")[1];\n }\n });\n\n // Launch the Cloud Viewer in a new window.\n var icon = M.cfg.wwwroot + '/plagiarism/turnitinsim/pix/tiiLogo.svg';\n var cvWindow = window.open();\n\n cvWindow.document.write('');\n cvWindow.document.write('');\n\n var loading = '
' +\n '
' +\n '' +\n '
' +\n '
' +\n '' +\n '' +\n '' +\n '
' +\n '
';\n $(cvWindow.document.body).html(loading);\n\n $.ajax({\n type: \"GET\",\n url: M.cfg.wwwroot + \"/plagiarism/turnitinsim/ajax/cv.php\",\n dataType: \"json\",\n data: {\n action: 'request_cv_launch',\n submissionid: submissionid,\n sesskey: M.cfg.sesskey\n },\n success: function(data) {\n // Redirect opened window to returned URL.\n cvWindow.location = data.viewer_url;\n this.checkDVClosed(cvWindow);\n },\n checkDVClosed: function(cvWindow) {\n var that = this;\n if (cvWindow.closed) {\n window.location = window.location + '';\n } else {\n setTimeout(function() {\n that.checkDVClosed(cvWindow);\n }, 500);\n }\n }\n });\n });\n }\n };\n});"],"file":"cv_launch.min.js"}
\ No newline at end of file
diff --git a/amd/build/eula_response.min.js b/amd/build/eula_response.min.js
index da8e566..1e1fadb 100644
--- a/amd/build/eula_response.min.js
+++ b/amd/build/eula_response.min.js
@@ -1,2 +1,2 @@
-define ("plagiarism_turnitinsim/eula_response",["jquery","core/str"],function(a,b){return{eulaResponse:function eulaResponse(){a(document).ready(function(){a("input[name=submitbutton]").prop("disabled","disabled")});a(document).on("click","#pp-eula-accept",function(){a("input[name=submitbutton]").prop("disabled","");a.ajax({type:"POST",url:M.cfg.wwwroot+"/plagiarism/turnitinsim/ajax/eula_response.php",dataType:"text",data:{action:"accept_eula",sesskey:M.cfg.sesskey},success:function success(){b.get_string("eulaaccepted","plagiarism_turnitinsim").done(function(b){a(".eulacontainer").hide().html(b).fadeIn()})}})});a(document).on("click","#pp-eula-decline",function(){b.get_string("euladeclined","plagiarism_turnitinsim").done(function(b){a(".eulacontainer").hide().html(b).fadeIn()});a("input[name=submitbutton]").prop("disabled","")})}}});
+define ("plagiarism_turnitinsim/eula_response",["jquery","core/str"],function(a,b){return{eulaResponse:function eulaResponse(){a(document).ready(function(){a("input[name=submitbutton]").prop("disabled","disabled")});a(document).on("click","#pp-eula-accept",function(){a("input[name=submitbutton]").prop("disabled","");a.ajax({type:"POST",url:M.cfg.wwwroot+"/plagiarism/turnitinsim/ajax/eula_response.php",dataType:"text",data:{action:"accept_eula",sesskey:M.cfg.sesskey},success:function success(){b.get_string("eulaaccepted","plagiarism_turnitinsim").done(function(c){a(".turnitinsim_eulacontainer").hide().html(c).fadeIn();b.get_string("submissiondisplaystatus:queued","plagiarism_turnitinsim").done(function(b){a(".tii_status_text").html(b)})})}})});a(document).on("click","#pp-eula-decline",function(){b.get_string("euladeclined","plagiarism_turnitinsim").done(function(b){a(".turnitinsim_eulacontainer").hide().html(b).fadeIn()});a("input[name=submitbutton]").prop("disabled","")})}}});
//# sourceMappingURL=eula_response.min.js.map
diff --git a/amd/build/eula_response.min.js.map b/amd/build/eula_response.min.js.map
index 6c00fdf..c004984 100644
--- a/amd/build/eula_response.min.js.map
+++ b/amd/build/eula_response.min.js.map
@@ -1 +1 @@
-{"version":3,"sources":["../src/eula_response.js"],"names":["define","$","str","eulaResponse","document","ready","prop","on","ajax","type","url","M","cfg","wwwroot","dataType","data","action","sesskey","success","get_string","done","text","hide","html","fadeIn"],"mappings":"AA4BAA,OAAM,wCAAC,CAAC,QAAD,CAAW,UAAX,CAAD,CAAyB,SAASC,CAAT,CAAYC,CAAZ,CAAiB,CAC5C,MAAO,CACHC,YAAY,CAAE,uBAAW,CACrBF,CAAC,CAACG,QAAD,CAAD,CAAYC,KAAZ,CAAkB,UAAW,CACzBJ,CAAC,CAAC,0BAAD,CAAD,CAA8BK,IAA9B,CAAmC,UAAnC,CAA+C,UAA/C,CACH,CAFD,EAIAL,CAAC,CAACG,QAAD,CAAD,CAAYG,EAAZ,CAAe,OAAf,CAAwB,iBAAxB,CAA2C,UAAW,CAClDN,CAAC,CAAC,0BAAD,CAAD,CAA8BK,IAA9B,CAAmC,UAAnC,CAA+C,EAA/C,EAGAL,CAAC,CAACO,IAAF,CAAO,CACHC,IAAI,CAAE,MADH,CAEHC,GAAG,CAAEC,CAAC,CAACC,GAAF,CAAMC,OAAN,CAAgB,gDAFlB,CAGHC,QAAQ,CAAE,MAHP,CAIHC,IAAI,CAAE,CAACC,MAAM,CAAE,aAAT,CAAwBC,OAAO,CAAEN,CAAC,CAACC,GAAF,CAAMK,OAAvC,CAJH,CAKHC,OAAO,CAAE,kBAAW,CAChBhB,CAAG,CAACiB,UAAJ,CAAe,cAAf,CAA+B,wBAA/B,EAAyDC,IAAzD,CAA8D,SAASC,CAAT,CAAe,CACzEpB,CAAC,CAAC,gBAAD,CAAD,CAAoBqB,IAApB,GAA2BC,IAA3B,CAAgCF,CAAhC,EAAsCG,MAAtC,EACH,CAFD,CAGH,CATE,CAAP,CAWH,CAfD,EAiBAvB,CAAC,CAACG,QAAD,CAAD,CAAYG,EAAZ,CAAe,OAAf,CAAwB,kBAAxB,CAA4C,UAAW,CACnDL,CAAG,CAACiB,UAAJ,CAAe,cAAf,CAA+B,wBAA/B,EAAyDC,IAAzD,CAA8D,SAASC,CAAT,CAAe,CACzEpB,CAAC,CAAC,gBAAD,CAAD,CAAoBqB,IAApB,GAA2BC,IAA3B,CAAgCF,CAAhC,EAAsCG,MAAtC,EACH,CAFD,EAIAvB,CAAC,CAAC,0BAAD,CAAD,CAA8BK,IAA9B,CAAmC,UAAnC,CAA+C,EAA/C,CACH,CAND,CAOH,CA9BE,CAgCV,CAjCK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Javascript controller for handling the EULA response.\n *\n * @package plagiarism_turnitinsim\n * @copyright 2018 Turnitin\n * @author John McGettrick \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * @module plagiarism_turnitinsim/handleEulaResponse\n */\n\ndefine(['jquery', 'core/str'], function($, str) {\n return {\n eulaResponse: function() {\n $(document).ready(function() {\n $('input[name=submitbutton]').prop('disabled', 'disabled');\n });\n\n $(document).on('click', '#pp-eula-accept', function() {\n $('input[name=submitbutton]').prop('disabled', '');\n\n // Hide the EULA link.\n $.ajax({\n type: \"POST\",\n url: M.cfg.wwwroot + \"/plagiarism/turnitinsim/ajax/eula_response.php\",\n dataType: \"text\",\n data: {action: \"accept_eula\", sesskey: M.cfg.sesskey},\n success: function() {\n str.get_string('eulaaccepted', 'plagiarism_turnitinsim').done(function(text) {\n $('.eulacontainer').hide().html(text).fadeIn();\n });\n }\n });\n });\n\n $(document).on('click', '#pp-eula-decline', function() {\n str.get_string('euladeclined', 'plagiarism_turnitinsim').done(function(text) {\n $('.eulacontainer').hide().html(text).fadeIn();\n });\n\n $('input[name=submitbutton]').prop('disabled', '');\n });\n }\n };\n});"],"file":"eula_response.min.js"}
\ No newline at end of file
+{"version":3,"sources":["../src/eula_response.js"],"names":["define","$","str","eulaResponse","document","ready","prop","on","ajax","type","url","M","cfg","wwwroot","dataType","data","action","sesskey","success","get_string","done","text","hide","html","fadeIn"],"mappings":"AA4BAA,OAAM,wCAAC,CAAC,QAAD,CAAW,UAAX,CAAD,CAAyB,SAASC,CAAT,CAAYC,CAAZ,CAAiB,CAC5C,MAAO,CACHC,YAAY,CAAE,uBAAW,CACrBF,CAAC,CAACG,QAAD,CAAD,CAAYC,KAAZ,CAAkB,UAAW,CACzBJ,CAAC,CAAC,0BAAD,CAAD,CAA8BK,IAA9B,CAAmC,UAAnC,CAA+C,UAA/C,CACH,CAFD,EAIAL,CAAC,CAACG,QAAD,CAAD,CAAYG,EAAZ,CAAe,OAAf,CAAwB,iBAAxB,CAA2C,UAAW,CAClDN,CAAC,CAAC,0BAAD,CAAD,CAA8BK,IAA9B,CAAmC,UAAnC,CAA+C,EAA/C,EAGAL,CAAC,CAACO,IAAF,CAAO,CACHC,IAAI,CAAE,MADH,CAEHC,GAAG,CAAEC,CAAC,CAACC,GAAF,CAAMC,OAAN,CAAgB,gDAFlB,CAGHC,QAAQ,CAAE,MAHP,CAIHC,IAAI,CAAE,CAACC,MAAM,CAAE,aAAT,CAAwBC,OAAO,CAAEN,CAAC,CAACC,GAAF,CAAMK,OAAvC,CAJH,CAKHC,OAAO,CAAE,kBAAW,CAChBhB,CAAG,CAACiB,UAAJ,CAAe,cAAf,CAA+B,wBAA/B,EAAyDC,IAAzD,CAA8D,SAASC,CAAT,CAAe,CACzEpB,CAAC,CAAC,4BAAD,CAAD,CAAgCqB,IAAhC,GAAuCC,IAAvC,CAA4CF,CAA5C,EAAkDG,MAAlD,GAEAtB,CAAG,CAACiB,UAAJ,CAAe,gCAAf,CAAiD,wBAAjD,EAA2EC,IAA3E,CAAgF,SAASC,CAAT,CAAe,CAC3FpB,CAAC,CAAC,kBAAD,CAAD,CAAsBsB,IAAtB,CAA2BF,CAA3B,CACH,CAFD,CAGH,CAND,CAOH,CAbE,CAAP,CAeH,CAnBD,EAqBApB,CAAC,CAACG,QAAD,CAAD,CAAYG,EAAZ,CAAe,OAAf,CAAwB,kBAAxB,CAA4C,UAAW,CACnDL,CAAG,CAACiB,UAAJ,CAAe,cAAf,CAA+B,wBAA/B,EAAyDC,IAAzD,CAA8D,SAASC,CAAT,CAAe,CACzEpB,CAAC,CAAC,4BAAD,CAAD,CAAgCqB,IAAhC,GAAuCC,IAAvC,CAA4CF,CAA5C,EAAkDG,MAAlD,EACH,CAFD,EAIAvB,CAAC,CAAC,0BAAD,CAAD,CAA8BK,IAA9B,CAAmC,UAAnC,CAA+C,EAA/C,CACH,CAND,CAOH,CAlCE,CAoCV,CArCK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Javascript controller for handling the EULA response.\n *\n * @package plagiarism_turnitinsim\n * @copyright 2018 Turnitin\n * @author John McGettrick \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * @module plagiarism_turnitinsim/handleEulaResponse\n */\n\ndefine(['jquery', 'core/str'], function($, str) {\n return {\n eulaResponse: function() {\n $(document).ready(function() {\n $('input[name=submitbutton]').prop('disabled', 'disabled');\n });\n\n $(document).on('click', '#pp-eula-accept', function() {\n $('input[name=submitbutton]').prop('disabled', '');\n\n // Hide the EULA link.\n $.ajax({\n type: \"POST\",\n url: M.cfg.wwwroot + \"/plagiarism/turnitinsim/ajax/eula_response.php\",\n dataType: \"text\",\n data: {action: \"accept_eula\", sesskey: M.cfg.sesskey},\n success: function() {\n str.get_string('eulaaccepted', 'plagiarism_turnitinsim').done(function(text) {\n $('.turnitinsim_eulacontainer').hide().html(text).fadeIn();\n\n str.get_string('submissiondisplaystatus:queued', 'plagiarism_turnitinsim').done(function(text) {\n $('.tii_status_text').html(text);\n });\n });\n }\n });\n });\n\n $(document).on('click', '#pp-eula-decline', function() {\n str.get_string('euladeclined', 'plagiarism_turnitinsim').done(function(text) {\n $('.turnitinsim_eulacontainer').hide().html(text).fadeIn();\n });\n\n $('input[name=submitbutton]').prop('disabled', '');\n });\n }\n };\n});"],"file":"eula_response.min.js"}
\ No newline at end of file
diff --git a/amd/build/inbox_eula_launch.min.js b/amd/build/inbox_eula_launch.min.js
deleted file mode 100644
index 82b4464..0000000
--- a/amd/build/inbox_eula_launch.min.js
+++ /dev/null
@@ -1,2 +0,0 @@
-define ("plagiarism_turnitinsim/inbox_eula_launch",["jquery","core/templates","core/modal_factory","plagiarism_turnitinsim/modal_eula"],function(a,b,c,d){return{inboxEulaLaunch:function inboxEulaLaunch(){var b=a(".eula-row-launch");c.create({type:d.TYPE},b)}}});
-//# sourceMappingURL=inbox_eula_launch.min.js.map
diff --git a/amd/build/inbox_eula_launch.min.js.map b/amd/build/inbox_eula_launch.min.js.map
deleted file mode 100644
index f846138..0000000
--- a/amd/build/inbox_eula_launch.min.js.map
+++ /dev/null
@@ -1 +0,0 @@
-{"version":3,"sources":["../src/inbox_eula_launch.js"],"names":["define","$","Templates","ModalFactory","ModalTcEula","inboxEulaLaunch","trigger","create","type","TYPE"],"mappings":"AAmBAA,OAAM,4CAAC,CAAC,QAAD,CACC,gBADD,CAEC,oBAFD,CAGC,mCAHD,CAAD,CAKF,SAASC,CAAT,CAAYC,CAAZ,CAAuBC,CAAvB,CAAqCC,CAArC,CAAkD,CAC9C,MAAO,CACHC,eAAe,CAAE,0BAAW,CACxB,GAAIC,CAAAA,CAAO,CAAGL,CAAC,CAAC,kBAAD,CAAf,CAEAE,CAAY,CAACI,MAAb,CACI,CACIC,IAAI,CAAEJ,CAAW,CAACK,IADtB,CADJ,CAIIH,CAJJ,CAMH,CAVE,CAYV,CAlBC,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * @module plagiarism_turnitinsim/inbox_eula_launch\n */\n\ndefine(['jquery',\n 'core/templates',\n 'core/modal_factory',\n 'plagiarism_turnitinsim/modal_eula'\n ],\n function($, Templates, ModalFactory, ModalTcEula) {\n return {\n inboxEulaLaunch: function() {\n var trigger = $('.eula-row-launch');\n\n ModalFactory.create(\n {\n type: ModalTcEula.TYPE\n },\n trigger\n );\n }\n };\n }\n);"],"file":"inbox_eula_launch.min.js"}
\ No newline at end of file
diff --git a/amd/src/cv_launch.js b/amd/src/cv_launch.js
index a638cb4..f4341a5 100644
--- a/amd/src/cv_launch.js
+++ b/amd/src/cv_launch.js
@@ -26,7 +26,7 @@
* @module plagiarism_turnitinsim/cv_launch
*/
-define(['jquery', 'core/str'], function($, str) {
+define(['jquery'], function($) {
return {
openCv: function() {
$(document).on('click', '.or_score', function() {
@@ -41,17 +41,23 @@ define(['jquery', 'core/str'], function($, str) {
});
// Launch the Cloud Viewer in a new window.
+ var icon = M.cfg.wwwroot + '/plagiarism/turnitinsim/pix/tiiLogo.svg';
var cvWindow = window.open();
- var loading = '
';
$(cvWindow.document.body).html(loading);
$.ajax({
@@ -71,7 +77,7 @@ define(['jquery', 'core/str'], function($, str) {
checkDVClosed: function(cvWindow) {
var that = this;
if (cvWindow.closed) {
- window.location = window.location;
+ window.location = window.location + '';
} else {
setTimeout(function() {
that.checkDVClosed(cvWindow);
diff --git a/amd/src/eula_response.js b/amd/src/eula_response.js
index 87b2ecc..237623a 100644
--- a/amd/src/eula_response.js
+++ b/amd/src/eula_response.js
@@ -44,7 +44,11 @@ define(['jquery', 'core/str'], function($, str) {
data: {action: "accept_eula", sesskey: M.cfg.sesskey},
success: function() {
str.get_string('eulaaccepted', 'plagiarism_turnitinsim').done(function(text) {
- $('.eulacontainer').hide().html(text).fadeIn();
+ $('.turnitinsim_eulacontainer').hide().html(text).fadeIn();
+
+ str.get_string('submissiondisplaystatus:queued', 'plagiarism_turnitinsim').done(function(text) {
+ $('.tii_status_text').html(text);
+ });
});
}
});
@@ -52,7 +56,7 @@ define(['jquery', 'core/str'], function($, str) {
$(document).on('click', '#pp-eula-decline', function() {
str.get_string('euladeclined', 'plagiarism_turnitinsim').done(function(text) {
- $('.eulacontainer').hide().html(text).fadeIn();
+ $('.turnitinsim_eulacontainer').hide().html(text).fadeIn();
});
$('input[name=submitbutton]').prop('disabled', '');
diff --git a/classes/assign.class.php b/classes/assign.class.php
index 08b8456..36987d9 100644
--- a/classes/assign.class.php
+++ b/classes/assign.class.php
@@ -194,7 +194,7 @@ public function show_other_posts_links($courseid, $userid) {
* @throws dml_exception
*/
public function create_submission_event_data($linkarray) {
- global $DB, $USER;
+ global $DB;
$cm = get_coursemodule_from_id('', $linkarray['cmid']);
@@ -202,7 +202,7 @@ public function create_submission_event_data($linkarray) {
$eventdata['contextinstanceid'] = $linkarray['cmid'];
$eventdata['eventtype'] = 'assessable_submitted';
- $eventdata['userid'] = $USER->id;
+ $eventdata['userid'] = $linkarray['userid'];
if (isset($linkarray['file'])) {
$eventdata['other']['pathnamehashes'] = array($linkarray['file']->get_pathnamehash());
diff --git a/classes/callback.class.php b/classes/callback.class.php
index 2448530..1f05e17 100644
--- a/classes/callback.class.php
+++ b/classes/callback.class.php
@@ -151,6 +151,19 @@ public function create_webhook() {
set_config('turnitin_webhook_secret', $secret, 'plagiarism_turnitinsim');
mtrace(get_string('taskoutputwebhookcreated', 'plagiarism_turnitinsim', TURNITINSIM_CALLBACK_URL));
+ } else if ($responsedata->httpstatus === TURNITINSIM_HTTP_CANNOT_EXTRACT_TEXT) {
+ // Webhook for this URL already exists in Turnitin, but not Moodle. Get webhooks.
+ $response = $this->tsrequest->send_request(TURNITINSIM_ENDPOINT_WEBHOOKS, json_encode(array()), 'GET');
+ $webhooks = json_decode($response);
+
+ // We want the webhook ID for this callback URL. Save it.
+ foreach ($webhooks as $webhook) {
+ if (is_object($webhook) && $webhook->url === TURNITINSIM_CALLBACK_URL) {
+ set_config('turnitin_webhook_id', $webhook->id, 'plagiarism_turnitinsim');
+ set_config('turnitin_webhook_secret', $secret, 'plagiarism_turnitinsim');
+ break;
+ }
+ }
} else {
mtrace(get_string('taskoutputwebhooknotcreated', 'plagiarism_turnitinsim', TURNITINSIM_CALLBACK_URL));
$loggingrequestinfo = new plagiarism_turnitinsim_logging_request_info(TURNITINSIM_ENDPOINT_WEBHOOKS, "POST",
diff --git a/classes/eula.class.php b/classes/eula.class.php
index 2eb531c..8d033b7 100644
--- a/classes/eula.class.php
+++ b/classes/eula.class.php
@@ -74,4 +74,78 @@ public function get_latest_version() {
return $responsedata;
}
}
+
+ /**
+ * Method for handling the acceptance of the EULA, called from eula_response.
+ * @throws dml_exception
+ */
+ public function accept_eula() {
+ global $DB, $USER;
+
+ // Get current user record.
+ $user = $DB->get_record('plagiarism_turnitinsim_users', array('userid' => $USER->id));
+
+ // Update EULA accepted version and timestamp for user.
+ $data = new stdClass();
+ $data->id = $user->id;
+ $data->lasteulaaccepted = get_config('plagiarism_turnitinsim', 'turnitin_eula_version');
+ $data->lasteulaacceptedtime = time();
+ $lang = $this->tsrequest->get_language();
+ $data->lasteulaacceptedlang = $lang->localecode;
+ $DB->update_record('plagiarism_turnitinsim_users', $data);
+
+ // Get all submissions for this student with EULA_NOT_ACCEPTED status.
+ $submissions = $DB->get_records(
+ 'plagiarism_turnitinsim_sub',
+ array(
+ 'status' => TURNITINSIM_SUBMISSION_STATUS_EULA_NOT_ACCEPTED,
+ 'userid' => $USER->id
+ )
+ );
+
+ // Update all existing submissions where EULA was not accepted.
+ foreach ($submissions as $submission) {
+ $data = new stdClass();
+ $data->id = $submission->id;
+ $data->status = TURNITINSIM_SUBMISSION_STATUS_QUEUED;
+ $data->tiiattempts = 0;
+ $data->tiiretrytime = 0;
+
+ $DB->update_record('plagiarism_turnitinsim_sub', $data);
+ }
+
+ return json_encode(["success" => true]);
+ }
+
+
+ /**
+ * This returns the HTML elements required to display a EULA_NOT_ACCEPTED status.
+ *
+ * @param int $cmid - course module id
+ * @param string $submissiontype - The type of submission - file or content.
+ * @return array The HTML elements for a EULA NOT ACCEPTED status.
+ * @throws coding_exception
+ * @throws dml_exception
+ */
+ public function get_eula_status($cmid, $submissiontype) {
+ global $OUTPUT;
+
+ $eulaconfirm = '';
+ if (!has_capability('plagiarism/turnitinsim:viewfullreport', context_module::instance($cmid))) {
+ $plagiarismpluginturnitinsim = new plagiarism_plugin_turnitinsim();
+ $eulaconfirm = $plagiarismpluginturnitinsim->print_disclosure($cmid, $submissiontype);
+ }
+
+ $helpicon = $OUTPUT->pix_icon(
+ 'help',
+ get_string('submissiondisplayerror:eulanotaccepted_help', 'plagiarism_turnitinsim'),
+ 'core'
+ );
+
+ return array('eula-confirm' => $eulaconfirm, 'eula-status' => html_writer::tag(
+ 'span',
+ get_string('submissiondisplaystatus:awaitingeula', 'plagiarism_turnitinsim') . $helpicon,
+ array('class' => 'tii_status_text tii_status_text_eula')
+ ));
+ }
}
\ No newline at end of file
diff --git a/classes/forum.class.php b/classes/forum.class.php
index 671f27b..2cb318a 100644
--- a/classes/forum.class.php
+++ b/classes/forum.class.php
@@ -144,15 +144,13 @@ public function show_other_posts_links($courseid, $userid) {
* @throws dml_exception
*/
public function create_submission_event_data($linkarray) {
- global $USER;
-
$cm = get_coursemodule_from_id('', $linkarray['cmid']);
$eventdata = array();
$eventdata['contextinstanceid'] = $linkarray['cmid'];
$eventdata['eventtype'] = 'assessable_submitted';
- $eventdata['userid'] = $USER->id;
+ $eventdata['userid'] = $linkarray['userid'];
if (isset($linkarray['file'])) {
$eventdata['other']['pathnamehashes'] = array($linkarray['file']->get_pathnamehash());
diff --git a/classes/observer.php b/classes/observer.php
index 37f8907..1bb4a45 100644
--- a/classes/observer.php
+++ b/classes/observer.php
@@ -118,4 +118,16 @@ public static function module_updated(\core\event\course_module_updated $event)
$plugin = new plagiarism_plugin_turnitinsim();
$plugin->module_updated(self::build_event_data($event, 'module_updated'));
}
+
+ /**
+ * Handle the course_module_deleted event.
+ * @param \core\event\course_module_deleted $event
+ */
+ public static function course_module_deleted(\core\event\course_module_deleted $event) {
+ global $DB;
+ $eventdata = $event->get_data();
+
+ $DB->delete_records('plagiarism_turnitinsim_sub', array('cm' => $eventdata['contextinstanceid']));
+ $DB->delete_records('plagiarism_turnitinsim_mod', array('cm' => $eventdata['contextinstanceid']));
+ }
}
\ No newline at end of file
diff --git a/classes/quiz.class.php b/classes/quiz.class.php
index ec2ce08..99f1b4f 100644
--- a/classes/quiz.class.php
+++ b/classes/quiz.class.php
@@ -133,15 +133,13 @@ public function show_other_posts_links($courseid, $userid) {
* @throws dml_exception
*/
public function create_submission_event_data($linkarray) {
- global $USER;
-
$cm = get_coursemodule_from_id('', $linkarray['cmid']);
$eventdata = array();
$eventdata['contextinstanceid'] = $linkarray['cmid'];
$eventdata['eventtype'] = 'quiz_submitted';
- $eventdata['userid'] = $USER->id;
+ $eventdata['userid'] = $linkarray['userid'];
$eventdata['objectid'] = $linkarray['area'];
if (isset($linkarray['file'])) {
diff --git a/classes/request.class.php b/classes/request.class.php
index 828ceba..c9700ee 100644
--- a/classes/request.class.php
+++ b/classes/request.class.php
@@ -281,11 +281,13 @@ public function test_connection($apiurl, $apikey) {
*
* @param object $e The exception.
* @param string $displaystr The string to display for the error.
+ * @param string|object|array $a An object, string or number that can be used
+ * within translation strings
* @throws coding_exception
*/
- public function handle_exception($e, $displaystr = '') {
+ public function handle_exception($e, $displaystr = '', $a = null) {
- $errorstr = get_string($displaystr, 'plagiarism_turnitinsim').PHP_EOL;
+ $errorstr = get_string($displaystr, 'plagiarism_turnitinsim', $a).PHP_EOL;
if (is_callable(array($e, 'getFaultCode'))) {
$errorstr .= get_string('faultcode', 'plagiarism_turnitinsim').": ".$e->getFaultCode().PHP_EOL;
diff --git a/classes/settings.class.php b/classes/settings.class.php
index 93c1f64..dfd1f8b 100644
--- a/classes/settings.class.php
+++ b/classes/settings.class.php
@@ -100,16 +100,36 @@ public function add_settings_to_module($mform, $canconfigureplugin = false, $con
// Immediate.
$label = get_string('reportgen0', 'plagiarism_turnitinsim');
- $reportgen[] = $mform->createElement('radio', 'reportgeneration', null, $label, TURNITINSIM_REPORT_GEN_IMMEDIATE);
+ $reportgen[] = $mform->createElement(
+ 'radio',
+ 'reportgeneration',
+ null,
+ $label,
+ TURNITINSIM_REPORT_GEN_IMMEDIATE,
+ array('class' => 'turnitinsim_settings_radio')
+ );
// Immediate and Due Date.
$label = get_string('reportgen1', 'plagiarism_turnitinsim');
- $reportgen[] = $mform->createElement('radio', 'reportgeneration', null, $label,
- TURNITINSIM_REPORT_GEN_IMMEDIATE_AND_DUEDATE);
+ $reportgen[] = $mform->createElement(
+ 'radio',
+ 'reportgeneration',
+ null,
+ $label,
+ TURNITINSIM_REPORT_GEN_IMMEDIATE_AND_DUEDATE,
+ array('class' => 'turnitinsim_settings_radio')
+ );
// Due Date.
$label = get_string('reportgen2', 'plagiarism_turnitinsim');
- $reportgen[] = $mform->createElement('radio', 'reportgeneration', null, $label, TURNITINSIM_REPORT_GEN_DUEDATE);
+ $reportgen[] = $mform->createElement(
+ 'radio',
+ 'reportgeneration',
+ null,
+ $label,
+ TURNITINSIM_REPORT_GEN_DUEDATE,
+ array('class' => 'turnitinsim_settings_radio')
+ );
// Group Report Gen options together.
$mform->addGroup($reportgen, 'reportgenoptions', get_string('reportgenoptions', 'plagiarism_turnitinsim'), ' ');
@@ -186,7 +206,10 @@ public function save_module_settings($data) {
$settings->id = $modsettings->id;
$DB->update_record('plagiarism_turnitinsim_mod', $settings);
} else {
- $DB->insert_record('plagiarism_turnitinsim_mod', $settings);
+ // Inserts only happen on activity creation, so if turnitinenabled is false - don't insert.
+ if ($settings->turnitinenabled) {
+ $DB->insert_record('plagiarism_turnitinsim_mod', $settings);
+ }
}
}
diff --git a/classes/submission.class.php b/classes/submission.class.php
index 44c54f0..2fd0332 100644
--- a/classes/submission.class.php
+++ b/classes/submission.class.php
@@ -314,7 +314,7 @@ public function create_group_metadata() {
$assignment = array(
'id' => $cm->id,
'name' => $cm->name,
- 'type' => TURNITINSIM_GROUP_TYPE_ASSIGNMENT
+ 'type' => $cm->modname == "assign" ? "ASSIGNMENT" : strtoupper($cm->modname)
);
// Add course metadata.
@@ -411,6 +411,9 @@ public function create_submission_in_turnitin() {
// Add owners to the metadata.
$request['metadata']['owners'] = $this->create_owners_metadata();
+ // Add original submission time metadata.
+ $request['metadata']['original_submitted_time'] = gmdate("Y-m-d\TH:i:s\Z", time());
+
// Add EULA acceptance details to submission if the submitter has accepted it.
$language = $this->tsrequest->get_language()->localecode;
$locale = ($tssubmitter->get_lasteulaacceptedlang()) ? $tssubmitter->get_lasteulaacceptedlang() : $language;
@@ -597,7 +600,6 @@ public function upload_submission_to_turnitin() {
// Handle response from the API.
$this->handle_upload_response($responsedata, $filename);
} catch (Exception $e) {
-
$this->tsrequest->handle_exception($e, 'taskoutputfailedupload', $this->getturnitinid());
}
}
@@ -945,6 +947,7 @@ public static function get_submission_details($linkarray) {
'type' => 'content', 'cm' => $linkarray['cmid'], 'quizanswer' => $quizanswer));
}
}
+
return $DB->get_record('plagiarism_turnitinsim_sub', array('userid' => $linkarray['userid'],
'cm' => $linkarray['cmid'], 'identifier' => $identifier, 'quizanswer' => $quizanswer));
diff --git a/classes/workshop.class.php b/classes/workshop.class.php
index 98fa969..b983fc2 100644
--- a/classes/workshop.class.php
+++ b/classes/workshop.class.php
@@ -130,7 +130,7 @@ public function show_other_posts_links($courseid, $userid) {
* @throws dml_exception
*/
public function create_submission_event_data($linkarray) {
- global $DB, $USER;
+ global $DB;
$cm = get_coursemodule_from_id('', $linkarray['cmid']);
@@ -138,7 +138,7 @@ public function create_submission_event_data($linkarray) {
$eventdata['contextinstanceid'] = $linkarray['cmid'];
$eventdata['eventtype'] = 'assessable_submitted';
- $eventdata['userid'] = $USER->id;
+ $eventdata['userid'] = $linkarray['userid'];
if (isset($linkarray['file'])) {
$eventdata['other']['pathnamehashes'] = array($linkarray['file']->get_pathnamehash());
diff --git a/db/events.php b/db/events.php
index 76fa369..5f2e4ec 100644
--- a/db/events.php
+++ b/db/events.php
@@ -53,5 +53,9 @@
array(
'eventname' => '\core\event\course_module_updated',
'callback' => 'plagiarism_turnitinsim_observer::module_updated'
- )
+ ),
+ array(
+ 'eventname' => '\core\event\course_module_deleted',
+ 'callback' => 'plagiarism_turnitinsim_observer::course_module_deleted'
+ ),
);
\ No newline at end of file
diff --git a/dbexport.php b/dbexport.php
index ae6ef14..b8c438e 100644
--- a/dbexport.php
+++ b/dbexport.php
@@ -27,6 +27,7 @@
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/dataformatlib.php');
+require_once( __DIR__ . '/utilities/handle_deprecation.php' );
// Restrict access to admins only.
require_login();
@@ -67,7 +68,8 @@
$data = $DB->get_records($table, null, 'id ASC');
// Use Moodle's dataformatting functions to output the data in the desired format.
- download_as_dataformat($exportfile, $dataformat, array_keys($DB->get_columns($table)), $data);
+ handle_deprecation::download_data($exportfile, $dataformat, array_keys($DB->get_columns($table)), $data);
+
exit;
} else {
diff --git a/lang/en/plagiarism_turnitinsim.php b/lang/en/plagiarism_turnitinsim.php
index f03714e..0254b5c 100644
--- a/lang/en/plagiarism_turnitinsim.php
+++ b/lang/en/plagiarism_turnitinsim.php
@@ -53,7 +53,6 @@
$string['indexoptions_help'] = 'Indexed submissions will be available for comparison in Similarity Reports.';
$string['invalidtablename'] = 'Table {$a} could not be exported';
$string['line'] = 'Line';
-$string['loadingcv'] = 'Loading Turnitin Cloud Viewer';
$string['message'] = 'Message';
$string['messageprovider:digital_receipt_student'] = 'Turnitin Student Digital Receipt';
$string['messageprovider:digital_receipt_instructor'] = 'Turnitin Instructor Digital Receipt';
@@ -119,7 +118,7 @@
$string['taskoutputlatesteulanotretrieved'] = 'Latest EULA version could not be retrieved';
$string['taskoutputlatesteularetrievalfailure'] = 'Latest EULA version call failed.';
$string['taskoutputfailedconnection'] = 'There was a problem connecting to the Turnitin API';
-$string['taskoutputfailedcvlaunchurl'] = 'There was a problem requesting a Cloud Viewer launch URL from the Turnitin API for submission id: {$a}';
+$string['taskoutputfailedcvlaunchurl'] = 'There was a problem requesting a Turnitin Viewer URL from the Turnitin API for submission id: {$a}';
$string['taskoutputfailedreportrequest'] = 'There was a problem requesting an originality report generation from the Turnitin API for submission id: {$a}';
$string['taskoutputfailedscorerequest'] = 'There was a problem requesting an originality report score from the Turnitin API for submission id: {$a}';
$string['taskoutputfailedupload'] = 'There was a problem uploading a file to the Turnitin API for submission id: {$a}';
@@ -153,7 +152,7 @@
$string['turnitinfeatures::header'] = 'Turnitin Integrity features';
$string['turnitinfeatures::moreinfo'] = 'For more information on the enabled features and packages available from Turnitin please see http://www.turnitin.com.';
$string['turnitinfeatures::repositories'] = 'Repositories checked against: ';
-$string['turnitinfeatures::viewoptions'] = 'Cloud Viewer options: ';
+$string['turnitinfeatures::viewoptions'] = 'Turnitin Viewer options: ';
$string['turnitinfeatures::eularequired'] = 'Acceptance of the Turnitin EULA is required for all users';
$string['turnitinfeatures::eulanotrequired'] = 'Acceptance of the Turnitin EULA is not required by users';
$string['turnitinhideidentity'] = 'Hide student\'s identity from Turnitin';
@@ -189,8 +188,8 @@
$string['privacy:metadata:plagiarism_turnitinsim_users:lasteulaacceptedlang'] = 'The langauge in which the user last accepted the Turnitin EULA.';
$string['privacy:metadata:plagiarism_turnitinsim_client'] = 'To successfully make a submission to Turnitin, specific user data needs to be exchanged between Moodle and Turnitin. For more information around Moodle Plugins and GDPR, please visit: https://help.turnitin.com/feedback-studio/moodle/moodle-plugins-and-gdpr.htm';
-$string['privacy:metadata:plagiarism_turnitinsim_client:firstname'] = 'The user\'s first name is sent to Turnitin on a Cloud Viewer launch so that the user can be identified.';
-$string['privacy:metadata:plagiarism_turnitinsim_client:lastname'] = 'The user\'s last name is sent to Turnitin on a Cloud Viewer launch so that the user can be identified.';
+$string['privacy:metadata:plagiarism_turnitinsim_client:firstname'] = 'The user\'s first name is sent to Turnitin on a Turnitin Viewer launch so that the user can be identified.';
+$string['privacy:metadata:plagiarism_turnitinsim_client:lastname'] = 'The user\'s last name is sent to Turnitin on a Turnitin Viewer launch so that the user can be identified.';
$string['privacy:metadata:plagiarism_turnitinsim_client:submission_title'] = 'The title of the submission is sent to Turntin so that it is identifiable.';
$string['privacy:metadata:plagiarism_turnitinsim_client:submission_filename'] = 'The name of the submitted file is sent to Turntin so that it is identifiable.';
$string['privacy:metadata:plagiarism_turnitinsim_client:submission_content'] = 'Please be aware that the content of a file/submission is sent to Turnitin for processing.';
diff --git a/amd/src/inbox_eula_launch.js b/lang/ja/plagiarism_turnitinsim.php
similarity index 55%
rename from amd/src/inbox_eula_launch.js
rename to lang/ja/plagiarism_turnitinsim.php
index 1fd49de..f8af95d 100644
--- a/amd/src/inbox_eula_launch.js
+++ b/lang/ja/plagiarism_turnitinsim.php
@@ -1,3 +1,4 @@
+.
/**
- * @module plagiarism_turnitinsim/inbox_eula_launch
+ * Strings for plagiarism_turnitinsim component, language: Japanese.
+ *
+ * This file should only contain *_link strings as other strings are handling through AMOS.
+ *
+ * @package plagiarism_turnitinsim
+ * @copyright 2020 Turnitin
+ * @author David Winn
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-define(['jquery',
- 'core/templates',
- 'core/modal_factory',
- 'plagiarism_turnitinsim/modal_eula'
- ],
- function($, Templates, ModalFactory, ModalTcEula) {
- return {
- inboxEulaLaunch: function() {
- var trigger = $('.eula-row-launch');
-
- ModalFactory.create(
- {
- type: ModalTcEula.TYPE
- },
- trigger
- );
- }
- };
- }
-);
\ No newline at end of file
+$string['help_link'] = 'https://help.turnitin.com/jp/integrity/管理者/moodle.htm#step-four';
diff --git a/lang/ko/plagiarism_turnitinsim.php b/lang/ko/plagiarism_turnitinsim.php
new file mode 100644
index 0000000..b40fd14
--- /dev/null
+++ b/lang/ko/plagiarism_turnitinsim.php
@@ -0,0 +1,28 @@
+.
+
+/**
+ * Strings for plagiarism_turnitinsim component, language: Korean.
+ *
+ * This file should only contain *_link strings as other strings are handling through AMOS.
+ *
+ * @package plagiarism_turnitinsim
+ * @copyright 2020 Turnitin
+ * @author David Winn
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$string['help_link'] = 'https://help.turnitin.com/ko/integrity/관리자/moodle.htm#step-four';
diff --git a/lang/zh_cn/plagiarism_turnitinsim.php b/lang/zh_cn/plagiarism_turnitinsim.php
new file mode 100644
index 0000000..e605ddd
--- /dev/null
+++ b/lang/zh_cn/plagiarism_turnitinsim.php
@@ -0,0 +1,28 @@
+.
+
+/**
+ * Strings for plagiarism_turnitinsim component, language: Simplified Chinese.
+ *
+ * This file should only contain *_link strings as other strings are handling through AMOS.
+ *
+ * @package plagiarism_turnitinsim
+ * @copyright 2020 Turnitin
+ * @author David Winn
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$string['help_link'] = 'https://help.turnitin.com/zh-hans/integrity/管理员身/moodle.htm#step-four';
diff --git a/lang/zh_tw/plagiarism_turnitinsim.php b/lang/zh_tw/plagiarism_turnitinsim.php
new file mode 100644
index 0000000..4fa6c5f
--- /dev/null
+++ b/lang/zh_tw/plagiarism_turnitinsim.php
@@ -0,0 +1,28 @@
+.
+
+/**
+ * Strings for plagiarism_turnitinsim component, language: Traditional Chinese.
+ *
+ * This file should only contain *_link strings as other strings are handling through AMOS.
+ *
+ * @package plagiarism_turnitinsim
+ * @copyright 2020 Turnitin
+ * @author David Winn
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$string['help_link'] = 'https://help.turnitin.com/zh-tw/integrity/管理員/moodle.htm#step-four';
diff --git a/lib.php b/lib.php
index 746ebb6..4d6386c 100644
--- a/lib.php
+++ b/lib.php
@@ -167,14 +167,22 @@ public function get_links($linkarray) {
static $jsloaded;
if (empty($jsloaded)) {
$jsloaded = true;
- $PAGE->requires->string_for_js('loadingcv', 'plagiarism_turnitinsim');
$PAGE->requires->string_for_js('submissiondisplaystatus:queued', 'plagiarism_turnitinsim');
$PAGE->requires->js_call_amd('plagiarism_turnitinsim/cv_launch', 'openCv');
$PAGE->requires->js_call_amd('plagiarism_turnitinsim/resend_submission', 'resendSubmission');
- $PAGE->requires->js_call_amd('plagiarism_turnitinsim/inbox_eula_launch', 'inboxEulaLaunch');
}
$output = '';
+ // Don't show links for certain file types as they won't have been submitted to Turnitin.
+ if (!empty($linkarray["file"])) {
+ $file = $linkarray["file"];
+ $filearea = $file->get_filearea();
+ $nonsubmittingareas = array("feedback_files", "introattachment");
+ if (in_array($filearea, $nonsubmittingareas)) {
+ return $output;
+ }
+ }
+
// If this is a quiz, retrieve the cmid.
$component = (!empty($linkarray['component'])) ? $linkarray['component'] : "";
if ($component == "qtype_essay" && !empty($linkarray['area'])) {
@@ -226,6 +234,7 @@ public function get_links($linkarray) {
// Display cv link and OR score or status.
if ((!empty($linkarray['file'])) || (!empty($linkarray['content']))) {
$submissionid = '';
+ $eulaconfirm = '';
$showresubmitlink = false;
$submission = null;
@@ -238,16 +247,17 @@ public function get_links($linkarray) {
return $output;
}
+ $plagiarismsettings = $this->get_settings($cm->id);
+
if ($plagiarismfile) {
$submission = new plagiarism_turnitinsim_submission(new plagiarism_turnitinsim_request(), $plagiarismfile->id);
- }
- // If the user is a student and they are not allowed to view reports,
- // and they have accepted the EULA then return empty output.
- $plagiarismsettings = $this->get_settings($cm->id);
- if (!$instructor && empty($plagiarismsettings->accessstudents) &&
- $submission->getstatus() !== TURNITINSIM_SUBMISSION_STATUS_EULA_NOT_ACCEPTED) {
- return $output;
+ // If the user is a student and they are not allowed to view reports,
+ // and they have accepted the EULA then return empty output.
+ if (!$instructor && empty($plagiarismsettings->accessstudents) &&
+ $submission->getstatus() !== TURNITINSIM_SUBMISSION_STATUS_EULA_NOT_ACCEPTED) {
+ return $output;
+ }
}
// Render the OR score or current submission status.
@@ -280,26 +290,12 @@ public function get_links($linkarray) {
break;
case TURNITINSIM_SUBMISSION_STATUS_EULA_NOT_ACCEPTED:
- // Allow a modal to be launched with a EULA link and ability to accept.
- $tsrequest = new plagiarism_turnitinsim_request();
- $lang = $tsrequest->get_language();
- $eulaurl = get_config('plagiarism_turnitinsim', 'turnitin_eula_url')."?lang=".$lang->localecode;
-
- $helpicon = $OUTPUT->pix_icon(
- 'help',
- get_string('submissiondisplayerror:eulanotaccepted_help', 'plagiarism_turnitinsim'),
- 'core',
- ['class' => 'eula-row-launch', 'data-eula-link' => $eulaurl]
- );
-
- $eulalaunch = ' '.$helpicon;
-
- $status = html_writer::tag(
- 'span',
- get_string('submissiondisplaystatus:awaitingeula', 'plagiarism_turnitinsim') . $eulalaunch,
- array('class' => 'tii_status_text tii_status_text_eula')
- );
+ $eula = new plagiarism_turnitinsim_eula();
+ $statusset = $eula->get_eula_status($cm->id, $submission->gettype());
+ $status = $statusset['eula-status'];
+ $eulaconfirm = $statusset['eula-confirm'];
$showresubmitlink = false;
+
break;
case TURNITINSIM_SUBMISSION_STATUS_ERROR:
@@ -350,8 +346,18 @@ public function get_links($linkarray) {
$eventdata = $moduleobject->create_submission_event_data($linkarray);
$this->submission_handler($eventdata);
- $status = html_writer::tag('span', get_string('submissiondisplaystatus:queued',
- 'plagiarism_turnitinsim'));
+ // Check if student has accepted the EULA.
+ $plagiarismfile = plagiarism_turnitinsim_submission::get_submission_details($linkarray);
+
+ if ($plagiarismfile->status === TURNITINSIM_SUBMISSION_STATUS_EULA_NOT_ACCEPTED) {
+ $eula = new plagiarism_turnitinsim_eula();
+ $statusset = $eula->get_eula_status($cm->id, $submission->gettype());
+ $status = $statusset['eula-status'];
+ $eulaconfirm = $statusset['eula-confirm'];
+ } else {
+ $status = html_writer::tag('span', get_string('submissiondisplaystatus:queued',
+ 'plagiarism_turnitinsim'));
+ }
}
// Render a Turnitin logo.
@@ -361,8 +367,10 @@ public function get_links($linkarray) {
$resubmitlink = ($instructor && $showresubmitlink) ? $this->render_resubmit_link($submission->getid()) : '';
// Output rendered status and resubmission link if applicable.
- $output .= html_writer::tag('div', $turnitinicon.$status.$resubmitlink,
- array('class' => 'turnitinsim_status submission_'.$submissionid));
+ if ($instructor || (!$instructor && $plagiarismsettings->accessstudents)) {
+ $output .= html_writer::tag('div', $eulaconfirm . $turnitinicon . $status . $resubmitlink,
+ array('class' => 'turnitinsim_status submission_' . $submissionid));
+ }
}
return html_writer::tag('div', $output, array('class' => 'turnitinsim_links'));
@@ -432,84 +440,99 @@ public function render_resubmit_link($submissionid) {
* Hook to allow a disclosure to be printed notifying users what will happen with their submission.
*
* @param int $cmid - course module id
+ * @param string $submissiontype - The type of submission - file or content.
* @return string
* @throws coding_exception
* @throws dml_exception
*/
- public function print_disclosure($cmid) {
+ public function print_disclosure($cmid, $submissiontype = 'file') {
global $CFG, $PAGE, $USER;
- // Return empty output if the plugin is not being used.
- if ($cmid > -1) {
- $cm = get_coursemodule_from_id('', $cmid);
- if (!$this->is_plugin_active($cm)) {
- return '';
+ // Avoid printing the EULA acceptance box more than once.
+ // This needs to be shown twice for a text submission as it exists in the dom twice.
+ // Allowed for unit testing otherwise only the first test that calls this would work.
+ static $disclosurecount = 1;
+ if (($submissiontype == 'file' && $disclosurecount === 1) ||
+ ($submissiontype == 'content' && $disclosurecount <= 2) ||
+ PHPUNIT_TEST) {
+ $disclosurecount++;
+
+ // Return empty output if the plugin is not being used.
+ if ($cmid > -1) {
+ $cm = get_coursemodule_from_id('', $cmid);
+ if (!$this->is_plugin_active($cm)) {
+ return '';
+ }
}
- }
- // Check we have the latest version of the EULA stored.
- // This should only happen the very first time someone submits.
- $eulaversion = get_config('plagiarism_turnitinsim', 'turnitin_eula_version');
- // Overwrite mtrace so when EULA is checked it doesn't output to screen.
- $CFG->mtrace_wrapper = 'plagiarism_turnitinsim_mtrace';
- if (empty($eulaversion)) {
- $tstask = new plagiarism_turnitinsim_task();
- $tstask->check_latest_eula_version();
+ // Check we have the latest version of the EULA stored.
+ // This should only happen the very first time someone submits.
$eulaversion = get_config('plagiarism_turnitinsim', 'turnitin_eula_version');
- }
+ // Overwrite mtrace so when EULA is checked it doesn't output to screen.
+ $CFG->mtrace_wrapper = 'plagiarism_turnitinsim_mtrace';
+ if (empty($eulaversion)) {
+ $tstask = new plagiarism_turnitinsim_task();
+ $tstask->check_latest_eula_version();
+ $eulaversion = get_config('plagiarism_turnitinsim', 'turnitin_eula_version');
+ }
- // We don't need to continue if the user has accepted the latest EULA and/or EULA acceptance is not required.
- $user = new plagiarism_turnitinsim_user($USER->id);
- $features = json_decode(get_config('plagiarism_turnitinsim', 'turnitin_features_enabled'));
+ // We don't need to continue if the user has accepted the latest EULA and/or EULA acceptance is not required.
+ $user = new plagiarism_turnitinsim_user($USER->id);
+ $features = json_decode(get_config('plagiarism_turnitinsim', 'turnitin_features_enabled'));
- if ($user->get_lasteulaaccepted() == $eulaversion) {
- return html_writer::tag(
- 'div',
- get_string('eulaalreadyaccepted', 'plagiarism_turnitinsim'),
- array('class' => 'eulacontainer', 'id' => 'eulacontainer')
- );
- }
+ if ($user->get_lasteulaaccepted() == $eulaversion) {
+ return html_writer::tag(
+ 'div',
+ get_string('eulaalreadyaccepted', 'plagiarism_turnitinsim'),
+ array('class' => 'turnitinsim_eulacontainer', 'id' => 'turnitinsim_eulacontainer')
+ );
+ }
- if (!(bool)$features->tenant->require_eula) {
- return html_writer::tag(
- 'div',
- get_string('eulanotrequired', 'plagiarism_turnitinsim'),
- array('class' => 'eulacontainer', 'id' => 'eulacontainer')
- );
- }
+ if (!(bool)$features->tenant->require_eula) {
+ return html_writer::tag(
+ 'div',
+ get_string('eulanotrequired', 'plagiarism_turnitinsim'),
+ array('class' => 'turnitinsim_eulacontainer', 'id' => 'turnitinsim_eulacontainer')
+ );
+ }
- // Require the JS module to handle the user's eula response.
- $PAGE->requires->string_for_js('eulaaccepted', 'plagiarism_turnitinsim');
- $PAGE->requires->string_for_js('euladeclined', 'plagiarism_turnitinsim');
- $PAGE->requires->js_call_amd('plagiarism_turnitinsim/eula_response', 'eulaResponse');
-
- // Link to open the Turnitin EULA in a new tab.
- $tsrequest = new plagiarism_turnitinsim_request();
- $lang = $tsrequest->get_language();
- $eulaurl = get_config('plagiarism_turnitinsim', 'turnitin_eula_url')."?lang=".$lang->localecode;
- $eulastring = ($cmid > -1) ? 'eulalink' : 'eulalinkgeneric';
- $eulalink = get_string($eulastring, 'plagiarism_turnitinsim', $eulaurl);
-
- // Button to allow the user to accept the Turnitin EULA.
- $eulaacceptbtn = html_writer::tag('button',
- get_string('eulaaccept', 'plagiarism_turnitinsim'),
- array('class' => 'btn btn-primary', 'id' => 'pp-eula-accept')
- );
+ // Require the JS module to handle the user's eula response.
+ $PAGE->requires->string_for_js('eulaaccepted', 'plagiarism_turnitinsim');
+ $PAGE->requires->string_for_js('euladeclined', 'plagiarism_turnitinsim');
+ $PAGE->requires->string_for_js('submissiondisplaystatus:queued', 'plagiarism_turnitinsim');
+ $PAGE->requires->js_call_amd('plagiarism_turnitinsim/eula_response', 'eulaResponse');
+
+ // Link to open the Turnitin EULA in a new tab.
+ $tsrequest = new plagiarism_turnitinsim_request();
+ $lang = $tsrequest->get_language();
+ $eulaurl = get_config('plagiarism_turnitinsim', 'turnitin_eula_url')."?lang=".$lang->localecode;
+ $eulastring = ($cmid > -1) ? 'eulalink' : 'eulalinkgeneric';
+ $eulalink = get_string($eulastring, 'plagiarism_turnitinsim', $eulaurl);
+
+ // Button to allow the user to accept the Turnitin EULA.
+ $eulaacceptbtn = html_writer::tag('span',
+ get_string('eulaaccept', 'plagiarism_turnitinsim'),
+ array('class' => 'btn btn-primary', 'id' => 'pp-eula-accept')
+ );
- // Button to allow the user to decline the Turnitin EULA.
- $euladeclinebtn = html_writer::tag('button',
- get_string('euladecline', 'plagiarism_turnitinsim'),
- array('class' => 'btn btn-secondary', 'id' => 'pp-eula-decline')
- );
+ // Button to allow the user to decline the Turnitin EULA.
+ $euladeclinebtn = html_writer::tag('span',
+ get_string('euladecline', 'plagiarism_turnitinsim'),
+ array('class' => 'btn btn-secondary', 'id' => 'pp-eula-decline')
+ );
- // Output EULA container.
- $output = html_writer::tag(
- 'div',
- $eulalink.$eulaacceptbtn.$euladeclinebtn,
- array('class' => 'eulacontainer', 'id' => 'eulacontainer')
- );
+ // Output EULA container.
+ $output = html_writer::tag(
+ 'div',
+ html_writer::tag(
+ 'p',
+ $eulalink
+ ).$eulaacceptbtn.$euladeclinebtn,
+ array('class' => 'turnitinsim_eulacontainer', 'id' => 'turnitinsim_eulacontainer')
+ );
- return $output;
+ return $output;
+ }
}
/**
@@ -662,7 +685,8 @@ public function submission_handler($eventdata) {
}
// If the submitter has not accepted the EULA then flag accordingly.
- if ($submitter->get_lasteulaaccepted() < get_config('plagiarism_turnitinsim', 'turnitin_eula_version')) {
+ $authoruser = new plagiarism_turnitinsim_user($author);
+ if ($authoruser->get_lasteulaaccepted() < get_config('plagiarism_turnitinsim', 'turnitin_eula_version')) {
$tssubmission->setstatus(TURNITINSIM_SUBMISSION_STATUS_EULA_NOT_ACCEPTED);
$tssubmission->update();
return true;
@@ -725,6 +749,15 @@ public function queue_files($cm, $eventdata, $sendtoturnitin, $features, $quizan
$submission = $DB->get_record_select('plagiarism_turnitinsim_sub', $query, $params);
$filedetails = $tssubmission->get_file_details();
+ // Do not submit feedback or into files.
+ if ($filedetails) {
+ $filearea = $filedetails->get_filearea();
+ $nonsubmittingareas = array("feedback_files", "introattachment");
+ if (in_array($filearea, $nonsubmittingareas)) {
+ return true;
+ }
+ }
+
// Check that the file exists and is not empty.
if (!$filedetails) {
$tssubmission->settogenerate(0);
@@ -761,8 +794,9 @@ public function queue_files($cm, $eventdata, $sendtoturnitin, $features, $quizan
}
// If the submitter has not accepted the EULA then flag accordingly.
- if ((empty($submitter->get_lasteulaaccepted()) ||
- $submitter->get_lasteulaaccepted() < get_config('plagiarism_turnitinsim', 'turnitin_eula_version')) &&
+ $authoruser = new plagiarism_turnitinsim_user($author);
+ if ((empty($authoruser->get_lasteulaaccepted()) ||
+ $authoruser->get_lasteulaaccepted() < get_config('plagiarism_turnitinsim', 'turnitin_eula_version')) &&
(bool)$features->tenant->require_eula
) {
$tssubmission->setstatus(TURNITINSIM_SUBMISSION_STATUS_EULA_NOT_ACCEPTED);
diff --git a/pix/tiiLogo.svg b/pix/tiiLogo.svg
new file mode 100644
index 0000000..22da669
--- /dev/null
+++ b/pix/tiiLogo.svg
@@ -0,0 +1,18 @@
+
\ No newline at end of file
diff --git a/styles.css b/styles.css
index fdcbca0..8f52a39 100644
--- a/styles.css
+++ b/styles.css
@@ -42,7 +42,7 @@
}
.turnitinsim_eulacontainer #pp-eula-accept {
- margin-left: 20px;
+ margin-right: 5px;
}
/* Icons in get_links */
@@ -126,4 +126,72 @@
.turnitinsim_links .turnitinsim_status .or_score_colour_100 {
background: #db4221;
color: #fff;
-}
\ No newline at end of file
+}
+
+.form-group .form-inline .form-check-inline.form-check-label.fitem.turnitinsim_settings_radio {
+ margin-right: 0;
+}
+
+.turnitinsim_loadingLogo {
+ width: 250px;
+ height: 72px;
+ display: inline-block;
+}
+
+.turnitinsim_Loading {
+ text-align: center;
+ position: absolute;
+ top: 0;
+ bottom: 0;
+ left: 0;
+ right: 0;
+ height: 168px;
+ margin: auto;
+}
+
+.turnitinsim_Loading_Circles {
+ margin-top: 40px;
+}
+
+.turnitinsim_Loading_Circle-1 {
+ animation-delay: -0.32s;
+ margin-right: 7px;
+}
+
+.turnitinsim_Loading_Circle-1,
+.turnitinsim_Loading_Circle-2,
+.turnitinsim_Loading_Circle-3 {
+ background-color: #BAD8EE;
+ animation-name: three-bubbles;
+ animation-duration: 2s;
+ animation-iteration-count: infinite;
+ border-radius: 100%;
+ display: inline-block;
+}
+
+.turnitinsim_Loading_Circle-2 {
+ width: 24px;
+ height: 24px;
+ animation-delay: -0.16s;
+}
+
+.turnitinsim_Loading_Circle-3 {
+ margin-left: 7px;
+}
+
+.turnitinsim_Loading_Circle-1,
+.turnitinsim_Loading_Circle-3 {
+ width: 16px;
+ height: 16px;
+ opacity: 0.5;
+ margin-bottom: 3px;
+}
+
+@keyframes three-bubbles {
+ 0%, 80%, 100% {
+ transform: scale(0);
+ }
+ 40% {
+ transform: scale(1);
+ }
+}
diff --git a/templates/modal_eula.mustache b/templates/modal_eula.mustache
deleted file mode 100644
index e639214..0000000
--- a/templates/modal_eula.mustache
+++ /dev/null
@@ -1,49 +0,0 @@
-{{!
- This file is part of Moodle - http://moodle.org/
-
- Moodle is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- Moodle is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Moodle. If not, see .
-}}
-{{!
- @template plagiarism_turnitinsim/modal_eula
-
- Shown for a user to accept or decline the EULA.
-
- Classes required for JS:
- * none
-
- Data attributes required for JS:
- * none
-
- Context variables required for this template:
- * title Content for the title
- * body Content for the body
- * footer Content for the footer
-
- Example context (json):
- {
- "title": "Example modal",
- "body": "Some example content for the body",
- "footer": "Accept, decline buttons."
- }
-}}
-{{< core/modal }}
- {{$title}}{{# str }} eulaheader, plagiarism_turnitinsim {{/ str }}{{/title}}
- {{$body}}
-
- {{/body}}
- {{$footer}}
-
-
- {{/footer}}
-{{/ core/modal }}
\ No newline at end of file
diff --git a/tests/classes/assign_test.php b/tests/classes/assign.class_test.php
similarity index 99%
rename from tests/classes/assign_test.php
rename to tests/classes/assign.class_test.php
index 1cb55c0..4011595 100644
--- a/tests/classes/assign_test.php
+++ b/tests/classes/assign.class_test.php
@@ -32,7 +32,7 @@
/**
* Tests for assign module class for plagiarism_turnitinsim component.
*/
-class assign_test extends advanced_testcase {
+class assign_class_testcase extends advanced_testcase {
/**
* This is text content for unit testing a text submission.
@@ -42,7 +42,7 @@ class assign_test extends advanced_testcase {
/**
* Set config for use in the tests.
*/
- public function setup() {
+ public function setUp(): void {
global $DB;
// Set plugin as enabled in config for this module type.
diff --git a/tests/classes/tscallback_test.php b/tests/classes/callback.class_test.php
similarity index 88%
rename from tests/classes/tscallback_test.php
rename to tests/classes/callback.class_test.php
index 16a807e..b2f2740 100644
--- a/tests/classes/tscallback_test.php
+++ b/tests/classes/callback.class_test.php
@@ -34,12 +34,12 @@
/**
* Tests for Turnitin Integrity submission class.
*/
-class plagiarism_tscallback_class_testcase extends advanced_testcase {
+class callback_class_testcase extends advanced_testcase {
/**
* Set config for use in the tests.
*/
- public function setup() {
+ public function setUp(): void {
global $CFG;
// Set plugin as enabled in config for this module type.
@@ -195,6 +195,41 @@ public function test_create_webhook_in_turnitin_failure() {
$this->assertFalse(get_config('plagiarism_turnitinsim', 'turnitin_webhook_id'));
}
+ /**
+ * Test create webhook where a webhook already exists and needs to be retrieved.
+ */
+ public function test_create_webhook_if_already_exists() {
+ $this->resetAfterTest();
+
+ // Get the response for a failed webhook creation.
+ $existsresponse = file_get_contents(__DIR__ . '/../fixtures/create_webhook_already_exists.json');
+
+ // Get the response for a successfully created webhook.
+ $successresponse = file_get_contents(__DIR__ . '/../fixtures/create_webhook_list_webhooks.json');
+ $jsonresponse = (array)json_decode($successresponse);
+
+ // Test that the webhook does not exist in Moodle.
+ $this->assertFalse(get_config('plagiarism_turnitinsim', 'turnitin_webhook_id'));
+
+ // Mock API request class.
+ $tsrequest = $this->getMockBuilder(plagiarism_turnitinsim_request::class)
+ ->setMethods(['send_request'])
+ ->setConstructorArgs([TURNITINSIM_ENDPOINT_WEBHOOKS])
+ ->getMock();
+
+ // Mock API send request method.
+ $tsrequest->expects($this->exactly(2))
+ ->method('send_request')
+ ->willReturnOnConsecutiveCalls($existsresponse, $successresponse);
+
+ // Attempt to create webhook. This should retrieve an existing webhook.
+ $tscallback = new plagiarism_turnitinsim_callback( $tsrequest );
+ $tscallback->create_webhook();
+
+ // Test that the webhook is created.
+ $this->assertEquals($jsonresponse[0]->id, get_config('plagiarism_turnitinsim', 'turnitin_webhook_id'));
+ }
+
/**
* Test create webhook failed request to Turnitin.
*/
diff --git a/tests/classes/tssettingsdefaultsform_test.php b/tests/classes/defaults_form_class_test.php
similarity index 92%
rename from tests/classes/tssettingsdefaultsform_test.php
rename to tests/classes/defaults_form_class_test.php
index 4e9951a..965bca5 100644
--- a/tests/classes/tssettingsdefaultsform_test.php
+++ b/tests/classes/defaults_form_class_test.php
@@ -27,16 +27,17 @@
global $CFG;
require_once($CFG->dirroot . '/plagiarism/turnitinsim/classes/defaults_form.class.php');
+require_once($CFG->dirroot . '/plagiarism/turnitinsim/utilities/handle_deprecation.php');
/**
* Tests for default settings form.
*/
-class plagiarism_tsdefaultsform_testcase extends advanced_testcase {
+class defaultsform_class_testcase extends advanced_testcase {
/**
* Set config for use in the tests.
*/
- public function setup() {
+ public function setUp(): void {
// Set API details in config.
set_config('turnitinapiurl', 'http://www.example.com', 'plagiarism_turnitinsim');
set_config('turnitinapikey', 1234, 'plagiarism_turnitinsim');
@@ -87,6 +88,6 @@ public function test_display() {
$form = new plagiarism_turnitinsim_defaults_form();
$output = $form->display();
- $this->assertContains('', $output);
+ handle_deprecation::assertcontains($this, '', $output);
}
}
\ No newline at end of file
diff --git a/tests/classes/eula.class_test.php b/tests/classes/eula.class_test.php
new file mode 100644
index 0000000..c85773b
--- /dev/null
+++ b/tests/classes/eula.class_test.php
@@ -0,0 +1,297 @@
+.
+
+/**
+ * Unit tests for (some of) plagiarism/turnitinsim/classes/eula.class.php.
+ *
+ * @package plagiarism_turnitinsim
+ * @copyright 2018 Turnitin
+ * @author John McGettrick
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+global $CFG;
+require_once($CFG->dirroot . '/plagiarism/turnitinsim/lib.php');
+require_once($CFG->dirroot . '/plagiarism/turnitinsim/tests/utilities.php');
+require_once($CFG->dirroot . '/plagiarism/turnitinsim/tests/turnitinsim_generator.php');
+
+/**
+ * Tests for Turnitin Integrity submission class.
+ */
+class eula_class_testcase extends advanced_testcase {
+
+ /**
+ * Set config for use in the tests.
+ */
+ public function setUp(): void {
+ global $CFG;
+
+ // Set plugin as enabled in config for this module type.
+ set_config('turnitinapiurl', 'http://www.example.com', 'plagiarism_turnitinsim');
+ set_config('turnitinapikey', 1234, 'plagiarism_turnitinsim');
+ set_config('turnitinenablelogging', 0, 'plagiarism_turnitinsim');
+
+ $CFG->mtrace_wrapper = 'plagiarism_turnitinsim_mtrace';
+ }
+
+ /**
+ * Test get latest eula version failed request to Turnitin.
+ */
+ public function test_get_latest_version_failure() {
+ $this->resetAfterTest();
+
+ // Get the response for a failed EULA version retrieval.
+ $response = file_get_contents(__DIR__ . '/../fixtures/get_latest_eula_version_failure.json');
+
+ // Mock API request class.
+ $tsrequest = $this->getMockBuilder(plagiarism_turnitinsim_request::class)
+ ->setMethods(['send_request'])
+ ->setConstructorArgs([TURNITINSIM_ENDPOINT_GET_LATEST_EULA])
+ ->getMock();
+
+ // Mock API send request method.
+ $tsrequest->expects($this->once())
+ ->method('send_request')
+ ->willReturn($response);
+
+ // Get latest EULA version.
+ $tseula = new plagiarism_turnitinsim_eula( $tsrequest );
+ $result = $tseula->get_latest_version();
+
+ // Test that the EULA version has not been retrieved.
+ $this->assertFalse(isset($result->version));
+ }
+
+ /**
+ * Test get latest eula version request to Turnitin fails with exception.
+ */
+ public function test_get_latest_version_exception() {
+ $this->resetAfterTest();
+
+ // Mock API request class.
+ $tsrequest = $this->getMockBuilder(plagiarism_turnitinsim_request::class)
+ ->setMethods(['send_request'])
+ ->setConstructorArgs([TURNITINSIM_ENDPOINT_GET_LATEST_EULA])
+ ->getMock();
+
+ // Mock API send request method.
+ $tsrequest->expects($this->once())
+ ->method('send_request')
+ ->will($this->throwException(new Exception()));
+
+ // Get the latest EULA version.
+ $tseula = new plagiarism_turnitinsim_eula($tsrequest);
+ $result = $tseula->get_latest_version();
+
+ // Test that the latest EULA version has not been retrieved.
+ $this->assertFalse(isset($result->version));
+ }
+
+ /**
+ * Test get latest eula version success request to Turnitin.
+ */
+ public function test_get_latest_version_success() {
+ $this->resetAfterTest();
+
+ // Get the response for a failed EULA version retrieval.
+ $response = file_get_contents(__DIR__ . '/../fixtures/get_latest_eula_version_success.json');
+
+ // Mock API request class.
+ $tsrequest = $this->getMockBuilder(plagiarism_turnitinsim_request::class)
+ ->setMethods(['send_request'])
+ ->setConstructorArgs([TURNITINSIM_ENDPOINT_GET_LATEST_EULA])
+ ->getMock();
+
+ // Mock API send request method.
+ $tsrequest->expects($this->once())
+ ->method('send_request')
+ ->willReturn($response);
+
+ // Get the latest EULA version.
+ $tseula = new plagiarism_turnitinsim_eula( $tsrequest );
+ $result = $tseula->get_latest_version();
+
+ // Test that the latest EULA version has been retrieved.
+ $this->assertTrue(isset($result->version));
+ }
+
+ /**
+ * Test accept EULA updates the status of the EULA for all of a student's submissions.
+ */
+ public function test_accept_eula_saves_eula_and_updates_submissions() {
+ global $DB;
+
+ $this->resetAfterTest();
+
+ set_config('turnitin_eula_version', 'v1beta', 'plagiarism_turnitinsim');
+
+ // Create 3 submissions.
+ $this->turnitinsim_generator = new turnitinsim_generator();
+ $submission = $this->turnitinsim_generator->create_submission(3, TURNITINSIM_SUBMISSION_STATUS_EULA_NOT_ACCEPTED);
+
+ $this->setUser($submission['student']);
+
+ // Insert a user to the TII table.
+ $user = new stdClass();
+ $user->userid = $submission['student']->id;
+ $user->turnitinid = (new handle_deprecation)->create_uuid();
+ $DB->insert_record('plagiarism_turnitinsim_users', $user);
+
+ // Check the data.
+ $submissions = $DB->get_records('plagiarism_turnitinsim_sub');
+ $this->assertCount(3, $submissions);
+
+ $users = $DB->get_records('plagiarism_turnitinsim_users');
+ $this->assertCount(1, $users);
+
+ // Accept the EULA.
+ $tseula = new plagiarism_turnitinsim_eula();
+ $result = json_decode($tseula->accept_eula());
+ $this->assertEquals(true, $result->success);
+
+ // Check the results.
+ $userresult = $DB->get_record('plagiarism_turnitinsim_users', array('userid' => $user->userid));
+ $this->assertEquals('v1beta', $userresult->lasteulaaccepted);
+ $this->assertGreaterThan('lasteulaacceptedtime', time() - 60);
+ $this->assertEquals('en-US', $userresult->lasteulaacceptedlang);
+
+ $submissionresult = $DB->get_records(
+ 'plagiarism_turnitinsim_sub',
+ array('status' => TURNITINSIM_SUBMISSION_STATUS_QUEUED)
+ );
+ $this->assertCount(3, $submissionresult);
+ }
+
+ /**
+ * Test get_eula_status returns expected output for student.
+ */
+ public function test_get_eula_status_for_student() {
+ global $DB;
+
+ $this->resetAfterTest();
+
+ // Set the features enabled.
+ $featuresenabled = file_get_contents(__DIR__ . '/../fixtures/get_features_enabled_success.json');
+ set_config('turnitin_features_enabled', $featuresenabled, 'plagiarism_turnitinsim');
+ set_config('turnitin_eula_version', 'v1-beta', 'plagiarism_turnitinsim');
+
+ // Create a course.
+ $this->course = $this->getDataGenerator()->create_course();
+
+ // Create student and enrol on course.
+ $studentrole = $DB->get_record('role', array('shortname' => 'student'));
+ $this->student = $this->getDataGenerator()->create_user();
+ $this->getDataGenerator()->enrol_user($this->student->id,
+ $this->course->id,
+ $studentrole->id
+ );
+
+ // Log new user in.
+ $this->setUser($this->student);
+
+ // Create assign module.
+ $record = new stdClass();
+ $record->course = $this->course;
+ $module = $this->getDataGenerator()->create_module('assign', $record);
+
+ // Get course module data.
+ $cm = get_coursemodule_from_instance('assign', $module->id);
+ $context = context_module::instance($cm->id);
+ $assign = new assign($context, $cm, $record->course);
+
+ // Set plugin config.
+ plagiarism_plugin_turnitinsim::enable_plugin(1);
+ set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim');
+
+ // Enable plugin for module.
+ $modsettings = array('cm' => $cm->id, 'turnitinenabled' => 1);
+ $DB->insert_record('plagiarism_turnitinsim_mod', $modsettings);
+
+ // Get course module data.
+ $cm = get_coursemodule_from_instance('assign', $module->id);
+
+ $tseula = new plagiarism_turnitinsim_eula();
+ $result = $tseula->get_eula_status($cm->id, 'file');
+
+ handle_deprecation::assertcontains($this,
+ get_string('eulalink', 'plagiarism_turnitinsim', '?lang=en-US'), $result['eula-confirm']);
+ handle_deprecation::assertcontains($this,
+ get_string('submissiondisplayerror:eulanotaccepted_help', 'plagiarism_turnitinsim'), $result['eula-status']);
+ }
+
+ /**
+ * Test get_eula_status returns expected output for instructor.
+ */
+ public function test_get_eula_status_for_instructor() {
+ global $DB;
+
+ $this->resetAfterTest();
+
+ // Set the features enabled.
+ $featuresenabled = file_get_contents(__DIR__ . '/../fixtures/get_features_enabled_success.json');
+ set_config('turnitin_features_enabled', $featuresenabled, 'plagiarism_turnitinsim');
+ set_config('turnitin_eula_version', 'v1-beta', 'plagiarism_turnitinsim');
+
+ // Create a course.
+ $this->course = $this->getDataGenerator()->create_course();
+
+ // Create instructor and enrol on course.
+ $this->instructor = $this->getDataGenerator()->create_user();
+ $instructorrole = $DB->get_record('role', array('shortname' => 'teacher'));
+ $this->getDataGenerator()->enrol_user($this->instructor->id,
+ $this->course->id,
+ $instructorrole->id
+ );
+
+ // Assign capability to instructor to view full reports at course level.
+ $context = context_course::instance($this->course->id);
+ assign_capability('plagiarism/turnitinsim:viewfullreport', CAP_ALLOW, $instructorrole->id, $context->id);
+ role_assign($instructorrole->id, $this->instructor->id, $context->id);
+ accesslib_clear_all_caches_for_unit_testing();
+
+ // Log new user in.
+ $this->setUser($this->instructor);
+
+ // Create assign module.
+ $record = new stdClass();
+ $record->course = $this->course;
+ $module = $this->getDataGenerator()->create_module('assign', $record);
+
+ // Get course module data.
+ $cm = get_coursemodule_from_instance('assign', $module->id);
+ $context = context_module::instance($cm->id);
+
+ // Set plugin config.
+ plagiarism_plugin_turnitinsim::enable_plugin(1);
+ set_config('turnitinmodenabledassign', 1, 'plagiarism_turnitinsim');
+
+ // Enable plugin for module.
+ $modsettings = array('cm' => $cm->id, 'turnitinenabled' => 1);
+ $DB->insert_record('plagiarism_turnitinsim_mod', $modsettings);
+
+ // Get course module data.
+ $cm = get_coursemodule_from_instance('assign', $module->id);
+
+ $tseula = new plagiarism_turnitinsim_eula();
+ $result = $tseula->get_eula_status($cm->id, 'file');
+
+ $this->assertEmpty($result['eula-confirm']);
+ handle_deprecation::assertcontains($this,
+ get_string('submissiondisplayerror:eulanotaccepted_help', 'plagiarism_turnitinsim'), $result['eula-status']);
+ }
+}
\ No newline at end of file
diff --git a/tests/classes/forum_test.php b/tests/classes/forum.class_test.php
similarity index 99%
rename from tests/classes/forum_test.php
rename to tests/classes/forum.class_test.php
index ffd3161..ad2d5ca 100644
--- a/tests/classes/forum_test.php
+++ b/tests/classes/forum.class_test.php
@@ -32,7 +32,7 @@
/**
* Tests for forum module class for plagiarism_turnitinsim component.
*/
-class forum_test extends advanced_testcase {
+class forum_class_testcase extends advanced_testcase {
/**
* Sample text for testing a forum.
@@ -42,7 +42,7 @@ class forum_test extends advanced_testcase {
/**
* Set config for use in the tests.
*/
- public function setup() {
+ public function setUp(): void {
global $DB;
// Set plugin as enabled in config for this module type.
diff --git a/tests/classes/tsgroup_test.php b/tests/classes/group.class_test.php
similarity index 96%
rename from tests/classes/tsgroup_test.php
rename to tests/classes/group.class_test.php
index 27fe237..ecac43d 100644
--- a/tests/classes/tsgroup_test.php
+++ b/tests/classes/group.class_test.php
@@ -31,7 +31,7 @@
/**
* Tests for Turnitin Integrity group class.
*/
-class plagiarism_turnitinsim_group_class_testcase extends advanced_testcase {
+class group_class_testcase extends advanced_testcase {
/**
* Test that group constructor creates a turnitinid in the correct format.
diff --git a/tests/classes/tslogging_request_test.php b/tests/classes/logging_request_class_test.php
similarity index 96%
rename from tests/classes/tslogging_request_test.php
rename to tests/classes/logging_request_class_test.php
index 209e296..3363735 100644
--- a/tests/classes/tslogging_request_test.php
+++ b/tests/classes/logging_request_class_test.php
@@ -32,13 +32,13 @@
/**
* Tests for Turnitin Integrity submission class.
*/
-class plagiarism_turnitinsim_logging_request_class_testcase extends advanced_testcase {
+class logging_request_class_testcase extends advanced_testcase {
/**
* Set config for use in the tests.
*/
- public function setup() {
+ public function setUp(): void {
// Set plugin as enabled in config for this module type.
set_config('turnitinenableremotelogging', 1, 'plagiarism_turnitinsim');
set_config('turnitinenablelogging', 0, 'plagiarism_turnitinsim');
diff --git a/tests/classes/quiz_test.php b/tests/classes/quiz.class_test.php
similarity index 99%
rename from tests/classes/quiz_test.php
rename to tests/classes/quiz.class_test.php
index 08472d7..b40ac20 100644
--- a/tests/classes/quiz_test.php
+++ b/tests/classes/quiz.class_test.php
@@ -34,7 +34,7 @@
/**
* Tests for quiz module class for plagiarism_turnitinsim component
*/
-class quiz_test extends advanced_testcase {
+class quiz_class_testcase extends advanced_testcase {
/**
* Sample text used for unit testing a quiz.
@@ -49,7 +49,7 @@ class quiz_test extends advanced_testcase {
/**
* Set config for use in the tests.
*/
- public function setup() {
+ public function setUp(): void {
// Set plugin as enabled in config for this module type.
set_config('turnitinapiurl', 'http://www.example.com', 'plagiarism_turnitinsim');
set_config('turnitinapikey', 1234, 'plagiarism_turnitinsim');
diff --git a/tests/classes/tsrequest_test.php b/tests/classes/request_class_test.php
similarity index 98%
rename from tests/classes/tsrequest_test.php
rename to tests/classes/request_class_test.php
index c890e3e..549ff5b 100644
--- a/tests/classes/tsrequest_test.php
+++ b/tests/classes/request_class_test.php
@@ -33,12 +33,12 @@
/**
* Tests for Turnitin Integrity submission class.
*/
-class plagiarism_tsrequest_testcase extends advanced_testcase {
+class request_class_testcase extends advanced_testcase {
/**
* Set config for use in the tests.
*/
- public function setup() {
+ public function setUp(): void {
// Set plugin as enabled in config for this module type.
set_config('turnitinapiurl', 'http://www.example.com', 'plagiarism_turnitinsim');
set_config('turnitinapikey', 1234, 'plagiarism_turnitinsim');
diff --git a/tests/classes/tssettings_test.php b/tests/classes/settings_class_test.php
similarity index 89%
rename from tests/classes/tssettings_test.php
rename to tests/classes/settings_class_test.php
index b34bd9b..c9216ad 100644
--- a/tests/classes/tssettings_test.php
+++ b/tests/classes/settings_class_test.php
@@ -32,12 +32,12 @@
/**
* Tests for settings form.
*/
-class plagiarism_tssettings_class_testcase extends advanced_testcase {
+class settings_class_testcase extends advanced_testcase {
/**
* Set config for use in the tests.
*/
- public function setup() {
+ public function setUp(): void {
global $CFG;
// Set API details in config.
@@ -98,6 +98,27 @@ public function test_save_module_settings() {
$this->assertEquals(0, $settings->excludebiblio);
}
+ /**
+ * Test that save module settings does not create an entry if Turnitin is disabled.
+ */
+ public function test_save_module_settings_does_not_create_entry_if_turnitin_disabled() {
+ global $DB;
+
+ $this->resetAfterTest();
+
+ // Create data object for new assignment.
+ $data = new stdClass();
+ $data->coursemodule = 1;
+ $data->turnitinenabled = 0;
+
+ // Save Module Settings to test inserting.
+ $form = new plagiarism_turnitinsim_settings();
+ $form->save_module_settings($data);
+
+ // Check that there is no entry for this module.
+ $this->assertFalse($DB->get_record('plagiarism_turnitinsim_mod', array('cm' => $data->coursemodule)));
+ }
+
/**
* Test that get_enabled_features does not return features on failure.
*/
diff --git a/tests/classes/tssetupform_test.php b/tests/classes/setup_form_class_test.php
similarity index 93%
rename from tests/classes/tssetupform_test.php
rename to tests/classes/setup_form_class_test.php
index dc9b4ab..ccdc031 100644
--- a/tests/classes/tssetupform_test.php
+++ b/tests/classes/setup_form_class_test.php
@@ -27,11 +27,12 @@
global $CFG;
require_once($CFG->dirroot . '/plagiarism/turnitinsim/classes/setup_form.class.php');
+require_once($CFG->dirroot . '/plagiarism/turnitinsim/utilities/handle_deprecation.php');
/**
* Tests for settings form.
*/
-class plagiarism_tssetupform_class_testcase extends advanced_testcase {
+class setupform_class_testcase extends advanced_testcase {
/**
* Plugin enabled.
@@ -132,10 +133,10 @@ public function test_display() {
$form = new plagiarism_turnitinsim_setup_form();
$output = $form->display();
- $this->assertContains('', $output);
+ handle_deprecation::assertcontains($this, '', $output);
// Verify that FERPA statement is present.
- $this->assertContains(get_string('viewerpermissionferpa', 'plagiarism_turnitinsim'), $output);
+ handle_deprecation::assertcontains($this, get_string('viewerpermissionferpa', 'plagiarism_turnitinsim'), $output);
}
/**
@@ -170,6 +171,6 @@ public function test_display_features_features_stored() {
$form = new plagiarism_turnitinsim_setup_form();
$output = $form->display_features();
- $this->assertContains(get_string('turnitinfeatures::moreinfo', 'plagiarism_turnitinsim'), $output);
+ handle_deprecation::assertcontains($this, get_string('turnitinfeatures::moreinfo', 'plagiarism_turnitinsim'), $output);
}
}
\ No newline at end of file
diff --git a/tests/classes/tssubmission_test.php b/tests/classes/submission_class_test.php
similarity index 96%
rename from tests/classes/tssubmission_test.php
rename to tests/classes/submission_class_test.php
index 99523e6..d7e80a8 100644
--- a/tests/classes/tssubmission_test.php
+++ b/tests/classes/submission_class_test.php
@@ -28,11 +28,12 @@
global $CFG;
require_once($CFG->dirroot . '/plagiarism/turnitinsim/lib.php');
require_once($CFG->dirroot . '/plagiarism/turnitinsim/tests/utilities.php');
+require_once($CFG->dirroot . '/plagiarism/turnitinsim/utilities/handle_deprecation.php');
/**
* Tests for Turnitin Integrity submission class.
*/
-class plagiarism_turnitinsim_submission_class_testcase extends advanced_testcase {
+class submission_class_testcase extends advanced_testcase {
/**
* A valid submission ID.
@@ -57,7 +58,7 @@ class plagiarism_turnitinsim_submission_class_testcase extends advanced_testcase
/**
* Set config for use in the tests.
*/
- public function setup() {
+ public function setUp(): void {
global $CFG, $DB;
// Set plugin as enabled in config for this module type.
@@ -137,7 +138,7 @@ public function test_update() {
$tssubmission->update();
// Submission id should now be set.
- $this->assertInternalType("int", $tssubmission->getid());
+ handle_deprecation::assertinternaltypeint($this, $tssubmission->getid());
// Check an id that doesn't exist doesn't return an object.
$submission = $DB->get_record('plagiarism_turnitinsim_sub', array('id' => 0));
@@ -252,15 +253,15 @@ public function test_create_owners_metadata_returns_all_group_member_details_as_
$tsuser2 = new plagiarism_turnitinsim_user($this->student2->id);
// Check user array returns correct details.
- $this->assertContains($this->student1->lastname, $owners[0]['family_name']);
- $this->assertContains($this->student1->firstname, $owners[0]['given_name']);
- $this->assertContains($this->student1->email, $owners[0]['email']);
- $this->assertContains($tsuser1->get_turnitinid(), $owners[0]['id']);
-
- $this->assertContains($this->student2->lastname, $owners[1]['family_name']);
- $this->assertContains($this->student2->firstname, $owners[1]['given_name']);
- $this->assertContains($this->student2->email, $owners[1]['email']);
- $this->assertContains($tsuser2->get_turnitinid(), $owners[1]['id']);
+ handle_deprecation::assertcontains($this, $this->student1->lastname, $owners[0]['family_name']);
+ handle_deprecation::assertcontains($this, $this->student1->firstname, $owners[0]['given_name']);
+ handle_deprecation::assertcontains($this, $this->student1->email, $owners[0]['email']);
+ handle_deprecation::assertcontains($this, $tsuser1->get_turnitinid(), $owners[0]['id']);
+
+ handle_deprecation::assertcontains($this, $this->student2->lastname, $owners[1]['family_name']);
+ handle_deprecation::assertcontains($this, $this->student2->firstname, $owners[1]['given_name']);
+ handle_deprecation::assertcontains($this, $this->student2->email, $owners[1]['email']);
+ handle_deprecation::assertcontains($this, $tsuser2->get_turnitinid(), $owners[1]['id']);
}
/**
@@ -362,6 +363,7 @@ public function test_create_group_metadata_full() {
// Verify assignment is in metadata.
$this->assertEquals($metadata['group']['id'], $cm->id);
$this->assertEquals($metadata['group']['name'], $cm->name);
+ $this->assertEquals($metadata['group']['type'], 'ASSIGNMENT');
// Verify course data is in metadata.
$coursedetails = $DB->get_record('course', array('id' => $cm->course), 'fullname');
@@ -378,6 +380,77 @@ public function test_create_group_metadata_full() {
$this->assertEquals($metadata['group_context']['owners'][0]['email'], $instructor->email);
}
+ /**
+ * Test that create metadata returns expected group type for forum.
+ */
+ public function test_create_group_metadata_forum() {
+ $this->resetAfterTest();
+
+ // Create forum module.
+ $record = new stdClass();
+ $record->course = $this->course;
+ $module = $this->getDataGenerator()->create_module('forum', $record);
+
+ // Get course module data.
+ $cm = get_coursemodule_from_instance('forum', $module->id);
+
+ $tssubmission = new plagiarism_turnitinsim_submission();
+ $tssubmission->setcm($cm->id);
+
+ $metadata = $tssubmission->create_group_metadata();
+
+ // Verify forum is in metadata.
+ $this->assertEquals($metadata['group']['type'], 'FORUM');
+ }
+
+ /**
+ * Test that create metadata returns expected group type for workshop.
+ */
+ public function test_create_group_metadata_workshop() {
+ $this->resetAfterTest();
+
+ $this->setAdminUser();
+
+ // Create workshop module.
+ $record = new stdClass();
+ $record->course = $this->course;
+ $module = $this->getDataGenerator()->create_module('workshop', $record);
+
+ // Get course module data.
+ $cm = get_coursemodule_from_instance('workshop', $module->id);
+
+ $tssubmission = new plagiarism_turnitinsim_submission();
+ $tssubmission->setcm($cm->id);
+
+ $metadata = $tssubmission->create_group_metadata();
+
+ // Verify forum is in metadata.
+ $this->assertEquals($metadata['group']['type'], 'WORKSHOP');
+ }
+
+ /**
+ * Test that create metadata returns expected group type for quiz.
+ */
+ public function test_create_group_metadata_quiz() {
+ $this->resetAfterTest();
+
+ // Create quiz module.
+ $record = new stdClass();
+ $record->course = $this->course;
+ $module = $this->getDataGenerator()->create_module('quiz', $record);
+
+ // Get course module data.
+ $cm = get_coursemodule_from_instance('quiz', $module->id);
+
+ $tssubmission = new plagiarism_turnitinsim_submission();
+ $tssubmission->setcm($cm->id);
+
+ $metadata = $tssubmission->create_group_metadata();
+
+ // Verify forum is in metadata.
+ $this->assertEquals($metadata['group']['type'], 'QUIZ');
+ }
+
/**
* Test that get file details returns false if a file doesn't exist.
*/
diff --git a/tests/classes/tstask_test.php b/tests/classes/task_class_test.php
similarity index 98%
rename from tests/classes/tstask_test.php
rename to tests/classes/task_class_test.php
index c57e2f3..6d45466 100644
--- a/tests/classes/tstask_test.php
+++ b/tests/classes/task_class_test.php
@@ -31,7 +31,7 @@
/**
* Tests for Turnitin Integrity user class.
*/
-class plagiarism_turnitinsim_task_class_testcase extends advanced_testcase {
+class task_class_testcase extends advanced_testcase {
/**
* An example API URL used for unit testing.
@@ -46,7 +46,7 @@ class plagiarism_turnitinsim_task_class_testcase extends advanced_testcase {
/**
* Set config for use in the tests.
*/
- public function setup() {
+ public function setUp(): void {
global $CFG;
// Set plugin as enabled in config for this module type.
diff --git a/tests/classes/tseula_test.php b/tests/classes/tseula_test.php
deleted file mode 100644
index a53139a..0000000
--- a/tests/classes/tseula_test.php
+++ /dev/null
@@ -1,131 +0,0 @@
-.
-
-/**
- * Unit tests for (some of) plagiarism/turnitinsim/classes/eula.class.php.
- *
- * @package plagiarism_turnitinsim
- * @copyright 2018 Turnitin
- * @author John McGettrick
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->dirroot . '/plagiarism/turnitinsim/lib.php');
-require_once($CFG->dirroot . '/plagiarism/turnitinsim/tests/utilities.php');
-
-/**
- * Tests for Turnitin Integrity submission class.
- */
-class plagiarism_turnitinsim_eula_class_testcase extends advanced_testcase {
-
- /**
- * Set config for use in the tests.
- */
- public function setup() {
- global $CFG;
-
- // Set plugin as enabled in config for this module type.
- set_config('turnitinapiurl', 'http://www.example.com', 'plagiarism_turnitinsim');
- set_config('turnitinapikey', 1234, 'plagiarism_turnitinsim');
- set_config('turnitinenablelogging', 0, 'plagiarism_turnitinsim');
-
- $CFG->mtrace_wrapper = 'plagiarism_turnitinsim_mtrace';
- }
-
- /**
- * Test get latest eula version failed request to Turnitin.
- */
- public function test_get_latest_version_failure() {
- $this->resetAfterTest();
-
- // Get the response for a failed EULA version retrieval.
- $response = file_get_contents(__DIR__ . '/../fixtures/get_latest_eula_version_failure.json');
-
- // Mock API request class.
- $tsrequest = $this->getMockBuilder(plagiarism_turnitinsim_request::class)
- ->setMethods(['send_request'])
- ->setConstructorArgs([TURNITINSIM_ENDPOINT_GET_LATEST_EULA])
- ->getMock();
-
- // Mock API send request method.
- $tsrequest->expects($this->once())
- ->method('send_request')
- ->willReturn($response);
-
- // Get latest EULA version.
- $tseula = new plagiarism_turnitinsim_eula( $tsrequest );
- $result = $tseula->get_latest_version();
-
- // Test that the EULA version has not been retrieved.
- $this->assertFalse(isset($result->version));
- }
-
- /**
- * Test get latest eula version request to Turnitin fails with exception.
- */
- public function test_get_latest_version_exception() {
- $this->resetAfterTest();
-
- // Mock API request class.
- $tsrequest = $this->getMockBuilder(plagiarism_turnitinsim_request::class)
- ->setMethods(['send_request'])
- ->setConstructorArgs([TURNITINSIM_ENDPOINT_GET_LATEST_EULA])
- ->getMock();
-
- // Mock API send request method.
- $tsrequest->expects($this->once())
- ->method('send_request')
- ->will($this->throwException(new Exception()));
-
- // Get the latest EULA version.
- $tseula = new plagiarism_turnitinsim_eula($tsrequest);
- $result = $tseula->get_latest_version();
-
- // Test that the latest EULA version has not been retrieved.
- $this->assertFalse(isset($result->version));
- }
-
- /**
- * Test get latest eula version success request to Turnitin.
- */
- public function test_get_latest_version_success() {
- $this->resetAfterTest();
-
- // Get the response for a failed EULA version retrieval.
- $response = file_get_contents(__DIR__ . '/../fixtures/get_latest_eula_version_success.json');
-
- // Mock API request class.
- $tsrequest = $this->getMockBuilder(plagiarism_turnitinsim_request::class)
- ->setMethods(['send_request'])
- ->setConstructorArgs([TURNITINSIM_ENDPOINT_GET_LATEST_EULA])
- ->getMock();
-
- // Mock API send request method.
- $tsrequest->expects($this->once())
- ->method('send_request')
- ->willReturn($response);
-
- // Get the latest EULA version.
- $tseula = new plagiarism_turnitinsim_eula( $tsrequest );
- $result = $tseula->get_latest_version();
-
- // Test that the latest EULA version has been retrieved.
- $this->assertTrue(isset($result->version));
- }
-}
\ No newline at end of file
diff --git a/tests/classes/tsuser_test.php b/tests/classes/user_class_test.php
similarity index 95%
rename from tests/classes/tsuser_test.php
rename to tests/classes/user_class_test.php
index 909aae0..fc380f1 100644
--- a/tests/classes/tsuser_test.php
+++ b/tests/classes/user_class_test.php
@@ -31,7 +31,7 @@
/**
* Tests for Turnitin Integrity user class.
*/
-class plagiarism_turnitinsim_user_class_testcase extends advanced_testcase {
+class user_class_testcase extends advanced_testcase {
/**
* Test that user constructor creates a turnitinid in the correct format.
diff --git a/tests/classes/workshop_test.php b/tests/classes/workshop_class_test.php
similarity index 99%
rename from tests/classes/workshop_test.php
rename to tests/classes/workshop_class_test.php
index 0fdf992..e2dc7ae 100644
--- a/tests/classes/workshop_test.php
+++ b/tests/classes/workshop_class_test.php
@@ -34,7 +34,7 @@
/**
* Tests for workshop module class for plagiarism_turnitinsim component
*/
-class workshop_test extends advanced_testcase {
+class workshop_class_testcase extends advanced_testcase {
/**
* Sample text used for unit testing a workshop.
@@ -44,7 +44,7 @@ class workshop_test extends advanced_testcase {
/**
* Set config for use in the tests.
*/
- public function setup() {
+ public function setUp(): void {
// Set plugin as enabled in config for this module type.
set_config('turnitinapiurl', 'http://www.example.com', 'plagiarism_turnitinsim');
set_config('turnitinapikey', 1234, 'plagiarism_turnitinsim');
diff --git a/tests/fixtures/create_webhook_already_exists.json b/tests/fixtures/create_webhook_already_exists.json
new file mode 100644
index 0000000..2762772
--- /dev/null
+++ b/tests/fixtures/create_webhook_already_exists.json
@@ -0,0 +1,5 @@
+{
+ "status": 409,
+ "message": "A webhook with the same URL already exist. Either update or delete the existing webhook.",
+ "httpstatus": 409
+}
\ No newline at end of file
diff --git a/tests/fixtures/create_webhook_list_webhooks.json b/tests/fixtures/create_webhook_list_webhooks.json
new file mode 100644
index 0000000..8d94ffe
--- /dev/null
+++ b/tests/fixtures/create_webhook_list_webhooks.json
@@ -0,0 +1,28 @@
+[
+ {
+ "id": "a7275318-232a-43ef-a3d6-8f3b732effa7",
+ "url": "https://www.example.com/moodle/plagiarism/turnitinsim/callbacks.php",
+ "description": "testing webhook",
+ "created_time": "2017-11-28T14:20:34.934Z",
+ "event_types": [
+ "SIMILARITY_COMPLETE",
+ "SUBMISSION_COMPLETE",
+ "SIMILARITY_UPDATED"
+ ],
+ "allow_insecure": false,
+ "httpstatus": 201
+ },
+ {
+ "id": "2d294ff3-f032-4562-adab-9538727c3ed7",
+ "url": "https://www.example.com/moodle/extra/plagiarism/turnitinsim/callbacks.php",
+ "description": "testing webhook",
+ "created_time": "2020-11-28T14:20:34.934Z",
+ "event_types": [
+ "SIMILARITY_COMPLETE",
+ "SUBMISSION_COMPLETE",
+ "SIMILARITY_UPDATED"
+ ],
+ "allow_insecure": false,
+ "httpstatus": 201
+ }
+]
\ No newline at end of file
diff --git a/tests/lib_test.php b/tests/lib_test.php
index e309bdc..54c35e5 100644
--- a/tests/lib_test.php
+++ b/tests/lib_test.php
@@ -28,6 +28,8 @@
global $CFG;
require_once($CFG->dirroot . '/plagiarism/turnitinsim/lib.php');
require_once($CFG->dirroot . '/plagiarism/turnitinsim/classes/setup_form.class.php');
+require_once($CFG->dirroot . '/plagiarism/turnitinsim/utilities/handle_deprecation.php');
+require_once($CFG->dirroot . '/plagiarism/turnitinsim/tests/utilities.php');
/**
* Tests for lib methods.
@@ -68,7 +70,7 @@ public function get_module_that_supports_plagiarism() {
/**
* Set config for use in the tests.
*/
- public function setup() {
+ public function setUp(): void {
global $DB;
// Set plugin as enabled in config for this module type.
@@ -276,16 +278,16 @@ public function test_get_links_with_submission() {
// The HTML returned should contain the queued status and a Tii icon.
$plagiarismturnitinsim = new plagiarism_plugin_turnitinsim();
- $this->assertContains(
+ handle_deprecation::assertcontains($this,
''.get_string( 'submissiondisplaystatus:queued', 'plagiarism_turnitinsim').'',
$plagiarismturnitinsim->get_links($linkarray)
);
- $this->assertContains('tii_icon', $plagiarismturnitinsim->get_links($linkarray));
+ handle_deprecation::assertcontains($this, 'tii_icon', $plagiarismturnitinsim->get_links($linkarray));
// Change submission status to Uploaded and verify that pending is displayed.
$tssubmission->setstatus(TURNITINSIM_SUBMISSION_STATUS_UPLOADED);
$tssubmission->update();
- $this->assertContains(
+ handle_deprecation::assertcontains($this,
''.get_string( 'submissiondisplaystatus:pending', 'plagiarism_turnitinsim').'',
$plagiarismturnitinsim->get_links($linkarray)
);
@@ -293,7 +295,7 @@ public function test_get_links_with_submission() {
// Change submission status to Uploaded and verify that not sent is displayed.
$tssubmission->setstatus(TURNITINSIM_SUBMISSION_STATUS_NOT_SENT);
$tssubmission->update();
- $this->assertContains(
+ handle_deprecation::assertcontains($this,
''.get_string( 'submissiondisplaystatus:notsent', 'plagiarism_turnitinsim').'',
$plagiarismturnitinsim->get_links($linkarray)
);
@@ -301,7 +303,7 @@ public function test_get_links_with_submission() {
// Change submission status to Requested and verify that pending is displayed.
$tssubmission->setstatus(TURNITINSIM_SUBMISSION_STATUS_REQUESTED);
$tssubmission->update();
- $this->assertContains(
+ handle_deprecation::assertcontains($this,
''.get_string( 'submissiondisplaystatus:pending', 'plagiarism_turnitinsim').'',
$plagiarismturnitinsim->get_links($linkarray)
);
@@ -311,17 +313,17 @@ public function test_get_links_with_submission() {
$tssubmission->update();
$output = $plagiarismturnitinsim->get_links($linkarray);
- $this->assertContains(
+ handle_deprecation::assertcontains($this,
get_string('submissiondisplaystatus:awaitingeula', 'plagiarism_turnitinsim'),
$output
);
- $this->assertContains(
+ handle_deprecation::assertcontains($this,
get_string('submissiondisplayerror:eulanotaccepted_help', 'plagiarism_turnitinsim'),
$output
);
// Log instructor in and check they do not see a resubmit link.
$this->setUser($this->instructor);
- $this->assertNotContains(
+ handle_deprecation::assertnotcontains($this,
get_string('resubmittoturnitin', 'plagiarism_turnitinsim'),
$output
);
@@ -329,7 +331,7 @@ public function test_get_links_with_submission() {
// Change submission status to a non constant and verify that the default is displayed.
$tssubmission->setstatus('nonconstantstring');
$tssubmission->update();
- $this->assertContains(
+ handle_deprecation::assertcontains($this,
get_string( 'submissiondisplaystatus:unknown', 'plagiarism_turnitinsim'),
$plagiarismturnitinsim->get_links($linkarray));
@@ -337,7 +339,7 @@ public function test_get_links_with_submission() {
$tssubmission->setstatus(TURNITINSIM_SUBMISSION_STATUS_ERROR);
$tssubmission->seterrormessage(TURNITINSIM_SUBMISSION_STATUS_TOO_MUCH_TEXT);
$tssubmission->update();
- $this->assertContains(
+ handle_deprecation::assertcontains($this,
get_string( 'submissiondisplayerror:toomuchtext', 'plagiarism_turnitinsim'),
$plagiarismturnitinsim->get_links($linkarray)
);
@@ -345,14 +347,14 @@ public function test_get_links_with_submission() {
// Change error message to generic and verify that it is displayed.
$tssubmission->seterrormessage('random_string_that_is_not_a_constant');
$tssubmission->update();
- $this->assertContains(
+ handle_deprecation::assertcontains($this,
get_string( 'submissiondisplayerror:generic', 'plagiarism_turnitinsim'),
$plagiarismturnitinsim->get_links($linkarray)
);
// Log instructor in and check they see a resubmit link.
$this->setUser($this->instructor);
- $this->assertContains(
+ handle_deprecation::assertcontains($this,
get_string( 'resubmittoturnitin', 'plagiarism_turnitinsim'),
$plagiarismturnitinsim->get_links($linkarray)
);
@@ -362,8 +364,9 @@ public function test_get_links_with_submission() {
$tssubmission->setstatus(TURNITINSIM_SUBMISSION_STATUS_COMPLETE);
$tssubmission->setoverallscore($score);
$tssubmission->update();
- $this->assertContains($score.'%', $plagiarismturnitinsim->get_links($linkarray));
- $this->assertContains('or_score_colour_' . round($score, -1), $plagiarismturnitinsim->get_links($linkarray));
+ handle_deprecation::assertcontains($this, $score.'%', $plagiarismturnitinsim->get_links($linkarray));
+ handle_deprecation::assertcontains($this,
+ 'or_score_colour_' . round($score, -1), $plagiarismturnitinsim->get_links($linkarray));
}
/**
@@ -374,7 +377,8 @@ public function test_render_resubmit_link() {
$plagiarismturnitinsim = new plagiarism_plugin_turnitinsim();
$submissionid = 1;
- $this->assertContains('pp_resubmit_id_'.$submissionid, $plagiarismturnitinsim->render_resubmit_link($submissionid));
+ handle_deprecation::assertcontains($this,
+ 'pp_resubmit_id_'.$submissionid, $plagiarismturnitinsim->render_resubmit_link($submissionid));
}
/**
@@ -489,7 +493,7 @@ public function test_print_disclosure_display_latest() {
// Verify EULA is output.
$plagiarismturnitinsim = new plagiarism_plugin_turnitinsim();
- $this->assertContains(
+ handle_deprecation::assertcontains($this,
get_string('eulalink', 'plagiarism_turnitinsim', $eulaurl),
$plagiarismturnitinsim->print_disclosure($this->cm->id)
);
@@ -525,7 +529,7 @@ public function test_print_disclosure_not_display_latest() {
// Verify EULA is not output.
$plagiarismturnitinsim = new plagiarism_plugin_turnitinsim();
- $this->assertContains(
+ handle_deprecation::assertcontains($this,
get_string('eulaalreadyaccepted', 'plagiarism_turnitinsim'),
$plagiarismturnitinsim->print_disclosure($this->cm->id));
}
@@ -557,7 +561,7 @@ public function test_print_disclosure_eula_not_displayed_if_not_required() {
// Verify EULA is not output.
$plagiarismturnitinsim = new plagiarism_plugin_turnitinsim();
- $this->assertContains(
+ handle_deprecation::assertcontains($this,
get_string('eulanotrequired', 'plagiarism_turnitinsim'),
$plagiarismturnitinsim->print_disclosure($this->cm->id));
}
diff --git a/tests/privacy/provider_test.php b/tests/privacy/provider_test.php
index 98cbbcb..118985d 100644
--- a/tests/privacy/provider_test.php
+++ b/tests/privacy/provider_test.php
@@ -42,7 +42,7 @@ class plagiarism_turnitinsim_privacy_provider_testcase extends advanced_testcase
/**
* Setup method that runs before each test.
*/
- public function setup() {
+ public function setUp(): void {
$this->turnitinsim_generator = new turnitinsim_generator();
$this->submission = $this->turnitinsim_generator->create_submission();
}
diff --git a/tests/turnitinsim_generator.php b/tests/turnitinsim_generator.php
index 1b3103d..f115425 100644
--- a/tests/turnitinsim_generator.php
+++ b/tests/turnitinsim_generator.php
@@ -88,11 +88,12 @@ public function create_assign_with_student_and_teacher($params = array()) {
* Create a Turnitin submission.
*
* @param int $numsubmissions The number of submissions to create.
+ * @param string $status The Turnitin status for this submission.
* @return array
* @throws coding_exception
* @throws dml_exception
*/
- public function create_submission($numsubmissions = 1) {
+ public function create_submission($numsubmissions = 1, $status = TURNITINSIM_SUBMISSION_STATUS_QUEUED) {
global $DB, $CFG;
require_once($CFG->dirroot . '/mod/assign/tests/base_test.php');
@@ -119,6 +120,7 @@ public function create_submission($numsubmissions = 1) {
$plagiarismfile->submissiontype = 2;
$plagiarismfile->itemid = 12;
$plagiarismfile->submitter = $student->id;
+ $plagiarismfile->status = $status;
for ($i = 0; $i < $numsubmissions; $i++) {
$DB->insert_record('plagiarism_turnitinsim_sub', $plagiarismfile);
diff --git a/utilities/constants.php b/utilities/constants.php
index b74ed6f..f484ac8 100644
--- a/utilities/constants.php
+++ b/utilities/constants.php
@@ -103,9 +103,6 @@
define('TURNITINSIM_REPORT_GEN_RETRY_WAIT_SECONDS', 3600);
define('TURNITINSIM_REPORT_GEN_FIRST_ATTEMPT_RETRY_WAIT_SECONDS', 900);
-// Metadata.
-define('TURNITINSIM_GROUP_TYPE_ASSIGNMENT', 'ASSIGNMENT');
-
// Turnitin Roles.
define('TURNITINSIM_ROLE_INSTRUCTOR', 'INSTRUCTOR');
define('TURNITINSIM_ROLE_LEARNER', 'LEARNER');
\ No newline at end of file
diff --git a/utilities/handle_deprecation.php b/utilities/handle_deprecation.php
index 93e21aa..b10a039 100644
--- a/utilities/handle_deprecation.php
+++ b/utilities/handle_deprecation.php
@@ -97,4 +97,66 @@ public static function get_plugin_enabled() {
return $CFG->branch < 39 ? get_config('plagiarism', 'turnitinsim_use')
: get_config('plagiarism_turnitinsim', 'enabled');
}
+
+ /**
+ * In Moodle 3.9, download_as_dataformat() was deprecated and \core\dataformat::download_data() was introduced.
+ * This method handles our support for multiple Moodle versions.
+ *
+ * @param string $exportfile The name of the file to download.
+ * @param string $dataformat The format of the file.
+ * @param array $columns The names of the columns.
+ * @param string $data The data to download.
+ */
+ public static function download_data($exportfile, $dataformat, $columns, $data) {
+ global $CFG;
+
+ $CFG->branch >= 39 ? \core\dataformat::download_data($exportfile, $dataformat, $columns, $data)
+ : download_as_dataformat($exportfile, $dataformat, $columns, $data);
+ }
+
+ /**
+ * In Moodle 3.10, Moodle switched to use PHPUnit 8.5 which contains deprecations for some assertions.
+ * assertContains was deprecated in favour of the newer assertStringContainsString. (PHPUnit 7.5)
+ * This method handles our support for Moodle versions that use PHPUnit 6.5. (Moodle 3.5 and 3.6)
+ *
+ * @param object $object The test class object.
+ * @param string $needle The string we want to find.
+ * @param string $haystack The string we are searching within.
+ */
+ public static function assertcontains($object, $needle, $haystack) {
+ global $CFG;
+
+ $CFG->branch >= 37 ? $object->assertStringContainsString($needle, $haystack)
+ : $object->assertContains($needle, $haystack);
+ }
+
+ /**
+ * In Moodle 3.10, Moodle switched to use PHPUnit 8.5 which contains deprecations for some assertions.
+ * assertNotContains was deprecated in favour of the newer assertStringNotContainsString. (PHPUnit 7.5)
+ * This method handles our support for Moodle versions that use PHPUnit 6.5. (Moodle 3.5 and 3.6)
+ *
+ * @param object $object The test class object.
+ * @param string $needle The string we want to find.
+ * @param string $haystack The string we are searching within.
+ */
+ public static function assertnotcontains($object, $needle, $haystack) {
+ global $CFG;
+
+ $CFG->branch >= 37 ? $object->assertStringNotContainsString($needle, $haystack)
+ : $object->assertNotContains($needle, $haystack);
+ }
+
+ /**
+ * In Moodle 3.10, Moodle switched to use PHPUnit 8.5 which contains deprecations for some assertions.
+ * assertInternalType was deprecated in favour of newer methods such as assertIsInt. (PHPUnit 7.5)
+ * This method handles our support for Moodle versions that use PHPUnit 6.5. (Moodle 3.5 and 3.6)
+ *
+ * @param object $object The test class object.
+ * @param string $value The value we are looking for.
+ */
+ public static function assertinternaltypeint($object, $value) {
+ global $CFG;
+
+ $CFG->branch >= 37 ? $object->assertIsInt($value) : $object->assertInternalType("int", $value);
+ }
}
\ No newline at end of file
diff --git a/version.php b/version.php
index 82cd46f..11593e6 100644
--- a/version.php
+++ b/version.php
@@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2020092301;
+$plugin->version = 2021011801;
$plugin->release = "v1.2";
$plugin->requires = 2017051500;
$plugin->component = 'plagiarism_turnitinsim';