Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   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   * Behat steps definitions for block social activities
  19   *
  20   * @package    block_social_activities
  21   * @category   test
  22   * @copyright  2016 Marina Glancy
  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  require_once (__DIR__ . '/../../../../lib/behat/behat_base.php');
  29  
  30  use Behat\Mink\Exception\ExpectationException as ExpectationException,
  31      Behat\Mink\Exception\DriverException as DriverException,
  32      Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
  33  
  34  /**
  35   * Behat steps definitions for block social activities
  36   *
  37   * @package    block_social_activities
  38   * @category   test
  39   * @copyright  2016 Marina Glancy
  40   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  41   */
  42  class behat_block_social_activities extends behat_base {
  43  
  44      /**
  45       * Returns the DOM node of the activity in the social activities block
  46       *
  47       * @throws ElementNotFoundException Thrown by behat_base::find
  48       * @param string $activityname The activity name
  49       * @return NodeElement
  50       */
  51      protected function get_social_block_activity_node($activityname) {
  52          $activityname = behat_context_helper::escape($activityname);
  53          $xpath = "//*[contains(concat(' ',normalize-space(@class),' '),' block_social_activities ')]//li[contains(., $activityname)]";
  54  
  55          return $this->find('xpath', $xpath);
  56      }
  57  
  58      /**
  59       * Checks that the specified activity in the social activities block should have the specified editing icon.
  60       *
  61       * This includes items in the action menu for the item (does not require it to be open)
  62       *
  63       * You should be in the course page with editing mode turned on.
  64       *
  65       * @Then /^"(?P<activity_name_string>(?:[^"]|\\")*)" activity in social activities block should have "(?P<icon_name_string>(?:[^"]|\\")*)" editing icon$/
  66       * @param string $activityname
  67       * @param string $iconname
  68       */
  69      public function activity_in_social_activities_block_should_have_editing_icon($activityname, $iconname) {
  70          $activitynode = $this->get_social_block_activity_node($activityname);
  71  
  72          $notfoundexception = new ExpectationException('"' . $activityname . '" doesn\'t have a "' .
  73              $iconname . '" editing icon', $this->getSession());
  74          $this->find('named_partial', array('link', $iconname), $notfoundexception, $activitynode);
  75      }
  76  
  77      /**
  78       * Checks that the specified activity in the social activities block should not have the specified editing icon.
  79       *
  80       * This includes items in the action menu for the item (does not require it to be open)
  81       *
  82       * You should be in the course page with editing mode turned on.
  83       *
  84       * @Then /^"(?P<activity_name_string>(?:[^"]|\\")*)" activity in social activities block should not have "(?P<icon_name_string>(?:[^"]|\\")*)" editing icon$/
  85       * @param string $activityname
  86       * @param string $iconname
  87       */
  88      public function activity_in_social_activities_block_should_not_have_editing_icon($activityname, $iconname) {
  89          $activitynode = $this->get_social_block_activity_node($activityname);
  90  
  91          try {
  92              $this->find('named_partial', array('link', $iconname), false, $activitynode);
  93              throw new ExpectationException('"' . $activityname . '" has a "' . $iconname .
  94                  '" editing icon when it should not', $this->getSession());
  95          } catch (ElementNotFoundException $e) {
  96              // This is good, the menu item should not be there.
  97          }
  98      }
  99  
 100      /**
 101       * Clicks on the specified element of the activity. You should be in the course page with editing mode turned on.
 102       *
 103       * @Given /^I click on "(?P<element_string>(?:[^"]|\\")*)" "(?P<selector_string>(?:[^"]|\\")*)" in the "(?P<activity_name_string>(?:[^"]|\\")*)" activity in social activities block$/
 104       * @param string $element
 105       * @param string $selectortype
 106       * @param string $activityname
 107       */
 108      public function i_click_on_in_the_activity_in_social_activities_block($element, $selectortype, $activityname) {
 109          $element = $this->get_social_block_activity_element($element, $selectortype, $activityname);
 110          $element->click();
 111      }
 112  
 113      /**
 114       * Finds the element containing a specific activity in the social activity block.
 115       *
 116       * @throws ElementNotFoundException
 117       * @param string $element
 118       * @param string $selectortype
 119       * @param string $activityname
 120       * @return NodeElement
 121       */
 122      protected function get_social_block_activity_element($element, $selectortype, $activityname) {
 123          $activitynode = $this->get_social_block_activity_node($activityname);
 124  
 125          $exception = new ElementNotFoundException($this->getSession(), "'{$element}' '{$selectortype}' in '$activityname}'");
 126          return $this->find($selectortype, $element, $exception, $activitynode);
 127      }
 128  
 129      /**
 130       * Checks that the specified activity is hidden in the social activities block.
 131       *
 132       * @Then /^"(?P<activity_name_string>(?:[^"]|\\")*)" activity in social activities block should be hidden$/
 133       * @param string $activityname
 134       */
 135      public function activity_in_social_activities_block_should_be_hidden($activityname) {
 136          $this->get_social_block_activity_element("a.dimmed", "css_element", $activityname);
 137      }
 138  
 139      /**
 140       * Checks that the specified activity is hidden in the social activities block.
 141       *
 142       * @Then /^"(?P<activity_name_string>(?:[^"]|\\")*)" activity in social activities block should be available but hidden from course page$/
 143       * @param string $activityname
 144       */
 145      public function activity_in_social_activities_block_should_be_available_but_hidden_from_course_page($activityname) {
 146          $this->get_social_block_activity_element("a.stealth", "css_element", $activityname);
 147      }
 148  
 149      /**
 150       * Opens an activity actions menu in the social activities block if it is not already opened.
 151       *
 152       * @Given /^I open "(?P<activity_name_string>(?:[^"]|\\")*)" actions menu in social activities block$/
 153       * @throws DriverException The step is not available when Javascript is disabled
 154       * @param string $activityname
 155       */
 156      public function i_open_actions_menu_in_social_activities_block($activityname) {
 157          $activityname = behat_context_helper::escape($activityname);
 158          $xpath = "//*[contains(concat(' ',normalize-space(@class),' '),' block_social_activities ')]//li[contains(., $activityname)]";
 159          $this->execute('behat_action_menu::i_open_the_action_menu_in', [$xpath, 'xpath_element']);
 160      }
 161  
 162      /**
 163       * Return the list of partial named selectors.
 164       *
 165       * @return array
 166       */
 167      public static function get_partial_named_selectors(): array {
 168          return [
 169              new behat_component_named_selector('Activity', [
 170                  "//*[contains(concat(' ',normalize-space(@class),' '),' block_social_activities ')]//li[contains(., %locator%)]",
 171              ]),
 172          ];
 173      }
 174  }