/admin/tool/behat/renderer.php

https://bitbucket.org/kudutest1/moodlegit · PHP · 116 lines · 56 code · 18 blank · 42 comment · 3 complexity · 8759e4db6aca676a589ebdaade221fcf MD5 · raw file

  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. * Behat tool renderer
  18. *
  19. * @package tool_behat
  20. * @copyright 2012 David Monllaó
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. defined('MOODLE_INTERNAL') || die();
  24. global $CFG;
  25. require_once($CFG->libdir . '/behat/classes/behat_command.php');
  26. /**
  27. * Renderer for behat tool web features
  28. *
  29. * @package tool_behat
  30. * @copyright 2012 David Monllaó
  31. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32. */
  33. class tool_behat_renderer extends plugin_renderer_base {
  34. /**
  35. * Renders the list of available steps according to the submitted filters.
  36. *
  37. * @param mixed $stepsdefinitions Available steps array.
  38. * @param moodleform $form
  39. * @return string HTML code
  40. */
  41. public function render_stepsdefinitions($stepsdefinitions, $form) {
  42. $title = get_string('pluginname', 'tool_behat');
  43. // Header.
  44. $html = $this->output->header();
  45. $html .= $this->output->heading($title);
  46. // Info.
  47. $installurl = behat_command::DOCS_URL . '#Installation';
  48. $installlink = html_writer::tag('a', $installurl, array('href' => $installurl, 'target' => '_blank'));
  49. $writetestsurl = behat_command::DOCS_URL . '#Writting_features';
  50. $writetestslink = html_writer::tag('a', $writetestsurl, array('href' => $writetestsurl, 'target' => '_blank'));
  51. $writestepsurl = behat_command::DOCS_URL . '#Adding_steps_definitions';
  52. $writestepslink = html_writer::tag('a', $writestepsurl, array('href' => $writestepsurl, 'target' => '_blank'));
  53. $infos = array(
  54. get_string('installinfo', 'tool_behat', $installlink),
  55. get_string('newtestsinfo', 'tool_behat', $writetestslink),
  56. get_string('newstepsinfo', 'tool_behat', $writestepslink)
  57. );
  58. // List of steps
  59. $html .= $this->output->box_start();
  60. $html .= html_writer::tag('h1', 'Info');
  61. $html .= html_writer::empty_tag('div');
  62. $html .= html_writer::empty_tag('ul');
  63. $html .= html_writer::empty_tag('li');
  64. $html .= implode(html_writer::end_tag('li') . html_writer::empty_tag('li'), $infos);
  65. $html .= html_writer::end_tag('li');
  66. $html .= html_writer::end_tag('ul');
  67. $html .= html_writer::end_tag('div');
  68. $html .= $this->output->box_end();
  69. // Form.
  70. ob_start();
  71. $form->display();
  72. $html .= ob_get_contents();
  73. ob_end_clean();
  74. if (empty($stepsdefinitions)) {
  75. $stepsdefinitions = get_string('nostepsdefinitions', 'tool_behat');
  76. } else {
  77. $stepsdefinitions = implode('', $stepsdefinitions);
  78. // Replace text selector type arguments with a user-friendly select.
  79. $stepsdefinitions = preg_replace_callback('/(TEXT_SELECTOR\d?_STRING)/',
  80. function ($matches) {
  81. return html_writer::select(behat_command::$allowedtextselectors, uniqid());
  82. },
  83. $stepsdefinitions
  84. );
  85. // Replace selector type arguments with a user-friendly select.
  86. $stepsdefinitions = preg_replace_callback('/(SELECTOR\d?_STRING)/',
  87. function ($matches) {
  88. return html_writer::select(behat_command::$allowedselectors, uniqid());
  89. },
  90. $stepsdefinitions
  91. );
  92. }
  93. // Steps definitions.
  94. $html .= html_writer::tag('div', $stepsdefinitions, array('class' => 'steps-definitions'));
  95. $html .= $this->output->footer();
  96. return $html;
  97. }
  98. }