2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Commenting system steps definitions.
20 * @package core_comment
22 * @copyright 2013 David MonllaĆ³
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
28 require_once(__DIR__
. '/../../../../lib/behat/behat_base.php');
30 use Behat\Mink\Exception\ElementNotFoundException
as ElementNotFoundException
,
31 Behat\Mink\Exception\ExpectationException
as ExpectationException
;
34 * Steps definitions to deal with the commenting system
36 * @package core_comment
38 * @copyright 2013 David MonllaĆ³
39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41 class behat_block_comments
extends behat_base
{
44 * Adds the specified option to the comments block of the current page.
46 * This method can be adapted in future to add other comments considering
47 * that there could be more than one comment textarea per page.
49 * Only 1 comments block instance is allowed per page, if this changes this
50 * steps definitions should be adapted.
52 * @Given /^I add "(?P<comment_text_string>(?:[^"]|\\")*)" comment to comments block$/
53 * @throws ElementNotFoundException
54 * @param string $comment
56 public function i_add_comment_to_comments_block($comment) {
58 // Getting the textarea and setting the provided value.
59 $exception = new ElementNotFoundException($this->getSession(), 'Comments block ');
61 // The whole DOM structure changes depending on JS enabled/disabled.
62 if ($this->running_javascript()) {
63 $commentstextarea = $this->find('css', '.comment-area textarea', $exception);
64 $commentstextarea->setValue($comment);
66 $this->find_link('Save comment')->click();
68 // Wait for the AJAX request.
69 $this->getSession()->wait(4 * 1000, false);
73 $commentstextarea = $this->find('css', '.block_comments form textarea', $exception);
74 $commentstextarea->setValue($comment);
76 // Comments submit button
77 $submit = $this->find('css', '.block_comments form input[type=submit]');
83 * Deletes the specified comment from the current page's comments block.
85 * @Given /^I delete "(?P<comment_text_string>(?:[^"]|\\")*)" comment from comments block$/
86 * @throws ElementNotFoundException
87 * @throws ExpectationException
88 * @param string $comment
90 public function i_delete_comment_from_comments_block($comment) {
92 $exception = new ElementNotFoundException($this->getSession(), '"' . $comment . '" comment ');
94 $commentxpath = "//div[contains(concat(' ', @class, ' '), ' block_comments ')]" .
95 "/descendant::div[@class='comment-message'][contains(., '" . $comment . "')]";
96 $commentnode = $this->find('xpath', $commentxpath, $exception);
98 // Click on delete icon.
99 $deleteexception = new ExpectationException('"' . $comment . '" comment can not be deleted', $this->getSession());
100 $deleteicon = $this->find('css', '.comment-delete a img', $deleteexception, $commentnode);
101 $deleteicon->click();
104 $confirmnode = $this->find('xpath', "//div[@class='comment-delete-confirm']/descendant::a[contains(., 'Yes')]");
105 $confirmnode->click();
107 // Wait for the AJAX request.
108 $this->getSession()->wait(4 * 1000, false);