Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
moodle
moodle
Commits
1d2cdb3a
Commit
1d2cdb3a
authored
Oct 01, 2021
by
Andrew Nicols
Browse files
MDL-71610 behat: Add custom steps for edit mode checks
parent
4562ea0b
Changes
4
Hide whitespace changes
Inline
Side-by-side
admin/tool/behat/tests/behat/data_generators.feature
View file @
1d2cdb3a
...
...
@@ -139,19 +139,19 @@ Feature: Set up contextual data for tests
|
user5
|
custom2
|
System
|
|
When
I log in as
"user1"
And
I am on site homepage
Then
I should see
"Edit mode"
Then
edit mode should be available on the current page
And
I log out
And
I log in as
"user2"
And
I am on
"Course 1"
course homepage
Then
I should see
"Edit mode"
Then
edit mode should be available on the current page
And
I log out
And
I log in as
"user3"
And
I am on
"Course 1"
course homepage
Then
I should see
"Edit mode"
Then
edit mode should be available on the current page
And
I log out
And
I log in as
"user4"
And
I am on
"Course 1"
course homepage
Then
I should see
"Edit mode"
Then
edit mode should be available on the current page
And
I log out
And
I log in as
"user5"
And
I should see
"You are logged in as"
...
...
lib/tests/behat/behat_general.php
View file @
1d2cdb3a
...
...
@@ -1010,6 +1010,45 @@ EOF;
throw
new
ExpectationException
(
"The '
{
$element
}
' '
{
$selectortype
}
' exists in the current page"
,
$this
->
getSession
());
}
/**
* Ensure that edit mode is (not) available on the current page.
*
* @Then edit mode should be available on the current page
* @Then edit mode should :not be available on the current page
* @param bool $not
*/
public
function
edit_mode_should_be_available
(
bool
$not
=
false
):
void
{
$isavailable
=
$this
->
is_edit_mode_available
();
$shouldbeavailable
=
empty
(
$not
);
if
(
$isavailable
&&
!
$shouldbeavailable
)
{
throw
new
ExpectationException
(
"Edit mode is available and should not be"
,
$this
->
getSession
());
}
else
if
(
$shouldbeavailable
&&
!
$isavailable
)
{
throw
new
ExpectationException
(
"Edit mode is not available and should be"
,
$this
->
getSession
());
}
}
/**
* Check whether edit mode is available on the current page.
*
* @return bool
*/
public
function
is_edit_mode_available
():
bool
{
// If the course is already in editing mode then it will have the class 'editing' on the body.
// This is a 'cheap' way of telling if the course is in editing mode and therefore if edit mode is available.
$body
=
$this
->
find
(
'css'
,
'body'
);
if
(
$body
->
hasClass
(
'editing'
))
{
return
true
;
}
try
{
$this
->
find
(
'field'
,
get_string
(
'editmode'
),
false
,
false
,
0
);
return
true
;
}
catch
(
ElementNotFoundException
$e
)
{
return
false
;
}
}
/**
* This step triggers cron like a user would do going to admin/cron.php.
*
...
...
lib/tests/behat/locking.feature
View file @
1d2cdb3a
...
...
@@ -44,15 +44,15 @@ Feature: Context freezing apply to child contexts
And
I click on
"Continue"
"button"
Then
"Add a new discussion topic"
"link"
should not exist
When
I am on
"courseaa1"
course homepage
Then
"Se
t mode
"
"button"
should exist
Then
edi
t mode
should be available on the current page
When
I follow
"faa1b"
Then
"Add a new discussion topic"
"link"
should exist
When
I am on
"courseaa2"
course homepage
Then
"Se
t mode
"
"button"
should exist
Then
edi
t mode
should be available on the current page
When
I follow
"faa2"
Then
"Add a new discussion topic"
"link"
should exist
When
I am on
"courseb"
course homepage
Then
"Se
t mode
"
"button"
should exist
Then
edi
t mode
should be available on the current page
When
I follow
"fb"
Then
"Add a new discussion topic"
"link"
should exist
...
...
@@ -61,15 +61,15 @@ Feature: Context freezing apply to child contexts
And
I follow
"faa1"
Then
"Add a new discussion topic"
"link"
should not exist
When
I am on
"courseaa1"
course homepage
Then
"Se
t mode
"
"button"
should exist
Then
edi
t mode
should be available on the current page
When
I follow
"faa1b"
Then
"Add a new discussion topic"
"link"
should exist
When
I am on
"courseaa2"
course homepage
Then
"Se
t mode
"
"button"
should exist
Then
edi
t mode
should be available on the current page
When
I follow
"faa2"
Then
"Add a new discussion topic"
"link"
should exist
When
I am on
"courseb"
course homepage
Then
"Se
t mode
"
"button"
should exist
Then
edi
t mode
should be available on the current page
When
I follow
"fb"
And
"Add a new discussion topic"
"link"
should exist
...
...
@@ -89,23 +89,23 @@ Feature: Context freezing apply to child contexts
Scenario
:
Freeze course should freeze all children
Given
I am on the
"courseaa1"
"Course"
page logged in as
"admin"
And
"Set mode"
"button"
should exist
Then
edit mode should be available on the current page
When
I follow
"Freeze this context"
And
I click on
"Continue"
"button"
Then
"Se
t mode
"
"button"
should not
exist
Then
edi
t mode should not
be available on the current page
Then
"Add a new discussion topic"
"link"
should not exist
When
I am on
"courseaa1"
course homepage
Then
"Se
t mode
"
"button"
should not
exist
Then
edi
t mode should not
be available on the current page
And
"Unfreeze this context"
"link"
should exist in current page administration
When
I follow
"faa1b"
Then
"Add a new discussion topic"
"link"
should not exist
And
"Unfreeze this context"
"link"
should not exist in current page administration
When
I am on
"courseaa2"
course homepage
Then
"Se
t mode
"
"button"
should exist
Then
edi
t mode
should be available on the current page
When
I follow
"faa2"
Then
"Add a new discussion topic"
"link"
should exist
When
I am on
"courseb"
course homepage
Then
"Se
t mode
"
"button"
should exist
Then
edi
t mode
should be available on the current page
When
I follow
"fb"
Then
"Add a new discussion topic"
"link"
should exist
...
...
@@ -114,15 +114,15 @@ Feature: Context freezing apply to child contexts
And
I follow
"faa1"
Then
"Add a new discussion topic"
"link"
should not exist
When
I am on
"courseaa1"
course homepage
Then
"Se
t mode
"
"button"
should not
exist
Then
edi
t mode should not
be available on the current page
When
I follow
"faa1b"
Then
"Add a new discussion topic"
"link"
should not exist
When
I am on
"courseaa2"
course homepage
Then
"Se
t mode
"
"button"
should exist
Then
edi
t mode
should be available on the current page
When
I follow
"faa2"
Then
"Add a new discussion topic"
"link"
should exist
When
I am on
"courseb"
course homepage
Then
"Se
t mode
"
"button"
should exist
Then
edi
t mode
should be available on the current page
When
I follow
"fb"
Then
"Add a new discussion topic"
"link"
should exist
...
...
@@ -146,39 +146,39 @@ Feature: Context freezing apply to child contexts
And
I click on
"managecontextlock"
action for
"cata"
in management category listing
And
I click on
"Continue"
"button"
And
I am on
"courseaa1"
course homepage
And
"Set mode"
"button"
should not exist
Then
edit mode should not be available on the current page
Then
"Add a new discussion topic"
"link"
should not exist
When
I am on
"courseaa1"
course homepage
Then
"Se
t mode
"
"button"
should not
exist
Then
edi
t mode should not
be available on the current page
And
"Unfreeze this context"
"link"
should not exist in current page administration
When
I follow
"faa1b"
Then
"Add a new discussion topic"
"link"
should not exist
And
"Unfreeze this context"
"link"
should not exist in current page administration
When
I am on
"courseaa2"
course homepage
Then
"Se
t mode
"
"button"
should not
exist
Then
edi
t mode should not
be available on the current page
When
I follow
"faa2"
Then
"Add a new discussion topic"
"link"
should not exist
And
"Unfreeze this context"
"link"
should not exist in current page administration
When
I am on
"courseb"
course homepage
Then
"Se
t mode
"
"button"
should exist
Then
edi
t mode
should be available on the current page
When
I follow
"fb"
Then
"Add a new discussion topic"
"link"
should exist
And
I log out
When
I am on the
"courseaa1"
"Course"
page logged in as
"teacher"
Then
"Se
t mode
"
"button"
should not
exist
Then
edi
t mode should not
be available on the current page
And
I follow
"faa1"
Then
"Add a new discussion topic"
"link"
should not exist
When
I am on
"courseaa1"
course homepage
Then
"Se
t mode
"
"button"
should not
exist
Then
edi
t mode should not
be available on the current page
When
I follow
"faa1b"
Then
"Add a new discussion topic"
"link"
should not exist
When
I am on
"courseaa2"
course homepage
Then
"Se
t mode
"
"button"
should not
exist
Then
edi
t mode should not
be available on the current page
When
I follow
"faa2"
Then
"Add a new discussion topic"
"link"
should not exist
When
I am on
"courseb"
course homepage
Then
"Se
t mode
"
"button"
should exist
Then
edi
t mode
should be available on the current page
When
I follow
"fb"
Then
"Add a new discussion topic"
"link"
should exist
...
...
theme/classic/tests/behat/behat_theme_classic_behat_general.php
0 → 100644
View file @
1d2cdb3a
<?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/>.
use
Behat\Mink\Exception\ElementNotFoundException
;
require_once
(
__DIR__
.
'/../../../../lib/tests/behat/behat_general.php'
);
/**
* Behat grade related step definition overrides for the Classic theme.
*
* @package theme_classic
* @category test
* @copyright 2021 Andrew Lyons <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class
behat_theme_classic_behat_general
extends
behat_general
{
/**
* Check whether edit mode is available on the current page.
*
* @return bool
*/
public
function
is_edit_mode_available
():
bool
{
// If the course is already in editing mode then it will have the class 'editing' on the body.
// This is a 'cheap' way of telling if the course is in editing mode and therefore if edit mode is available.
$body
=
$this
->
find
(
'css'
,
'body'
);
if
(
$body
->
hasClass
(
'editing'
))
{
return
true
;
}
// If the page is not in editing mode then the only way to put it in editing mode is a "Turn editing on" button
// or link.
try
{
$this
->
find
(
'button'
,
get_string
(
'turneditingon'
),
false
,
false
,
0
);
return
true
;
}
catch
(
ElementNotFoundException
$e
)
{}
try
{
$this
->
find
(
'link'
,
get_string
(
'turneditingon'
),
false
,
false
,
0
);
return
true
;
}
catch
(
ElementNotFoundException
$e
)
{}
return
false
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment