Beispiel #1
0
 /**
  * Renders the list of available steps according to the submitted filters.
  *
  * @param mixed $stepsdefinitions Available steps array.
  * @param moodleform $form
  * @return string HTML code
  */
 public function render_stepsdefinitions($stepsdefinitions, $form)
 {
     $title = get_string('pluginname', 'tool_behat');
     // Header.
     $html = $this->output->header();
     $html .= $this->output->heading($title);
     // Info.
     $installurl = behat_command::DOCS_URL . '#Installation';
     $installlink = html_writer::tag('a', $installurl, array('href' => $installurl, 'target' => '_blank'));
     $writetestsurl = behat_command::DOCS_URL . '#Writting_features';
     $writetestslink = html_writer::tag('a', $writetestsurl, array('href' => $writetestsurl, 'target' => '_blank'));
     $writestepsurl = behat_command::DOCS_URL . '#Adding_steps_definitions';
     $writestepslink = html_writer::tag('a', $writestepsurl, array('href' => $writestepsurl, 'target' => '_blank'));
     $infos = array(get_string('installinfo', 'tool_behat', $installlink), get_string('newtestsinfo', 'tool_behat', $writetestslink), get_string('newstepsinfo', 'tool_behat', $writestepslink));
     // List of steps.
     $html .= $this->output->box_start();
     $html .= html_writer::tag('h1', get_string('infoheading', 'tool_behat'));
     $html .= html_writer::tag('div', get_string('aim', 'tool_behat'));
     $html .= html_writer::start_tag('div');
     $html .= html_writer::start_tag('ul');
     $html .= html_writer::start_tag('li');
     $html .= implode(html_writer::end_tag('li') . html_writer::start_tag('li'), $infos);
     $html .= html_writer::end_tag('li');
     $html .= html_writer::end_tag('ul');
     $html .= html_writer::end_tag('div');
     $html .= $this->output->box_end();
     // Form.
     ob_start();
     $form->display();
     $html .= ob_get_contents();
     ob_end_clean();
     if (empty($stepsdefinitions)) {
         $stepsdefinitions = get_string('nostepsdefinitions', 'tool_behat');
     } else {
         $stepsdefinitions = implode('', $stepsdefinitions);
         // Replace text selector type arguments with a user-friendly select.
         $stepsdefinitions = preg_replace_callback('/(TEXT_SELECTOR\\d?_STRING)/', function ($matches) {
             return html_writer::select(behat_selectors::get_allowed_text_selectors(), uniqid());
         }, $stepsdefinitions);
         // Replace selector type arguments with a user-friendly select.
         $stepsdefinitions = preg_replace_callback('/(SELECTOR\\d?_STRING)/', function ($matches) {
             return html_writer::select(behat_selectors::get_allowed_selectors(), uniqid());
         }, $stepsdefinitions);
         // Replace simple OR options.
         $regex = '#\\(\\?P<[^>]+>([^\\)|]+\\|[^\\)]+)\\)#';
         $stepsdefinitions = preg_replace_callback($regex, function ($matches) {
             return html_writer::select(explode('|', $matches[1]), uniqid());
         }, $stepsdefinitions);
     }
     // Steps definitions.
     $html .= html_writer::tag('div', $stepsdefinitions, array('class' => 'steps-definitions'));
     $html .= $this->output->footer();
     return $html;
 }
Beispiel #2
0
    /**
     * Renders the list of available steps according to the submitted filters.
     *
     * @param mixed $stepsdefinitions Available steps array.
     * @param moodleform $form
     * @return string HTML code
     */
    public function render_stepsdefinitions($stepsdefinitions, $form) {

        $html = $this->generic_info();

        // Form.
        ob_start();
        $form->display();
        $html .= ob_get_contents();
        ob_end_clean();

        if (empty($stepsdefinitions)) {
            $stepsdefinitions = get_string('nostepsdefinitions', 'tool_behat');
        } else {

            $stepsdefinitions = implode('', $stepsdefinitions);

            // Replace text selector type arguments with a user-friendly select.
            $stepsdefinitions = preg_replace_callback('/(TEXT_SELECTOR\d?_STRING)/',
                function ($matches) {
                    return html_writer::select(behat_selectors::get_allowed_text_selectors(), uniqid());
                },
                $stepsdefinitions
            );

            // Replace selector type arguments with a user-friendly select.
            $stepsdefinitions = preg_replace_callback('/(SELECTOR\d?_STRING)/',
                function ($matches) {
                    return html_writer::select(behat_selectors::get_allowed_selectors(), uniqid());
                },
                $stepsdefinitions
            );

            // Replace simple OR options.
            $regex = '#\(\?P<[^>]+>([^\)|]+\|[^\)]+)\)#';
            $stepsdefinitions = preg_replace_callback($regex,
                function($matches){
                    return html_writer::select(explode('|', $matches[1]), uniqid());
                },
                $stepsdefinitions
            );

        }

        // Steps definitions.
        $html .= html_writer::tag('div', $stepsdefinitions, array('class' => 'steps-definitions'));

        $html .= $this->output->footer();

        return $html;
    }
