Skip to content

Commit

Permalink
Fix behat test
Browse files Browse the repository at this point in the history
  • Loading branch information
dasistwas committed Jan 11, 2025
1 parent 7892276 commit ca707fb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
16 changes: 6 additions & 10 deletions classes/view/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ abstract class base {
* when just displaying the view.
* @var bool
*/
protected bool $entriesprocessedsuccessfully = false;
public bool $entriesprocessedsuccessfully = false;

/**
* Constructor
Expand Down Expand Up @@ -164,19 +164,15 @@ public function __construct($df = 0, $view = 0, $filteroptions = true) {
// Set editors and patterns.
$this->set__editors();
$this->set__patterns();
$this->set_filter($filteroptions, $this->is_forcing_filter()); // If filter is forced ignore URL parameters.

// Base url params.
$baseurlparams = array();
$baseurlparams['d'] = $this->_df->id();
$baseurlparams['view'] = $this->id();
$baseurlparams['filter'] = $this->_filter->id;
if (!empty($eids)) {
$baseurlparams['eids'] = $eids;
}
if ($this->_filter->page) {
$baseurlparams['page'] = $this->_filter->page;
}

if ($this->_df->currentgroup) {
$baseurlparams['currentgroup'] = $this->_df->currentgroup;
}
Expand All @@ -191,10 +187,10 @@ public function __construct($df = 0, $view = 0, $filteroptions = true) {

$this->_baseurl = new moodle_url("/mod/datalynx/{$this->_df->pagefile()}.php", $baseurlparams);
$this->set_filter($filteroptions, $this->is_forcing_filter()); // If filter is forced ignore URL parameters.
$this->_baseurl->param('filter', $this->_filter->id);
if ($this->_filter->page) {
$this->_baseurl->param('page', $this->_filter->page);
}
$this->_baseurl->param('filter', $this->_filter->id);
$this->set_groupby_per_page();

require_once("$CFG->dirroot/mod/datalynx/entries_class.php");
Expand Down Expand Up @@ -641,7 +637,7 @@ public function display(array $options = []): string {
} else if ($this->_entries->get_count()) {
// Entries have been updated or added.
if ($this->entriesprocessedsuccessfully) {
$redirectid = $this->_redirect ? $this->_redirect : $this->id();
$redirectid = $this->_redirect ?: $this->id();
$url = new moodle_url($this->_baseurl, array('view' => $redirectid));
$output = $notifications . $OUTPUT->continue_button($url);
} else {
Expand Down Expand Up @@ -1594,8 +1590,8 @@ public function process_entries_data() {
$this->_entries->set_content();
}

// Set the display definition for the form.
$this->_editentries = explode(',', $update);
// Set the display definition for the form. Cast $update to string because PHP has a problem exploding -1 integer.
$this->_editentries = explode(',', (string) $update);
$this->set__display_definition();

$entriesform = $this->get_entries_form();
Expand Down
7 changes: 5 additions & 2 deletions filter/filter_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
* @copyright based on the work by 2011 Itamar Tzadok
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use mod_datalynx\view\base;

defined('MOODLE_INTERNAL') || die();

/**
Expand Down Expand Up @@ -1367,7 +1370,7 @@ public function get_advanced_filter_form($filter, $view) {

/**
*/
public function get_customfilter_frontend_form($filter, $view, $customfilter = false) {
public function get_customfilter_frontend_form($filter, base $view, $customfilter = false) {
global $CFG;

require_once("$CFG->dirroot/mod/datalynx/filter/filter_form.php");
Expand Down Expand Up @@ -1396,7 +1399,7 @@ public function get_user_filters_menu($viewid) {

/**
*/
public function set_user_filter($filterid, $view, $advanced = false, $customfilter = false) {
public function set_user_filter($filterid, base $view, $advanced = false, $customfilter = false) {
$df = $this->_df;
$dfid = $df->id();
$viewid = $view->id();
Expand Down
17 changes: 11 additions & 6 deletions tests/behat/customfilter_multiselect.feature
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ Feature: Create entry, add multiselect and use customfilter

# Make customfilter visible in view.
When I follow "Views"
And I click on "//table/tbody/tr[1]/td[9]/a" "xpath_element"
Then I should see "Gridview"
And I click on "Edit Gridview" "link"
And I click on "View template" "link"
Then I add to "id_esection_editor" editor the text ". ##addnewentry## ##customfilter:mycustomfilter## ##entries## ."
And I press "Save changes"
Expand All @@ -61,13 +60,15 @@ Feature: Create entry, add multiselect and use customfilter
And I click on "Opt4" item in the autocomplete list
And I click on "Opt5" item in the autocomplete list
And I press "Save changes"
And I wait until the page is ready
And I should see "1 entry(s) updated"
Then I press "Continue"

And I follow "Add a new entry"
And I fill in the entry form fields
| type | name | value |
| text | Text | testtext2 |
And I open the autocomplete suggestions list
And I click on "Opt2" item in the autocomplete list
And I press "Save changes"
And I press "Continue"
Expand All @@ -76,6 +77,7 @@ Feature: Create entry, add multiselect and use customfilter
And I fill in the entry form fields
| type | name | value |
| text | Text | testtext3 |
And I open the autocomplete suggestions list
And I click on "Opt3" item in the autocomplete list
And I press "Save changes"
And I press "Continue"
Expand All @@ -84,6 +86,7 @@ Feature: Create entry, add multiselect and use customfilter
And I fill in the entry form fields
| type | name | value |
| text | Text | testtext4 |
And I open the autocomplete suggestions list
And I click on "Opt4" item in the autocomplete list
And I press "Save changes"
And I press "Continue"
Expand All @@ -98,16 +101,18 @@ Feature: Create entry, add multiselect and use customfilter
Then "Opt2" "autocomplete_suggestions" should exist
And I click on "Opt2" item in the autocomplete list
And I close the autocomplete suggestions list
And I click on "//input[@value = 'Search']" "xpath_element"
And I press the escape key
And I press "id_customsearch"
And I should see "Opt2"
And I should not see "Opt3"
And I should not see "Opt5"

# Use customfilter to select Opt1 OR Opt2.
When I follow "Search"
And I open the autocomplete suggestions list
And I click on "Opt1" item in the autocomplete list
And I close the autocomplete suggestions list
And I click on "//input[@value = 'Search']" "xpath_element"
And I press "id_customsearch"
And I should see "Opt1"
And I should see "Opt2"
And I should see "Opt4"
Expand All @@ -120,7 +125,7 @@ Feature: Create entry, add multiselect and use customfilter
And I click on "Opt5" item in the autocomplete list
And I close the autocomplete suggestions list
And I click on "All selected options have to be part of the entry" "checkbox"
And I click on "//input[@value = 'Search']" "xpath_element"
And I press "id_customsearch"
And I should not see "Opt2"
And I should not see "testtext2"

Expand All @@ -139,7 +144,7 @@ Feature: Create entry, add multiselect and use customfilter
And I open the autocomplete suggestions list
And I click on "Opt1" item in the autocomplete list
And I close the autocomplete suggestions list
And I click on "//input[@value = 'Search']" "xpath_element"
And I press "id_customsearch"
And I should see "Opt1"
And I should see "testtext1"
And I should see "Opt4"
Expand Down
3 changes: 2 additions & 1 deletion view/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@
$viewdescription = shorten_text($view->view->description, 30);
$viewedit = html_writer::link(
new moodle_url($editbaseurl, $linkparams + array('vedit' => $viewid)),
$OUTPUT->pix_icon('t/edit', $stredit));
$OUTPUT->pix_icon('t/edit', $stredit . " " . $view->name()),
array('title' => $stredit . " " . $view->name()));
$viewduplicate = html_writer::link(
new moodle_url($actionbaseurl, $linkparams + array('duplicate' => $viewid)),
$OUTPUT->pix_icon('t/copy', $strduplicate));
Expand Down
4 changes: 4 additions & 0 deletions view/view_patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ protected function get_userpref_replacements($tag, array $options = null) {
case '##advancedfilter##':
return $this->print_advanced_filter($filter, true);
}
// When we just updated an entry, only a continue button is shown, so do not display the form.
if ($this->_view->entriesprocessedsuccessfully) {
return '';
}
if (strpos($tag, '##customfilter') !== false && empty($view->user_is_editing())) {
return $this->print_custom_filter($tag, true);
}
Expand Down

0 comments on commit ca707fb

Please sign in to comment.