Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
 * Commenting system steps definitions for question.
19
 *
20
 * @package    qbank_comment
21
 * @copyright  2021 Catalyst IT Australia Pty Ltd
22
 * @author     Safat Shahin <safatshahin@catalyst-au.net>
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
require_once(__DIR__ . '/../../../../../lib/behat/behat_base.php');
28
require_once(__DIR__ . '/../../../../tests/behat/behat_question_base.php');
29
 
30
use Behat\Mink\Exception\ExpectationException as ExpectationException,
31
    Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
32
 
33
/**
34
 * Steps definitions to deal with the commenting system in question.
35
 *
36
 * @package    qbank_comment
37
 * @copyright  2021 Catalyst IT Australia Pty Ltd
38
 * @author     Safat Shahin <safatshahin@catalyst-au.net>
39
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40
 */
41
class behat_qbank_comment extends behat_question_base {
42
 
43
    /**
44
     * Adds the specified option to the question comments of the current modal.
45
     *
46
     * @Then I add :arg1 comment to question
47
     * @param string $comment
48
     */
49
    public function i_add_comment_to_question($comment) {
50
 
51
        // Getting the textarea and setting the provided value.
52
        $exception = new ElementNotFoundException($this->getSession(), 'Question ');
53
 
54
        if ($this->running_javascript()) {
55
            $commentstextarea = $this->find('css',
56
                                        '.modal-dialog .question-comment-view .comment-area textarea', $exception);
57
            $commentstextarea->setValue($comment);
58
 
59
            // We delay 1 second which is all we need.
60
            $this->getSession()->wait(1000);
61
 
62
        } else {
63
            throw new ExpectationException('JavaScript not running', $this->getSession());
64
        }
65
    }
66
 
67
    /**
68
     * Adds the specified option to the question comments of the question preview.
69
     *
70
     * @Then I add :arg1 comment to question preview
71
     * @param string $comment
72
     */
73
    public function i_add_comment_to_question_preview($comment) {
74
 
75
        // Getting the textarea and setting the provided value.
76
        $exception = new ElementNotFoundException($this->getSession(), 'Question ');
77
 
78
        if ($this->running_javascript()) {
79
            $commentstextarea = $this->find('css',
80
                    '.comment-area textarea', $exception);
81
            $commentstextarea->setValue($comment);
82
 
83
            // We delay 1 second which is all we need.
84
            $this->getSession()->wait(1000);
85
 
86
        } else {
87
            throw new ExpectationException('JavaScript not running', $this->getSession());
88
        }
89
    }
90
 
91
    /**
92
     * Deletes the specified comment from the current question comment preview.
93
     *
94
     * @Then I delete :arg comment from question preview
95
     * @param string $comment
96
     */
97
    public function i_delete_comment_from_question_preview($comment) {
98
 
99
        $exception = new ElementNotFoundException($this->getSession(), '"' . $comment . '" comment ');
100
 
101
        // Using xpath liternal to avoid possible problems with comments containing quotes.
102
        $commentliteral = behat_context_helper::escape($comment);
103
 
104
        $commentxpath = "//*[contains(concat(' ', normalize-space(@class), ' '), ' comment-ctrl ')]" .
105
            "/descendant::div[@class='comment-message'][contains(., $commentliteral)]";
106
 
107
        // Click on delete icon.
108
        $this->execute('behat_general::i_click_on_in_the',
109
            ["Delete comment posted by", "icon", $this->escape($commentxpath), "xpath_element"]
110
        );
111
 
112
        // Wait for the animation to finish, in theory is just 1 sec, adding 4 just in case.
113
        $this->getSession()->wait(4 * 1000);
114
    }
115
 
116
    /**
117
     * Deletes the specified comment from the current question comment modal.
118
     *
119
     * @Then I delete :arg comment from question
120
     * @param string $comment
121
     */
122
    public function i_delete_comment_from_question($comment) {
123
 
124
        $exception = new ElementNotFoundException($this->getSession(), '"' . $comment . '" comment ');
125
 
126
        // Using xpath liternal to avoid possible problems with comments containing quotes.
127
        $commentliteral = behat_context_helper::escape($comment);
128
 
129
        $commentxpath = "//*[contains(concat(' ', normalize-space(@class), ' '), ' question-comment-view ')]" .
130
                "/descendant::div[@class='comment-message'][contains(., $commentliteral)]";
131
 
132
        // Click on delete icon.
133
        $this->execute('behat_general::i_click_on_in_the',
134
                ["Delete comment posted by", "icon", $this->escape($commentxpath), "xpath_element"]
135
        );
136
 
137
        // Wait for the animation to finish, in theory is just 1 sec, adding 4 just in case.
138
        $this->getSession()->wait(4 * 1000);
139
    }
140
 
1441 ariadna 141
    /**
142
     * Define named selectors for the comments column.
143
     *
144
     * Supported selectors are:
145
     * - "qbank_comment > Comment count link" a comment count displayed as a link.
146
     * - "qbank_comment > Comment count text" a comment count displayed as un-linked text.
147
     *
148
     * @return behat_component_named_selector[]
149
     */
150
    public static function get_exact_named_selectors(): array {
151
        $commentcountxpath = "//table/tbody/tr/td[contains(@class, 'commentcount')]/%s[text() = %%locator%%]";
152
        return [
153
            new behat_component_named_selector(
154
                'Comment count link',
155
                [sprintf($commentcountxpath, 'a')]
156
            ),
157
            new behat_component_named_selector(
158
                'Comment count text',
159
                [sprintf($commentcountxpath, 'span')]
160
            ),
161
        ];
162
    }
1 efrain 163
}