Beispiel #3
0
 /**
  * Renders the list of available steps according to the submitted filters.
  *
  * @param mixed $stepsdefinitions Available steps array.
  * @param moodleform $form
  * @return string HTML code
  */
 public function render_stepsdefinitions($stepsdefinitions, $form)
 {
     $html = $this->generic_info();
     // Form.
     ob_start();
     $form->display();
     $html .= ob_get_contents();
     ob_end_clean();
     if (empty($stepsdefinitions)) {
         $stepsdefinitions = get_string('nostepsdefinitions', 'tool_behat');
     } else {
         $stepsdefinitions = implode('', $stepsdefinitions);
         // Replace text selector type arguments with a user-friendly select.
         $stepsdefinitions = preg_replace_callback('/(TEXT_SELECTOR\\d?_STRING)/', function ($matches) {
             return html_writer::select(behat_selectors::get_allowed_text_selectors(), uniqid());
         }, $stepsdefinitions);
         // Replace selector type arguments with a user-friendly select.
         $stepsdefinitions = preg_replace_callback('/(SELECTOR\\d?_STRING)/', function ($matches) {
             return html_writer::select(behat_selectors::get_allowed_selectors(), uniqid());
         }, $stepsdefinitions);
         // Replace simple OR options.
         $regex = '#\\(\\?P<[^>]+>([^\\)|]+\\|[^\\)]+)\\)#';
         $stepsdefinitions = preg_replace_callback($regex, function ($matches) {
             return html_writer::select(explode('|', $matches[1]), uniqid());
         }, $stepsdefinitions);
         $stepsdefinitions = preg_replace_callback('/(FIELD_VALUE_STRING)/', function ($matches) {
             global $CFG;
             // Creating a link to a popup with the help.
             $url = new moodle_url('/help.php', array('component' => 'tool_behat', 'identifier' => 'fieldvalueargument', 'lang' => current_language()));
             // Note: this title is displayed only if JS is disabled,
             // otherwise the link will have the new ajax tooltip.
             $title = get_string('fieldvalueargument', 'tool_behat');
             $title = get_string('helpprefix2', '', trim($title, ". \t"));
             $attributes = array('href' => $url, 'title' => $title, 'aria-haspopup' => 'true', 'target' => '_blank');
             $output = html_writer::tag('a', 'FIELD_VALUE_STRING', $attributes);
             return html_writer::tag('span', $output, array('class' => 'helptooltip'));
         }, $stepsdefinitions);
     }
     // Steps definitions.
     $html .= html_writer::tag('div', $stepsdefinitions, array('class' => 'steps-definitions'));
     $html .= $this->output->footer();
     return $html;
 }
 /**
  * Transforms from step definition's argument style to Mink format.
  *
  * Mink has 3 different selectors css, xpath and named, where named
  * selectors includes link, button, field... to simplify and group multiple
  * steps in one we use the same interface, considering all link, buttons...
  * at the same level as css selectors and xpath; this method makes the
  * conversion from the arguments received by the steps to the selectors and locators
  * required to interact with Mink.
  *
  * @throws ExpectationException
  * @param string $selectortype It can be css, xpath or any of the named selectors.
  * @param string $element The locator (or string) we are looking for.
  * @return array Contains the selector and the locator expected by Mink.
  */
 protected function transform_selector($selectortype, $element)
 {
     // Here we don't know if an allowed text selector is being used.
     $selectors = behat_selectors::get_allowed_selectors();
     if (!isset($selectors[$selectortype])) {
         throw new ExpectationException('The "' . $selectortype . '" selector type does not exist', $this->getSession());
     }
     return behat_selectors::get_behat_selector($selectortype, $element, $this->getSession());
 }