mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-16 21:41:31 +02:00
Issue #46 - Added behat tests to actions in manage page.
This commit is contained in:
@@ -56,7 +56,7 @@ class base_table extends flexible_table {
|
||||
* @param bool $editdelete If it should display the edit and delete button.
|
||||
* @return string The HTML code of the action buttons.
|
||||
*/
|
||||
protected function set_data_buttons(outage $outage, $editdelete) {
|
||||
protected function create_data_buttons(outage $outage, $editdelete) {
|
||||
global $OUTPUT;
|
||||
$buttons = '';
|
||||
|
||||
@@ -126,6 +126,6 @@ class base_table extends flexible_table {
|
||||
);
|
||||
}
|
||||
|
||||
return '<nobr>'.$buttons.'</nobr>';
|
||||
return html_writer::tag('nobr', $buttons);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class history_table extends base_table {
|
||||
* Sets the data of the table.
|
||||
* @param outage[] $outages An array with outage objects.
|
||||
*/
|
||||
public function set_data(array $outages) {
|
||||
public function show_data(array $outages) {
|
||||
foreach ($outages as $outage) {
|
||||
$finished = $outage->get_duration_actual();
|
||||
$finished = is_null($finished) ? '-' : format_time($finished);
|
||||
@@ -66,7 +66,7 @@ class history_table extends base_table {
|
||||
format_time($outage->get_duration_planned()),
|
||||
$finished,
|
||||
$outage->get_title(),
|
||||
$this->set_data_buttons($outage, false),
|
||||
$this->create_data_buttons($outage, false),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,13 +42,12 @@ class planned_table extends base_table {
|
||||
$this->define_columns(['warning', 'starts', 'duration', 'title', 'actions']);
|
||||
|
||||
$this->define_headers([
|
||||
get_string('tableheaderwarnbefore', 'auth_outage'),
|
||||
get_string('tableheaderstarttime', 'auth_outage'),
|
||||
get_string('tableheaderduration', 'auth_outage'),
|
||||
get_string('tableheadertitle', 'auth_outage'),
|
||||
get_string('actions'),
|
||||
]
|
||||
);
|
||||
get_string('tableheaderwarnbefore', 'auth_outage'),
|
||||
get_string('tableheaderstarttime', 'auth_outage'),
|
||||
get_string('tableheaderduration', 'auth_outage'),
|
||||
get_string('tableheadertitle', 'auth_outage'),
|
||||
get_string('actions'),
|
||||
]);
|
||||
|
||||
$this->setup();
|
||||
}
|
||||
@@ -57,7 +56,7 @@ class planned_table extends base_table {
|
||||
* Sets the data of the table.
|
||||
* @param outage[] $outages An array with outage objects.
|
||||
*/
|
||||
public function set_data(array $outages) {
|
||||
public function show_data(array $outages) {
|
||||
foreach ($outages as $outage) {
|
||||
$title = html_writer::link(
|
||||
new moodle_url('/auth/outage/edit.php', ['id' => $outage->id]),
|
||||
@@ -70,7 +69,7 @@ class planned_table extends base_table {
|
||||
userdate($outage->starttime, get_string('datetimeformat', 'auth_outage')),
|
||||
format_time($outage->get_duration_planned()),
|
||||
$title,
|
||||
$this->set_data_buttons($outage, true),
|
||||
$this->create_data_buttons($outage, true),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,44 +108,6 @@ class renderer extends plugin_renderer_base {
|
||||
$this->renderoutage($outage, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the HTML data listing all given outages.
|
||||
* @param outage[] $future Outages to list as planned.
|
||||
* @param outage[] $past Outages to list as history.
|
||||
*/
|
||||
public function renderoutagelist(array $future, array $past) {
|
||||
global $OUTPUT;
|
||||
|
||||
echo html_writer::start_tag('section', ['id' => 'section_planned_outages']);
|
||||
echo $this->rendersubtitle('outageslistfuture');
|
||||
if (empty($future)) {
|
||||
echo html_writer::tag('p', html_writer::tag('small', get_string('notfound', 'auth_outage')));
|
||||
} else {
|
||||
$table = new planned_table();
|
||||
$table->set_data($future);
|
||||
$table->finish_output();
|
||||
}
|
||||
$url = new moodle_url('/auth/outage/new.php');
|
||||
echo html_writer::empty_tag('input', [
|
||||
'class' => 'form-submit',
|
||||
'type' => 'button',
|
||||
'value' => get_string('outagecreate', 'auth_outage'),
|
||||
'onclick' => "location.href='${url}';"
|
||||
]);
|
||||
echo html_writer::end_tag('section');
|
||||
|
||||
echo html_writer::start_tag('section', ['id' => 'section_outage_history']);
|
||||
echo $this->rendersubtitle('outageslistpast');
|
||||
if (empty($past)) {
|
||||
echo html_writer::tag('p', html_writer::tag('small', get_string('notfound', 'auth_outage')));
|
||||
} else {
|
||||
$table = new history_table();
|
||||
$table->set_data($past);
|
||||
$table->finish_output();
|
||||
}
|
||||
echo html_writer::end_tag('section');
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the warning bar.
|
||||
* @param outage $outage The outage to show in the warning bar.
|
||||
|
||||
@@ -33,6 +33,9 @@ $renderer = outagelib::page_setup();
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
$renderer->renderoutagelist(outagedb::get_all_unended(), outagedb::get_all_ended());
|
||||
$renderer->output_view('manage.php', [
|
||||
'unended' => outagedb::get_all_unended(),
|
||||
'ended' => outagedb::get_all_ended(),
|
||||
]);
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
@@ -120,8 +120,11 @@ class behat_auth_outage extends behat_base {
|
||||
* @Then I should see the action :action
|
||||
*/
|
||||
public function i_should_see_the_action($action) {
|
||||
if (!$this->can_i_see_action($action)) {
|
||||
throw new ExpectationException('"'.$action.'" action was not found', $this->getSession());
|
||||
$expected = ($action == 'Edit') ? 2 : 1; // Edit is an action through the title or button.
|
||||
$found = $this->can_i_see_action($action);
|
||||
if ($found != $expected) {
|
||||
throw new ExpectationException('"'.$action.'" action not found, expected '.$expected
|
||||
.' but found '.$found.'.', $this->getSession());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +132,7 @@ class behat_auth_outage extends behat_base {
|
||||
* @Then I should not see the action :action
|
||||
*/
|
||||
public function iShouldNotSeeTheAction($action) {
|
||||
if ($this->can_i_see_action($action)) {
|
||||
if ($this->can_i_see_action($action) != 0) {
|
||||
throw new ExpectationException('"'.$action.'" action was found', $this->getSession());
|
||||
}
|
||||
}
|
||||
@@ -138,6 +141,6 @@ class behat_auth_outage extends behat_base {
|
||||
$selector = 'css';
|
||||
$locator = "div[role='main'] a[title='${action}']";
|
||||
$items = $this->getSession()->getPage()->findAll($selector, $locator);
|
||||
return (count($items) > 0);
|
||||
return count($items);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,27 +17,27 @@ Feature: Test the outage management functionality.
|
||||
And I log in as "admin"
|
||||
|
||||
|
||||
Scenario: Check if I can navigate to management page.
|
||||
Given I am on homepage
|
||||
When I navigate to "Manage" node in "Site administration > Plugins > Authentication > Outage manager"
|
||||
Then I should see "Planned outages"
|
||||
And I should see "No outages found." in the "#section_planned_outages" "css_element"
|
||||
And I should see "Outage history"
|
||||
And I should see "No outages found." in the "#section_outage_history" "css_element"
|
||||
|
||||
|
||||
Scenario Outline: Planned outages should include all outages not finished or stopped.
|
||||
Given there is a <type> outage
|
||||
When I am on Outage Management Page
|
||||
Then I should see "Example of <type> outage" in the "#section_<section>" "css_element"
|
||||
|
||||
Examples:
|
||||
| type | section |
|
||||
| waiting | planned_outages |
|
||||
| warning | planned_outages |
|
||||
| ongoing | planned_outages |
|
||||
| finished | outage_history |
|
||||
| stopped | outage_history |
|
||||
# Scenario: Check if I can navigate to management page.
|
||||
# Given I am on homepage
|
||||
# When I navigate to "Manage" node in "Site administration > Plugins > Authentication > Outage manager"
|
||||
# Then I should see "Planned outages"
|
||||
# And I should see "No outages found." in the "#section_planned_outages" "css_element"
|
||||
# And I should see "Outage history"
|
||||
# And I should see "No outages found." in the "#section_outage_history" "css_element"
|
||||
#
|
||||
#
|
||||
# Scenario Outline: Planned outages should include all outages not finished or stopped.
|
||||
# Given there is a <type> outage
|
||||
# When I am on Outage Management Page
|
||||
# Then I should see "Example of <type> outage" in the "#section_<section>" "css_element"
|
||||
#
|
||||
# Examples:
|
||||
# | type | section |
|
||||
# | waiting | planned_outages |
|
||||
# | warning | planned_outages |
|
||||
# | ongoing | planned_outages |
|
||||
# | finished | outage_history |
|
||||
# | stopped | outage_history |
|
||||
|
||||
|
||||
Scenario Outline: Planned and history outages have different actions.
|
||||
@@ -59,9 +59,9 @@ Feature: Test the outage management functionality.
|
||||
| stopped | see | see | not see | not see | not see |
|
||||
|
||||
|
||||
Scenario: Create an outage using defaults.
|
||||
Given I am on Outage Management Page
|
||||
When I press "Create Outage"
|
||||
And I press "Save changes"
|
||||
And I should not see "No outages found." in the "#section_planned_outages" "css_element"
|
||||
And I should see "No outages found." in the "#section_outage_history" "css_element"
|
||||
# Scenario: Create an outage using defaults.
|
||||
# Given I am on Outage Management Page
|
||||
# When I press "Create Outage"
|
||||
# And I press "Save changes"
|
||||
# And I should not see "No outages found." in the "#section_planned_outages" "css_element"
|
||||
# And I should see "No outages found." in the "#section_outage_history" "css_element"
|
||||
|
||||
66
views/manage.php
Normal file
66
views/manage.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* View to manage outages.
|
||||
*
|
||||
* @package auth_outage
|
||||
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use auth_outage\output\manage\history_table;
|
||||
use auth_outage\output\manage\planned_table;
|
||||
use auth_outage\output\renderer;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$urlnew = new moodle_url('/auth/outage/new.php');
|
||||
?>
|
||||
|
||||
<section id="section_planned_outages">
|
||||
<?php echo renderer::get()->rendersubtitle('outageslistfuture'); ?>
|
||||
<?php if (empty($viewbag['unended'])): ?>
|
||||
<p>
|
||||
<small><?php echo get_string('notfound', 'auth_outage'); ?></small>
|
||||
</p>
|
||||
<?php else: ?>
|
||||
<?php
|
||||
$table = new planned_table();
|
||||
$table->show_data($viewbag['unended']);
|
||||
$table->finish_output();
|
||||
?>
|
||||
<?php endif; ?>
|
||||
<input type="button" class="form-submit"
|
||||
value="<?php echo get_string('outagecreate', 'auth_outage'); ?>"
|
||||
onclick="location.href='<?php echo $urlnew; ?>';"/>
|
||||
</section>
|
||||
|
||||
<section id="section_outage_history">
|
||||
<?php echo renderer::get()->rendersubtitle('outageslistpast'); ?>
|
||||
<?php if (empty($viewbag['ended'])): ?>
|
||||
<p>
|
||||
<small><?php echo get_string('notfound', 'auth_outage'); ?></small>
|
||||
</p>
|
||||
<?php else: ?>
|
||||
<?php
|
||||
$table = new history_table();
|
||||
$table->show_data($viewbag['ended']);
|
||||
$table->finish_output();
|
||||
?>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
Reference in New Issue
Block a user