[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/forum/tests/behat/ -> behat_mod_forum.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   * Steps definitions related with the forum activity.
  19   *
  20   * @package    mod_forum
  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\Behat\Context\Step\Given as Given,
  31      Behat\Gherkin\Node\TableNode as TableNode;
  32  /**
  33   * Forum-related steps definitions.
  34   *
  35   * @package    mod_forum
  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_mod_forum extends behat_base {
  41  
  42      /**
  43       * Adds a topic to the forum specified by it's name. Useful for the News forum and blog-style forums.
  44       *
  45       * @Given /^I add a new topic to "(?P<forum_name_string>(?:[^"]|\\")*)" forum with:$/
  46       * @param string $forumname
  47       * @param TableNode $table
  48       */
  49      public function i_add_a_new_topic_to_forum_with($forumname, TableNode $table) {
  50          return $this->add_new_discussion($forumname, $table, get_string('addanewtopic', 'forum'));
  51      }
  52  
  53      /**
  54       * Adds a discussion to the forum specified by it's name with the provided table data (usually Subject and Message). The step begins from the forum's course page.
  55       *
  56       * @Given /^I add a new discussion to "(?P<forum_name_string>(?:[^"]|\\")*)" forum with:$/
  57       * @param string $forumname
  58       * @param TableNode $table
  59       */
  60      public function i_add_a_forum_discussion_to_forum_with($forumname, TableNode $table) {
  61          return $this->add_new_discussion($forumname, $table, get_string('addanewdiscussion', 'forum'));
  62      }
  63  
  64      /**
  65       * Adds a reply to the specified post of the specified forum. The step begins from the forum's page or from the forum's course page.
  66       *
  67       * @Given /^I reply "(?P<post_subject_string>(?:[^"]|\\")*)" post from "(?P<forum_name_string>(?:[^"]|\\")*)" forum with:$/
  68       * @param string $postname The subject of the post
  69       * @param string $forumname The forum name
  70       * @param TableNode $table
  71       */
  72      public function i_reply_post_from_forum_with($postsubject, $forumname, TableNode $table) {
  73  
  74          return array(
  75              new Given('I follow "' . $this->escape($forumname) . '"'),
  76              new Given('I follow "' . $this->escape($postsubject) . '"'),
  77              new Given('I follow "' . get_string('reply', 'forum') . '"'),
  78              new Given('I set the following fields to these values:', $table),
  79              new Given('I press "' . get_string('posttoforum', 'forum') . '"'),
  80              new Given('I wait to be redirected')
  81          );
  82  
  83      }
  84  
  85      /**
  86       * Returns the steps list to add a new discussion to a forum.
  87       *
  88       * Abstracts add a new topic and add a new discussion, as depending
  89       * on the forum type the button string changes.
  90       *
  91       * @param string $forumname
  92       * @param TableNode $table
  93       * @param string $buttonstr
  94       * @return Given[]
  95       */
  96      protected function add_new_discussion($forumname, TableNode $table, $buttonstr) {
  97  
  98          // Escaping $forumname as it has been stripped automatically by the transformer.
  99          return array(
 100              new Given('I follow "' . $this->escape($forumname) . '"'),
 101              new Given('I press "' . $buttonstr . '"'),
 102              new Given('I set the following fields to these values:', $table),
 103              new Given('I press "' . get_string('posttoforum', 'forum') . '"'),
 104              new Given('I wait to be redirected')
 105          );
 106  
 107      }
 108  
 109  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1