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 mod_feedback;
|
|
|
18 |
|
|
|
19 |
use advanced_testcase;
|
|
|
20 |
use ReflectionClass;
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* This file contains unit tests for the mod_feedback items.
|
|
|
24 |
*
|
|
|
25 |
* @package mod_feedback
|
|
|
26 |
* @copyright 2020 Mikhail Golenkov <mikhailgolenkov@catalyst-au.net>
|
|
|
27 |
* @author 2023 David Woloszyn <david.woloszyn@moodle.com>
|
|
|
28 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
29 |
*/
|
|
|
30 |
class item_test extends advanced_testcase {
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Test that get_analysed() for textarea item returns correctly formatted data for exporting to Excel.
|
|
|
34 |
*
|
|
|
35 |
* @covers ::get_analysed
|
|
|
36 |
*/
|
|
|
37 |
public function test_get_analysed_textarea_for_excel_export(): void {
|
|
|
38 |
global $DB;
|
|
|
39 |
$this->resetAfterTest();
|
|
|
40 |
|
|
|
41 |
// Create a course, a feedback activity and an item.
|
|
|
42 |
$course = $this->getDataGenerator()->create_course();
|
|
|
43 |
$feedback = $this->getDataGenerator()->create_module('feedback', ['course' => $course]);
|
|
|
44 |
$feedbackgenerator = $this->getDataGenerator()->get_plugin_generator('mod_feedback');
|
|
|
45 |
$item = $feedbackgenerator->create_item_textfield($feedback);
|
|
|
46 |
|
|
|
47 |
// Expected text.
|
|
|
48 |
$valuetext = "First line\nSecond line";
|
|
|
49 |
|
|
|
50 |
// Create a temporary response.
|
|
|
51 |
$completedid = $DB->insert_record('feedback_completedtmp', (object)['feedback' => $feedback->id]);
|
|
|
52 |
$completed = $DB->get_record('feedback_completedtmp', ['id' => $completedid], '*', MUST_EXIST);
|
|
|
53 |
$value = (object)['course_id' => $course->id, 'item' => $item->id, 'completed' => $completedid, 'value' => $valuetext];
|
|
|
54 |
$DB->insert_record('feedback_valuetmp', $value);
|
|
|
55 |
feedback_save_tmp_values($completed);
|
|
|
56 |
|
|
|
57 |
// Set get_analysed() method accessibility.
|
|
|
58 |
$itemclass = feedback_get_item_class('textarea');
|
|
|
59 |
$reflection = new ReflectionClass($itemclass);
|
|
|
60 |
$method = $reflection->getMethod('get_analysed');
|
|
|
61 |
|
|
|
62 |
// Call the method and indicate it is being used for Excel.
|
|
|
63 |
$actual = $method->invoke(new $itemclass(), $item, false, $course->id, true);
|
|
|
64 |
|
|
|
65 |
// Check returned data maintains the line break.
|
|
|
66 |
$this->assertCount(1, $actual->data);
|
|
|
67 |
$datum = reset($actual->data);
|
|
|
68 |
$this->assertEquals($valuetext, $datum);
|
|
|
69 |
}
|
|
|
70 |
}
|