Commit 506cdabb authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Merge "Behat Bug:1829080 SmartEvidence framework matrix editor functionality"

parents 154c2894 ccbd4232
......@@ -174,6 +174,7 @@ $frameworks = Framework::get_frameworks('any');
if ($frameworks) {
foreach ($frameworks as $framework) {
$fk = new Framework($framework->id);
$framework->institution_name = ($fk->get('institution_name')) ? $fk->get('institution_name') : '';
if ($fk->get('active')) {
$framework->active = array(
'title' => 'Enabled',
......
......@@ -33,7 +33,7 @@
* check copy save
* add inst default in the php. It's already there?
*/
var editor;
jQuery(function($) {
// Use bootstrap
JSONEditor.defaults.options.theme = 'bootstrap4';
......@@ -57,7 +57,6 @@ jQuery(function($) {
// Enable select2
JSONEditor.plugins.select2.enable = true;
var editor;
var parent_array = [''];
var standard_array = [];
var standard_names = [];
......
......@@ -177,6 +177,7 @@ class Framework {
private $id;
private $name;
private $institution;
private $institution_name;
private $description;
private $selfassess;
private $active = 1; // active by default
......@@ -215,6 +216,9 @@ class Framework {
if ($field == 'selfassess' || $field == 'active') {
$value = (int) $value;
}
if ($field === 'institution' && $value != 'all') {
$this->institution_name = get_field('institution', 'displayname', 'name', $value);
}
$this->{$field} = $value;
}
}
......
......@@ -1524,6 +1524,107 @@ EOF;
}
}
private function i_get_se_field($dv) {
// If we are not running javascript we can't test the form
if (!$this->running_javascript()) {
throw new DriverException('SE editor tests are disabled in scenarios without Javascript support');
}
// If we are looking at a "standards" or "standardelements" node we need to check that it is active
$checkactive = (preg_match('/\.standards\./', $dv) || preg_match('/\.standardelements\./', $dv)) ? "//div[contains(concat(' ', normalize-space(@class), ' '), ' active ')]" : '';
$exception = new Exception('The field at schemapath "' . $dv . '" ' . ($checkactive ? 'in active tab ' : '') . 'not found');
$xpath = $checkactive . "//div[contains(concat(' ', normalize-space(@data-schemapath), ' '), ' " . $dv . " ')]" .
"//input" .
" | " .
$checkactive . "//div[contains(concat(' ', normalize-space(@data-schemapath), ' '), ' " . $dv . " ')]" .
"//select" .
" | " .
$checkactive . "//div[contains(concat(' ', normalize-space(@data-schemapath), ' '), ' " . $dv . " ')]" .
"//textarea";
// First check the node exists
$node = $this->find('xpath', $xpath, $exception);
return $xpath;
}
/**
* Investigate a Smart Evidence editor field via data schemepath attribute
*
* @Given the SE field :datavalue should contain :value
*/
public function i_check_the_se_field($dv, $value) {
$xpath = $this->i_get_se_field($dv);
$textliteral = $this->escaper->escapeLiteral($value);
// Then check that is set to value
// We need to do this via JS
$js = "(function() {
var fxpath = document.evaluate (
\"" . $xpath . "\",
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null
);
var hasValue = jQuery(fxpath.snapshotItem(0)).val();
var hasMatch = hasValue.indexOf(" . $textliteral . ");
// If not found in value check if a select field and if option text matches
if (hasMatch == -1 && jQuery(fxpath.snapshotItem(0)).prop('tagName') == 'SELECT') {
hasValue = jQuery(fxpath.snapshotItem(0)).find(':selected').text();
hasMatch = hasValue.indexOf(" . $textliteral . ");
}
return (hasMatch != -1);
})()";
$result = $this->getSession()->evaluateScript("$js");
if ($result == false) {
throw new Exception('The field at schemapath "' . $dv . '" does not contain text "' . $textliteral . '"');
}
}
/**
* Investigate a Smart Evidence editor field via data schemepath attribute
*
* @Given the SE field :datavalue should not contain :value
*/
public function i_check_the_se_field2($dv, $value) {
$xpath = $this->i_get_se_field($dv);
$textliteral = $this->escaper->escapeLiteral($value);
// Then check that is set to value
// We need to do this via JS
$js = "(function() {
var fxpath = document.evaluate (
\"" . $xpath . "\",
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null
);
var hasValue = jQuery(fxpath.snapshotItem(0)).val();
var hasMatch = hasValue.indexOf(" . $textliteral . ");
// If not found in value check if a select field and if option text matches
if (hasMatch == -1 && jQuery(fxpath.snapshotItem(0)).prop('tagName') == 'SELECT') {
hasValue = jQuery(fxpath.snapshotItem(0)).find(':selected').text();
hasMatch = hasValue.indexOf(" . $textliteral . ");
}
return (hasMatch == -1);
})()";
$result = $this->getSession()->evaluateScript("$js");
if ($result == false) {
throw new Exception('The field at schemapath "' . $dv . '" does contain text "' . $textliteral . '"');
}
}
/**
* Update a Smart Evidence editor field via data schemepath attribute
*
* @Given I set the SE field :datavalue to :value
*/
public function i_set_the_se_field($dv, $value) {
$xpath = $this->i_get_se_field($dv);
$textliteral = $this->escaper->escapeLiteral($value);
// Then check that is set to value
// We need to do this via JS
$js = 'editor.getEditor("' . $dv . '").setValue(' . $textliteral . ');';
$result = $this->getSession()->evaluateScript("$js");
}
/**
* Display the editting page
*
......
......@@ -7,6 +7,7 @@
<thead>
<tr>
<th>{str tag="name"}</th>
<th>{str tag="institution" section="mahara"}</th>
<th>{str tag="usedincollections" section="module.framework"}</th>
<th>{str tag="selfassess" section="module.framework"}</th>
<th>{str tag="active"}</th>
......@@ -17,6 +18,7 @@
{foreach from=$frameworks key=k item=item}
<tr>
<td>{$item->name}</td>
<td>{$item->institution_name}</td>
<td>{$item->collections}</td>
<td>{$item->selfassess}</td>
<td>
......
@javascript @core @smartevidence
Feature: SmartEvidence editor
As a site administrator
I want to edit or copy a framework matrix
Background:
Given the following "institutions" exist:
| name | displayname | registerallowed | registerconfirm |
| instone | Institution One | ON | OFF |
Scenario: Site administrator uploads and edits a SmartEvidence framework matrix
Given I log in as "admin" with password "Kupuh1pa!"
And I choose "SmartEvidence" in "Extensions" from administration menu
And I follow "Import" in the "Arrow-bar nav" property
And I attach the file "example.matrix" to "Matrix file"
And I press "Upload matrix"
# Check that we have new framework
Then I should see "Title of your framework"
When I click on "Edit" in "Title of your framework" row
And I disable the switch "Active framework"
And I press "Save"
Then I should see "Settings saved"
When I follow "Editor" in the "Arrow-bar nav" property
Then I should see "The current form contents are valid and ok to submit"
When I select "Title of your framework" from "Edit saved framework"
And I wait "1" seconds
And the SE field "root.name" should contain "Title of your framework"
And I set the SE field "root.name" to "Fish"
And the SE field "root.name" should not contain "Title of your framework"
And the SE field "root.institution" should contain "all"
And I set the SE field "root.institution" to "Institution One"
And the SE field "root.evidencestatuses.begun" should contain "Ready for assessment"
And the SE field "root.standards.0.name" should contain "Title of the standard"
And I set the SE field "root.standards.0.name" to "Standard One"
And the SE field "root.description" should contain "You can write more in the description"
And I set the SE field "root.description" to "This is my new description"
And the SE field "root.selfassess" should contain "No"
And I press "add_standard"
And the SE field "root.standards.4.shortname" should contain "Short name"
And I set the SE field "root.standards.4.shortname" to "New standard"
# Not working yet
# And I click on "Delete last standard" delete button
And I follow "1.2"
And the SE field "root.standardelements.1.name" should contain "1.2 - Sub level of the standard"
And I scroll to the top
And I press "Save"
And I follow "Management" in the "Arrow-bar nav" property
Then I should see "Fish"
Then I should see "Institution One"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment