Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
   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  // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
  18  require_once (__DIR__ . '/../../../../../lib/behat/behat_base.php');
  19  require_once (__DIR__ . '/../../../../tests/behat/behat_question_base.php');
  20  
  21  use Behat\Mink\Exception\ExpectationException as ExpectationException,
  22      Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
  23  
  24  /**
  25   * Steps definitions to deal with the usage in question.
  26   *
  27   * @package    qbank_usage
  28   * @copyright  2021 Catalyst IT Australia Pty Ltd
  29   * @author     Safat Shahin <safatshahin@catalyst-au.net>
  30   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31   */
  32  class behat_qbank_usage extends behat_question_base {
  33  
  34      /**
  35       * Looks for a table, then looks for a row that contains the given text.
  36       * Once it finds the right row, it clicks a link in that row.
  37       *
  38       * @When I click :arg1 on the usage column
  39       * @param string $linkname
  40       */
  41      public function i_click_on_the_usage_column($linkname) {
  42          $exception = new ElementNotFoundException($this->getSession(),
  43              'Cannot find any row on the page containing the text ' . $linkname);
  44          $row = $this->find('css', sprintf('table tbody tr td.questionusage a:contains("%s")', $linkname), $exception);
  45          $row->click();
  46      }
  47  
  48      /**
  49       * Looks for the appropriate usage count in the column.
  50       *
  51       * @Then I should see :arg1 on the usage column
  52       * @param string $linkdata
  53       */
  54      public function i_should_see_on_the_usage_column($linkdata) {
  55          $exception = new ElementNotFoundException($this->getSession(),
  56              'Cannot find any row with the usage count of ' . $linkdata . ' on the column named Usage');
  57          $this->find('css', sprintf('table tbody tr td.questionusage a:contains("%s")', $linkdata), $exception);
  58      }
  59  }