From 104ea886bac23f9b6a5dd1dc00fb2753d4baeccb Mon Sep 17 00:00:00 2001 From: hieuvu Date: Thu, 1 Aug 2024 12:54:00 +0700 Subject: [PATCH] StudentQuiz: When a user filters multiple states of questions, it should display correct result --- classes/condition/studentquiz_condition.php | 9 ++++++--- tests/behat/state_visibility.feature | 15 +++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/classes/condition/studentquiz_condition.php b/classes/condition/studentquiz_condition.php index d5cea258..125e61b3 100755 --- a/classes/condition/studentquiz_condition.php +++ b/classes/condition/studentquiz_condition.php @@ -170,7 +170,7 @@ protected function init() { $sqldata[0] = str_replace($field->_name, $this->get_sql_field($field->_name) , $sqldata[0]); $sqldata[0] = $this->get_special_sql($sqldata[0], $field->_name); - $this->tests[] = '((' . $sqldata[0] . '))'; + $this->tests[] = $sqldata[0]; $this->customparams = array_merge($this->customparams, $sqldata[1]); } } @@ -255,8 +255,11 @@ private function get_sql_table_prefix($name) { * Provide SQL fragment to be ANDed into the WHERE clause to filter which questions are shown. * @return string SQL fragment. Must use named parameters. */ - public function where() { - return implode(' AND ', $this->tests); + public function where(): string { + if (!empty($this->tests)) { + return '(' . implode(' OR ', $this->tests) . ')'; + } + return ''; } /** diff --git a/tests/behat/state_visibility.feature b/tests/behat/state_visibility.feature index 7736bb89..1418ba01 100644 --- a/tests/behat/state_visibility.feature +++ b/tests/behat/state_visibility.feature @@ -53,7 +53,7 @@ Feature: Question states and visibility And I should see "TF 01" @javascript @_switch_window - Scenario: Test filter + Scenario: Test filter for StudentQuiz When I am on the "StudentQuiz Test 2" "mod_studentquiz > View" page logged in as "student1" And I click on "Create new question" "button" @@ -105,6 +105,7 @@ Feature: Question states and visibility And I click on "Change state" "button" And I switch to the main window + # There is a duplicate link that contain a 'new' word. And I click on "//a[text() = 'New']" "xpath_element" And I press "id_submitbutton" Then I should see "TF 04" @@ -113,7 +114,7 @@ Feature: Question states and visibility And I should not see "TF 03" And I click on "Reset" "button" - And I click on "//a[text() = 'Approved']" "xpath_element" + And I click on "Approved" "link" And I press "id_submitbutton" And I should see "TF 02" And I should not see "TF 01" @@ -121,7 +122,7 @@ Feature: Question states and visibility And I should not see "TF 04" And I click on "Reset" "button" - And I click on "//a[text() = 'Disapproved']" "xpath_element" + And I click on "Disapproved" "link" And I press "id_submitbutton" And I should see "TF 01" And I should not see "TF 02" @@ -129,7 +130,7 @@ Feature: Question states and visibility And I should not see "TF 04" And I click on "Reset" "button" - And I click on "//a[text() = 'Changed']" "xpath_element" + And I click on "Changed" "link" And I press "id_submitbutton" And I should see "TF 03" And I should not see "TF 01" @@ -137,6 +138,12 @@ Feature: Question states and visibility And I should not see "TF 04" And I click on "Reset" "button" + And I click on "Changed" "link" + And I click on "Approved" "link" + And I press "id_submitbutton" + And I should see "TF 03" + And I should see "TF 02" + @javascript Scenario: Hide question When I am on the "StudentQuiz Test 1" "mod_studentquiz > View" page logged in as "admin"