| 1 | 
           efrain | 
           1 | 
           <?php
  | 
        
        
            | 
            | 
           2 | 
           // This file is part of Moodle - http://moodle.org/
  | 
        
        
            | 
            | 
           3 | 
           //
  | 
        
        
            | 
            | 
           4 | 
           // Moodle is free software: you can redistribute it and/or modify
  | 
        
        
            | 
            | 
           5 | 
           // it under the terms of the GNU General Public License as published by
  | 
        
        
            | 
            | 
           6 | 
           // the Free Software Foundation, either version 3 of the License, or
  | 
        
        
            | 
            | 
           7 | 
           // (at your option) any later version.
  | 
        
        
            | 
            | 
           8 | 
           //
  | 
        
        
            | 
            | 
           9 | 
           // Moodle is distributed in the hope that it will be useful,
  | 
        
        
            | 
            | 
           10 | 
           // but WITHOUT ANY WARRANTY; without even the implied warranty of
  | 
        
        
            | 
            | 
           11 | 
           // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  | 
        
        
            | 
            | 
           12 | 
           // GNU General Public License for more details.
  | 
        
        
            | 
            | 
           13 | 
           //
  | 
        
        
            | 
            | 
           14 | 
           // You should have received a copy of the GNU General Public License
  | 
        
        
            | 
            | 
           15 | 
           // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  | 
        
        
            | 
            | 
           16 | 
              | 
        
        
            | 
            | 
           17 | 
           namespace qbank_exporttoxml;
  | 
        
        
            | 
            | 
           18 | 
              | 
        
        
            | 
            | 
           19 | 
           use context_course;
  | 
        
        
            | 
            | 
           20 | 
           use context_module;
  | 
        
        
            | 
            | 
           21 | 
           use moodle_url;
  | 
        
        
            | 
            | 
           22 | 
           use question_bank;
  | 
        
        
            | 
            | 
           23 | 
              | 
        
        
            | 
            | 
           24 | 
           /**
  | 
        
        
            | 
            | 
           25 | 
            * Class helper unit tests.
  | 
        
        
            | 
            | 
           26 | 
            *
  | 
        
        
            | 
            | 
           27 | 
            * @package    qbank_exporttoxml
  | 
        
        
            | 
            | 
           28 | 
            * @copyright  2021 Catalyst IT Australia Pty Ltd
  | 
        
        
            | 
            | 
           29 | 
            * @author     Safat Shahin <safatshahin@catalyst-au.net>
  | 
        
        
            | 
            | 
           30 | 
            * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
        
        
            | 
            | 
           31 | 
            * @coversDefaultClass \qbank_exporttoxml\helper
  | 
        
        
            | 
            | 
           32 | 
            */
  | 
        
        
           | 1441 | 
           ariadna | 
           33 | 
           final class helper_test extends \advanced_testcase {
  | 
        
        
           | 1 | 
           efrain | 
           34 | 
              | 
        
        
            | 
            | 
           35 | 
               /**
  | 
        
        
            | 
            | 
           36 | 
                * Test the export single question url.
  | 
        
        
            | 
            | 
           37 | 
                *
  | 
        
        
            | 
            | 
           38 | 
                * @covers ::question_get_export_single_question_url
  | 
        
        
            | 
            | 
           39 | 
                */
  | 
        
        
           | 11 | 
           efrain | 
           40 | 
               public function test_question_get_export_single_question_url(): void {
  | 
        
        
           | 1 | 
           efrain | 
           41 | 
                   $this->resetAfterTest();
  | 
        
        
            | 
            | 
           42 | 
                   $generator = $this->getDataGenerator();
  | 
        
        
            | 
            | 
           43 | 
              | 
        
        
            | 
            | 
           44 | 
                   // Create a course and an activity.
  | 
        
        
            | 
            | 
           45 | 
                   $course = $generator->create_course();
  | 
        
        
           | 1441 | 
           ariadna | 
           46 | 
                   $qbank = self::getDataGenerator()->create_module('qbank', ['course' => $course->id]);
  | 
        
        
            | 
            | 
           47 | 
                   $qbankcontext = \context_module::instance($qbank->cmid);
  | 
        
        
           | 1 | 
           efrain | 
           48 | 
                   $quiz = $generator->create_module('quiz', ['course' => $course->id]);
  | 
        
        
            | 
            | 
           49 | 
              | 
        
        
            | 
            | 
           50 | 
                   // Create a question in each place.
  | 
        
        
            | 
            | 
           51 | 
                   $questiongenerator = $generator->get_plugin_generator('core_question');
  | 
        
        
           | 1441 | 
           ariadna | 
           52 | 
                   $qbankqcat = $questiongenerator->create_question_category(['contextid' => $qbankcontext->id]);
  | 
        
        
            | 
            | 
           53 | 
                   $qbankq = $questiongenerator->create_question('truefalse', null, ['category' => $qbankqcat->id]);
  | 
        
        
           | 1 | 
           efrain | 
           54 | 
                   $quizqcat = $questiongenerator->create_question_category(['contextid' => context_module::instance($quiz->cmid)->id]);
  | 
        
        
            | 
            | 
           55 | 
                   $quizq = $questiongenerator->create_question('truefalse', null, ['category' => $quizqcat->id]);
  | 
        
        
            | 
            | 
           56 | 
              | 
        
        
            | 
            | 
           57 | 
                   // Verify some URLs.
  | 
        
        
            | 
            | 
           58 | 
                   $this->assertEquals(new moodle_url('/question/bank/exporttoxml/exportone.php',
  | 
        
        
           | 1441 | 
           ariadna | 
           59 | 
                           ['id' => $qbankq->id, 'cmid' => $qbank->cmid, 'sesskey' => sesskey()]),
  | 
        
        
           | 1 | 
           efrain | 
           60 | 
                           helper::question_get_export_single_question_url(
  | 
        
        
           | 1441 | 
           ariadna | 
           61 | 
                                   question_bank::load_question_data($qbankq->id)));
  | 
        
        
           | 1 | 
           efrain | 
           62 | 
              | 
        
        
            | 
            | 
           63 | 
                   $this->assertEquals(new moodle_url('/question/bank/exporttoxml/exportone.php',
  | 
        
        
            | 
            | 
           64 | 
                           ['id' => $quizq->id, 'cmid' => $quiz->cmid, 'sesskey' => sesskey()]),
  | 
        
        
            | 
            | 
           65 | 
                           helper::question_get_export_single_question_url(
  | 
        
        
            | 
            | 
           66 | 
                                   question_bank::load_question($quizq->id)));
  | 
        
        
            | 
            | 
           67 | 
               }
  | 
        
        
            | 
            | 
           68 | 
              | 
        
        
            | 
            | 
           69 | 
           }
  |