Merge branch 'MDL-68667-master' of git://github.com/aanabit/moodle
authorSara Arjona <sara@moodle.com>
Wed, 27 May 2020 10:26:46 +0000 (12:26 +0200)
committerSara Arjona <sara@moodle.com>
Wed, 27 May 2020 10:26:46 +0000 (12:26 +0200)
1  2 
lib/behat/classes/behat_core_generator.php
repository/filepicker.js

@@@ -648,18 -648,9 +648,18 @@@ class behat_core_generator extends beha
       * We start with test_question_maker::get_question_form_data($data['qtype'], $data['template'])
       * and then overlay the values from any other fields of $data that are set.
       *
 +     * There is a special case that allows you to set qtype to 'missingtype'.
 +     * This creates an example of broken question, such as you might get if you
 +     * install a question type, create some questions of that type, and then
 +     * uninstall the question type (which is prevented through the UI but can
 +     * still happen). This special lets tests verify that these questions are
 +     * handled OK.
 +     *
       * @param array $data the row of data from the behat script.
       */
      protected function process_question($data) {
 +        global $DB;
 +
          if (array_key_exists('questiontext', $data)) {
              $data['questiontext'] = array(
                      'text'   => $data['questiontext'],
              $which = $data['template'];
          }
  
 -        $this->datagenerator->get_plugin_generator('core_question')->create_question($data['qtype'], $which, $data);
 +        $missingtypespecialcase = false;
 +        if ($data['qtype'] === 'missingtype') {
 +            $data['qtype'] = 'essay'; // Actual type uses here does not matter. We just need any question.
 +            $missingtypespecialcase = true;
 +        }
 +
 +        $questiondata = $this->datagenerator->get_plugin_generator('core_question')
 +            ->create_question($data['qtype'], $which, $data);
 +
 +        if ($missingtypespecialcase) {
 +            $DB->set_field('question', 'qtype', 'unknownqtype', ['id' => $questiondata->id]);
 +        }
      }
  
      /**
              $content = $contenttype->create_content($record);
  
              if (!empty($data['filepath'])) {
+                 $filename = basename($data['filepath']);
                  $fs = get_file_storage();
                  $filerecord = array(
                      'component' => 'contentbank',
                      'contextid' => $context->id,
                      'userid' => $data['userid'],
                      'itemid' => $content->get_id(),
-                     'filename' => $data['contentname'],
+                     'filename' => $filename,
                      'filepath' => '/'
                  );
                  $fs->create_file_from_pathname($filerecord, $CFG->dirroot . $data['filepath']);
diff --combined repository/filepicker.js
@@@ -1149,7 -1149,7 +1149,7 @@@ M.core_filepicker.init = function(Y, op
              }, false);
          },
          select_file: function(args) {
-             var argstitle = args.title;
+             var argstitle = args.shorttitle ? args.shorttitle : args.title;
              // Limit the string length so it fits nicely on mobile devices
              var titlelength = 30;
              if (argstitle.length > titlelength) {
  
              // TODO MDL-32532: attributes 'hasauthor' and 'haslicense' need to be obsolete,
              selectnode.one('.fp-setauthor input').set('value', args.author ? args.author : this.options.author);
 -            this.set_selected_license(selectnode.one('.fp-setlicense'), args.license);
 +            this.populateLicensesSelect(selectnode.one('.fp-setlicense select'), args);
              selectnode.one('form #filesource-'+client_id).set('value', args.source);
              selectnode.one('form #filesourcekey-'+client_id).set('value', args.sourcekey);
  
              selectnode.all('.fp-linktype-2,.fp-linktype-1,.fp-linktype-4,.fp-linktype-8').each(function (node) {
                  node.one('input').on('change', changelinktype, this);
              });
 -            this.populate_licenses_select(selectnode.one('.fp-setlicense select'));
              // register event on clicking submit button
              getfile.on('click', function(e) {
                  e.preventDefault();
                      if (origlicense) {
                          origlicense = origlicense.getContent();
                      }
 -                    this.set_preference('recentlicense', license.get('value'));
 +                    if (this.options.rememberuserlicensepref) {
 +                        this.set_preference('recentlicense', license.get('value'));
 +                    }
                  }
                  params['author'] = selectnode.one('.fp-setauthor input').get('value');
  
                  callback: this.display_response
              }, true);
          },
 -        populate_licenses_select: function(node) {
 -            if (!node) {
 +        populateLicensesSelect: function(licensenode, filenode) {
 +            if (!licensenode) {
                  return;
              }
 -            node.setContent('');
 -            var licenses = this.options.licenses;
 -            var recentlicense = this.get_preference('recentlicense');
 -            if (recentlicense) {
 -                this.options.defaultlicense=recentlicense;
 +            licensenode.setContent('');
 +            var selectedlicense = this.options.defaultlicense;
 +            if (filenode) {
 +                // File has a license already, use it.
 +                selectedlicense = filenode.license;
 +            } else if (this.options.rememberuserlicensepref) {
 +                selectedlicense = this.get_preference('recentlicense');
              }
 +            var licenses = this.options.licenses;
              for (var i in licenses) {
 -                var option = Y.Node.create('<option/>').
 -                    set('selected', (this.options.defaultlicense==licenses[i].shortname)).
 +                // Include the file's current license, even if not enabled, to prevent displaying
 +                // misleading information about which license the file currently has assigned to it.
 +                if (licenses[i].enabled == true || (filenode !== undefined && licenses[i].shortname === filenode.license)) {
 +                    var option = Y.Node.create('<option/>').
 +                    set('selected', (licenses[i].shortname == selectedlicense)).
                      set('value', licenses[i].shortname).
                      setContent(Y.Escape.html(licenses[i].fullname));
 -                node.appendChild(option)
 -            }
 -        },
 -        set_selected_license: function(node, value) {
 -            var licenseset = false;
 -            node.all('option').each(function(el) {
 -                if (el.get('value')==value || el.getContent()==value) {
 -                    el.set('selected', true);
 -                    licenseset = true;
 +                    licensenode.appendChild(option);
                  }
 -            });
 -            if (!licenseset) {
 -                // we did not find the value in the list
 -                var recentlicense = this.get_preference('recentlicense');
 -                node.all('option[selected]').set('selected', false);
 -                node.all('option[value='+recentlicense+']').set('selected', true);
              }
          },
          create_object_container: function(data) {
              content.one('.fp-saveas input').set('name', 'title');
              content.one('.fp-setauthor input').setAttrs({name:'author', value:this.options.author});
              content.one('.fp-setlicense select').set('name', 'license');
 -            this.populate_licenses_select(content.one('.fp-setlicense select'))
 +            this.populateLicensesSelect(content.one('.fp-setlicense select'));
              // append hidden inputs to the upload form
              content.one('form').appendChild(Y.Node.create('<input/>').
                  setAttrs({type:'hidden',name:'itemid',value:this.options.itemid}));
                  e.preventDefault();
                  var license = content.one('.fp-setlicense select');
  
 -                this.set_preference('recentlicense', license.get('value'));
 +                if (this.options.rememberuserlicensepref) {
 +                    this.set_preference('recentlicense', license.get('value'));
 +                }
                  if (!content.one('.fp-file input').get('value')) {
                      scope.print_msg(M.util.get_string('nofilesattached', 'repository'), 'error');
                      return false;