Issue #46 - Added behat tests for the warning bar. Fixed failing unit tests for Moodle 27 28 and 29. Fixed javascript not considering stop time of an outage related to Issue #53.

This commit is contained in:
Daniel Thee Roperto
2016-09-27 16:05:38 +10:00
parent 6a78557487
commit 58eeaccc75
7 changed files with 193 additions and 17 deletions

View File

@@ -14,24 +14,30 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Steps definitions related to auth_outage.
*
* @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
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
use auth_outage\dml\outagedb;
use auth_outage\local\outage;
use Behat\Gherkin\Node\TableNode;
use Behat\Mink\Exception\ExpectationException;
require_once(__DIR__.'/../../../../lib/behat/behat_base.php');
/**
* Steps definitions related to auth_outage.
*
* @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
* @SuppressWarnings("public") Allow this test to have as many tests as necessary.
*/
class behat_auth_outage extends behat_base {
/**
* @var outage Which outage are we checking.
*/
private $outage = null;
/**
* @Given the authentication plugin :name is enabled
*/
@@ -159,4 +165,109 @@ class behat_auth_outage extends behat_base {
throw new ExpectationException('Number of windows: '.$count, $this->getSession());
}
}
/**
* @Then I should see :text in the warning bar
*/
public function i_should_see_in_the_warning_bar($text) {
$element = '#auth_outage_warningbar_box';
$container = $this->getSession()->getPage()->findAll('css', $element);
if (count($container) == 0) {
throw new ExpectationException('"'.$element.'" element not found', $this->getSession());
}
$container = $container[0];
$xpathliteral = behat_context_helper::escape($text);
$xpath = "/descendant-or-self::*[contains(., $xpathliteral)]".
"[count(descendant::*[contains(., $xpathliteral)]) = 0]";
$found = $this->find_all('xpath', $xpath, false, $container);
if (count($found) == 0) {
throw new ExpectationException('"'.$text.'" text was not found in the "'.$element.'" element', $this->getSession());
}
foreach ($found as $node) {
if ($node->isVisible()) {
return;
}
}
throw new ExpectationException('"'.$text.'" text was found in the "'.$element.'" element but was not visible',
$this->getSession());
}
/**
* @Then I should not see the warning bar
*/
public function i_should_not_see_the_warning_bar() {
$selector = 'css';
$locator = "#auth_outage_warningbar_box";
$items = $this->getSession()->getPage()->findAll($selector, $locator);
if (count($items) > 0) {
throw new ExpectationException($locator.' found, not expected.', $this->getSession());
}
}
/**
* @Given there is the following outage:
*/
public function there_is_the_following_outage(TableNode $data) {
$time = time();
$row = $data->getHash()[0];
// Set defaults.
$row = array_merge(
[
'autostart' => 'no',
'warnbefore' => 60,
'startsin' => 0,
'stopsafter' => 60,
'finished' => null,
'title' => 'Outage Title',
'description' => 'Outage Description.',
],
$row
);
if (($row['autostart'] != 'yes') && ($row['autostart'] != 'no')) {
throw new Exception('autostart must be yes or no, found: '.$row['autostart']);
}
if ($row['finished'] == '') {
$row['finished'] = null;
}
$starttime = $time + $row['startsin'];
$this->outage = new outage([
'autostart' => ($row['autostart'] == 'yes'),
'warntime' => $starttime - $row['warnbefore'],
'starttime' => $starttime,
'stoptime' => $starttime + $row['stopsafter'],
'finished' => $row['finished'],
'title' => $row['title'],
'description' => $row['description'],
]);
outagedb::save($this->outage);
}
/**
* @When /^I wait until the outage (?P<what>warns|starts|stops)$/
*/
public function i_wait_until_outage($what) {
switch ($what) {
case 'warns':
$seconds = $this->outage->warntime - time();
break;
case 'starts':
$seconds = $this->outage->starttime - time();
break;
case 'stops':
$seconds = $this->outage->stoptime - time();
break;
default:
throw new Exception('Invalid $what='.$what);
}
if ($seconds >= 0) {
$seconds++; // Give one extra second for things to happen.
$this->getSession()->wait($seconds * 1000, false);
}
}
}

View File

@@ -1,5 +1,5 @@
@auth @auth_outage @javascript
Feature: Test changing the default settings.
Feature: Change the default settings
In order to easily create outages
As an admin
I need to configure the outage defaults

View File

@@ -1,8 +1,8 @@
@auth @auth_outage @javascript
Feature: Test the outage management functionality.
In order to check if I can manage outages
Feature: Manage outages
In order to manage outages
As an admin
I need to view, create, edit, delete, clone and finish an outage.
I need to view, create, edit, delete, clone and finish an outage
Outage stage terminology:
- waiting is an outage in the future, not yet in the warning period.

View File

@@ -0,0 +1,56 @@
@dev @auth @auth_outage @javascript
Feature: Warning bar
In order alert users about an outage
As any user
I need to view the warning bar
Outage stage terminology:
- waiting is an outage in the future, not yet in the warning period.
- warning is an outage in the future but already in the warning period.
- ongoing is an outage that has started, but not yet reached the stop time nor is marked as finished.
- finished is an outage that has explicitly been marked as finished.
- stopped is an outage that has already ended but not explicitly marked as finished.
Background:
Given the authentication plugin "outage" is enabled
Scenario: This is how an outage should happend without maintenance mode and manual finish.
Given there is the following outage:
| warnbefore | startsin | stopsafter |
| 10 | 20 | 10 |
When I am on homepage
Then I should not see the warning bar
When I wait until the outage warns
And I reload the page
Then I should see "Shutting down in" in the warning bar
When I wait until the outage starts
Then I should see "Back online at" in the warning bar
When I wait until the outage stops
Then I should see "We are back online!" in the warning bar
When I reload the page
Then I should not see the warning bar
Scenario Outline: Some stages should show its own warning message.
Given there is a <type> outage
When I am on homepage
Then I should see "<see>" in the warning bar
Examples:
| type | see |
| warning | Shutting down in |
| ongoing | Back online at |
Scenario Outline: Some stages should not have a warning bar.
Given there is a <type> outage
When I am on homepage
Then I should not see the warning bar
Examples:
| type |
| waiting |
| finished |
| stopped |

View File

@@ -17,6 +17,7 @@
use auth_outage\dml\outagedb;
use auth_outage\local\controllers\infopage;
use auth_outage\local\outage;
use auth_outage\task\update_static_page;
defined('MOODLE_INTERNAL') || die();
@@ -272,13 +273,12 @@ class infopagecontroller_test extends advanced_testcase {
'description' => 'Description',
]);
$info = new infopage(['outage' => $outage]);
self::hasExpectationOnOutput();
$output = $info->get_output();
self::assertContains('auth_outage_info', $output);
}
public function test_tasks() {
$task = new \auth_outage\task\update_static_page();
$task = new update_static_page();
self::assertNotEmpty($task->get_name());
$task->execute();
}

View File

@@ -86,7 +86,6 @@ class outagelib_test extends advanced_testcase {
}
public function test_inject_broken() {
global $CFG;
$_GET = ['auth_outage_break_code' => '1'];
outagelib::reinject();
self::assertCount(2, phpunit_util::get_debugging_messages());