1441 |
ariadna |
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 core_ai\aiactions\responses;
|
|
|
18 |
|
|
|
19 |
use core_ai\aiactions\responses\response_summarise_text;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Test response_generate_image_test action methods.
|
|
|
23 |
*
|
|
|
24 |
* @package core_ai
|
|
|
25 |
* @copyright 2024 Matt Porritt <matt.porritt@moodle.com>
|
|
|
26 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
27 |
* @covers \core_ai\aiactions\responses\response_summarise_text
|
|
|
28 |
*/
|
|
|
29 |
final class response_summarise_text_test extends \advanced_testcase {
|
|
|
30 |
/**
|
|
|
31 |
* Test get_basename.
|
|
|
32 |
*/
|
|
|
33 |
public function test_get_success(): void {
|
|
|
34 |
$actionresponse = new response_summarise_text(
|
|
|
35 |
success: true,
|
|
|
36 |
);
|
|
|
37 |
|
|
|
38 |
$this->assertTrue($actionresponse->get_success());
|
|
|
39 |
$this->assertEquals('summarise_text', $actionresponse->get_actionname());
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* Test constructor with error.
|
|
|
44 |
*/
|
|
|
45 |
public function test_construct_error(): void {
|
|
|
46 |
$this->expectException(\coding_exception::class);
|
|
|
47 |
$this->expectExceptionMessage('Error code and message must exist in an error response.');
|
|
|
48 |
new response_summarise_text(
|
|
|
49 |
success: false,
|
|
|
50 |
);
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* Test set_response_data.
|
|
|
55 |
*/
|
|
|
56 |
public function test_set_response_data(): void {
|
|
|
57 |
$this->resetAfterTest();
|
|
|
58 |
$body = [
|
|
|
59 |
'id' => 'chatcmpl-123',
|
|
|
60 |
'fingerprint' => 'fp_44709d6fcb',
|
|
|
61 |
'generatedcontent' => 'This is the generated content',
|
|
|
62 |
'finishreason' => 'stop',
|
|
|
63 |
'prompttokens' => 9,
|
|
|
64 |
'completiontokens' => 12,
|
|
|
65 |
];
|
|
|
66 |
$actionresponse = new response_summarise_text(
|
|
|
67 |
success: true,
|
|
|
68 |
);
|
|
|
69 |
$actionresponse->set_response_data($body);
|
|
|
70 |
|
|
|
71 |
$this->assertEquals($body['id'], $actionresponse->get_response_data()['id']);
|
|
|
72 |
$this->assertEquals($body['fingerprint'], $actionresponse->get_response_data()['fingerprint']);
|
|
|
73 |
$this->assertEquals($body['generatedcontent'], $actionresponse->get_response_data()['generatedcontent']);
|
|
|
74 |
$this->assertEquals($body['finishreason'], $actionresponse->get_response_data()['finishreason']);
|
|
|
75 |
$this->assertEquals($body['prompttokens'], $actionresponse->get_response_data()['prompttokens']);
|
|
|
76 |
$this->assertEquals($body['completiontokens'], $actionresponse->get_response_data()['completiontokens']);
|
|
|
77 |
}
|
|
|
78 |
}
|