[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/completion/tests/behat/ -> behat_completion.php (source)

   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   * Completion steps definitions.
  19   *
  20   * @package    core_completion
  21   * @category   test
  22   * @copyright  2013 David Monllaó
  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\ElementNotFoundException as ElementNotFoundException;
  31  
  32  /**
  33   * Steps definitions to deal with course and activities completion.
  34   *
  35   * @package    core_completion
  36   * @category   test
  37   * @copyright  2013 David Monllaó
  38   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class behat_completion extends behat_base {
  41  
  42      /**
  43       * Checks that the specified user has completed the specified activity of the current course.
  44       *
  45       * @Then /^"(?P<user_fullname_string>(?:[^"]|\\")*)" user has completed "(?P<activity_name_string>(?:[^"]|\\")*)" activity$/
  46       * @param string $userfullname
  47       * @param string $activityname
  48       */
  49      public function user_has_completed_activity($userfullname, $activityname) {
  50  
  51          // Will throw an exception if the element can not be hovered.
  52          $titleliteral = behat_context_helper::escape($userfullname . ", " . $activityname . ": Completed");
  53          $xpath = "//table[@id='completion-progress']" .
  54              "/descendant::img[contains(@title, $titleliteral)]";
  55  
  56          $this->execute("behat_completion::go_to_the_current_course_activity_completion_report");
  57          $this->execute("behat_general::should_exist",
  58              array($this->escape($xpath), "xpath_element")
  59          );
  60      }
  61  
  62      /**
  63       * Checks that the specified user has not completed the specified activity of the current course.
  64       *
  65       * @Then /^"(?P<user_fullname_string>(?:[^"]|\\")*)" user has not completed "(?P<activity_name_string>(?:[^"]|\\")*)" activity$/
  66       * @param string $userfullname
  67       * @param string $activityname
  68       */
  69      public function user_has_not_completed_activity($userfullname, $activityname) {
  70  
  71          // Will throw an exception if the element can not be hovered.
  72          $titleliteral = behat_context_helper::escape($userfullname . ", " . $activityname . ": Not completed");
  73          $xpath = "//table[@id='completion-progress']" .
  74              "/descendant::img[contains(@title, $titleliteral)]";
  75  
  76          $this->execute("behat_completion::go_to_the_current_course_activity_completion_report");
  77          $this->execute("behat_general::should_exist", array($this->escape($xpath), "xpath_element"));
  78      }
  79  
  80      /**
  81       * Goes to the current course activity completion report.
  82       *
  83       * @Given /^I go to the current course activity completion report$/
  84       */
  85      public function go_to_the_current_course_activity_completion_report() {
  86          $completionnode = get_string('pluginname', 'report_progress');
  87          $reportsnode = get_string('courseadministration') . ' > ' . get_string('reports');
  88  
  89          $this->execute("behat_navigation::i_navigate_to_node_in", array($completionnode, $reportsnode));
  90      }
  91  
  92      /**
  93       * Toggles completion tracking for course being in the course page.
  94       *
  95       * @When /^completion tracking is "(?P<completion_status_string>Enabled|Disabled)" in current course$/
  96       * @param string $completionstatus The status, enabled or disabled.
  97       */
  98      public function completion_is_toggled_in_course($completionstatus) {
  99  
 100          $toggle = strtolower($completionstatus) == 'enabled' ? get_string('yes') : get_string('no');
 101  
 102          // Go to course editing.
 103          $this->execute("behat_general::click_link", get_string('editsettings'));
 104  
 105          // Expand all the form fields.
 106          $this->execute("behat_forms::i_expand_all_fieldsets");
 107  
 108          // Enable completion.
 109          $this->execute("behat_forms::i_set_the_field_to",
 110              array(get_string('enablecompletion', 'completion'), $toggle));
 111  
 112          // Save course settings.
 113          $this->execute("behat_forms::press_button", get_string('savechangesanddisplay'));
 114      }
 115  
 116      /**
 117       * Checks if the activity with specified name is maked as complete.
 118       *
 119       * @Given /^the "(?P<activityname_string>(?:[^"]|\\")*)" "(?P<activitytype_string>(?:[^"]|\\")*)" activity with "(manual|auto)" completion should be marked as complete$/
 120       */
 121      public function activity_marked_as_complete($activityname, $activitytype, $completiontype) {
 122          if ($completiontype == "manual") {
 123              $imgalttext = get_string("completion-alt-manual-y", 'core_completion', $activityname);
 124          } else {
 125              $imgalttext = get_string("completion-alt-auto-y", 'core_completion', $activityname);
 126          }
 127          $csselementforactivitytype = "li.modtype_".strtolower($activitytype);
 128  
 129          $xpathtocheck = "//img[contains(@alt, '$imgalttext')]";
 130          $this->execute("behat_general::should_exist_in_the",
 131              array($xpathtocheck, "xpath_element", $csselementforactivitytype, "css_element")
 132          );
 133  
 134      }
 135  
 136      /**
 137       * Checks if the activity with specified name is maked as complete.
 138       *
 139       * @Given /^the "(?P<activityname_string>(?:[^"]|\\")*)" "(?P<activitytype_string>(?:[^"]|\\")*)" activity with "(manual|auto)" completion should be marked as not complete$/
 140       */
 141      public function activity_marked_as_not_complete($activityname, $activitytype, $completiontype) {
 142          if ($completiontype == "manual") {
 143              $imgalttext = get_string("completion-alt-manual-n", 'core_completion', $activityname);
 144          } else {
 145              $imgalttext = get_string("completion-alt-auto-n", 'core_completion', $activityname);
 146          }
 147          $csselementforactivitytype = "li.modtype_".strtolower($activitytype);
 148  
 149          $xpathtocheck = "//img[contains(@alt, '$imgalttext')]";
 150          $this->execute("behat_general::should_exist_in_the",
 151              array($xpathtocheck, "xpath_element", $csselementforactivitytype, "css_element")
 152          );
 153  
 154      }
 155  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1