Skip to content

Commit

Permalink
StudentQuiz: When a user filters multiple states of questions, it sho…
Browse files Browse the repository at this point in the history
…uld display correct result
  • Loading branch information
hieuvu committed Aug 2, 2024
1 parent 8f4fe71 commit 104ea88
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
9 changes: 6 additions & 3 deletions classes/condition/studentquiz_condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Expand Down Expand Up @@ -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 '';
}

/**
Expand Down
15 changes: 11 additions & 4 deletions tests/behat/state_visibility.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -113,30 +114,36 @@ 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"
And I should not see "TF 03"
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"
And I should not see "TF 03"
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"
And I should not see "TF 02"
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"
Expand Down

0 comments on commit 104ea88

Please sign in to comment.