Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StudentQuiz: When a user filters multiple states of questions, it sho… #495

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading