Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
/**
18
 * Steps definitions related to mod_quiz.
19
 *
20
 * @package   mod_wiki
21
 * @category  test
22
 * @copyright 2023 Catalyst IT Europe Ltd.
23
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
27
 
28
use Behat\Gherkin\Node\TableNode as TableNode;
29
use Behat\Mink\Exception\ExpectationException as ExpectationException;
30
 
31
/**
32
 * Steps definitions related to mod_wiki.
33
 *
34
 * @copyright 2023 Catalyst IT Europe Ltd.
35
 * @author Mark Johnson <mark.johnson@catalyst-eu.net>
36
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class behat_mod_wiki extends behat_base {
39
 
40
    /**
41
     * Add the specified pages to the specified wiki
42
     *
43
     * The first row should be column names:
44
     * | wiki | user | group | title | content |
45
     *
46
     *
47
     * wiki        idnumber of the wiki course module
48
     * user        username of the user who is creating the page
49
     * group       (optional) idnumber of the group the page belongs to
50
     * title       (optional) the title text of the page
51
     * content     (optional) the content of the page
52
     *
53
     * @param TableNode $data The pages to add
54
     *
55
     * @Given /^the following wiki pages exist:$/
56
     */
57
    public function the_following_wiki_pages_exist(TableNode $data): void {
58
        global $DB;
59
 
60
        $generator = behat_util::get_data_generator()->get_plugin_generator('mod_wiki');
61
        // Add the pages.
62
        foreach ($data->getHash() as $pagedata) {
63
            if (!array_key_exists('wiki', $pagedata)) {
64
                throw new ExpectationException('When adding pages to a wiki, ' .
65
                        'the wiki column is required containing the wiki idnumber.', $this->getSession());
66
            }
67
 
68
            $wikicm = $this->get_course_module_for_identifier($pagedata['wiki']);
69
            $wiki = $DB->get_record('wiki', ['id' => $wikicm->instance]);
70
            $wiki->cmid = $wikicm->cmid;
71
            $pagedata['wikiid'] = $wiki->id;
72
            unset($pagedata['wiki']);
73
 
74
            if (array_key_exists('group', $pagedata)) {
75
                $pagedata['group'] = $DB->get_field('groups', 'id', ['idnumber' => $pagedata['group']], MUST_EXIST);
76
            }
77
 
78
            if (array_key_exists('user', $pagedata)) {
79
                $pagedata['userid'] = $DB->get_field('user', 'id', ['username' => $pagedata['user']], MUST_EXIST);
80
                unset($pagedata['user']);
81
            }
82
 
83
            $generator->create_page($wiki, $pagedata);
84
        }
85
    }
86
}