Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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\external;
18
 
19
/**
20
 * Test provider order external api calls.
21
 *
22
 * @package    core_ai
23
 * @copyright  Meirza <meirza.arson@moodle.com>
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 * @covers     \core_ai\external\set_provider_order
26
 */
27
final class provider_order_test extends \advanced_testcase {
28
    /**
29
     * Test set provider order.
30
     */
31
    public function test_set_provider_order(): void {
32
        $this->resetAfterTest();
33
 
34
        // Create the provider instances.
35
        $manager = \core\di::get(\core_ai\manager::class);
36
        $openai = $manager->create_provider_instance(
37
            classname: '\aiprovider_openai\provider',
38
            name: 'openai instance',
39
            enabled: true, // Must be set to true to activate the sort function.
40
            config: ['data' => 'openai configurations'],
41
        );
42
        $azureai = $manager->create_provider_instance(
43
            classname: '\aiprovider_azureai\provider',
44
            name: 'azureai instance',
45
            enabled: true, // Must be set to true to activate the sort function.
46
            config: ['data' => 'azureai configurations'],
47
        );
48
 
49
        $this->setAdminUser();
50
 
51
        // Move the OpenAI instance to the bottom, and AzureAI will automatically move to the top.
52
        set_provider_order::execute($openai->id, \core\plugininfo\aiprovider::MOVE_DOWN);
53
        $providers = array_keys($manager->get_sorted_providers());
54
        $this->assertEquals($providers[0], $azureai->id);
55
        $this->assertEquals($providers[1], $openai->id);
56
 
57
        // Move the OpenAI instance to the top, and AzureAI will automatically move to the bottom.
58
        set_provider_order::execute($openai->id, \core\plugininfo\aiprovider::MOVE_UP);
59
        $providers = array_keys($manager->get_sorted_providers());
60
        $this->assertEquals($providers[0], $openai->id);
61
        $this->assertEquals($providers[1], $azureai->id);
62
    }
63
}