diff --git a/admin/tool/behat/tests/behat/data_generators.feature b/admin/tool/behat/tests/behat/data_generators.feature index f2aa63317d0..19bf84211d0 100644 --- a/admin/tool/behat/tests/behat/data_generators.feature +++ b/admin/tool/behat/tests/behat/data_generators.feature @@ -280,7 +280,7 @@ Feature: Set up contextual data for tests | student1 | CHC | When I log in as "admin" And I navigate to "Users > Accounts > Cohorts" in site administration - Then the following should exist in the "cohorts" table: + Then the following should exist in the "reportbuilder-table" table: | Name | Cohort size | | System cohort A | 1 | | System cohort B | 2 | @@ -289,7 +289,7 @@ Feature: Set up contextual data for tests And I follow "Cat 1" And I navigate to "Cohorts" in current page administration And I should not see "System cohort" - And the following should exist in the "cohorts" table: + And the following should exist in the "reportbuilder-table" table: | Name | Cohort size | | Cohort in category | 1 | | Empty cohort | 0 | diff --git a/cohort/classes/reportbuilder/local/entities/cohort.php b/cohort/classes/reportbuilder/local/entities/cohort.php index 462a498f5c4..e7c54b150c3 100644 --- a/cohort/classes/reportbuilder/local/entities/cohort.php +++ b/cohort/classes/reportbuilder/local/entities/cohort.php @@ -296,6 +296,16 @@ class cohort extends base { )) ->add_joins($this->get_joins()); + // Description filter. + $filters[] = (new filter( + text::class, + 'description', + new lang_string('description'), + $this->get_entity_name(), + "{$tablealias}.description" + )) + ->add_joins($this->get_joins()); + return $filters; } } diff --git a/cohort/classes/reportbuilder/local/systemreports/cohorts.php b/cohort/classes/reportbuilder/local/systemreports/cohorts.php new file mode 100644 index 00000000000..785953b2f21 --- /dev/null +++ b/cohort/classes/reportbuilder/local/systemreports/cohorts.php @@ -0,0 +1,267 @@ +. + +namespace core_cohort\reportbuilder\local\systemreports; + +use context; +use context_coursecat; +use context_system; +use core_cohort\reportbuilder\local\entities\cohort; +use core_reportbuilder\local\helpers\database; +use core_reportbuilder\local\report\action; +use core_reportbuilder\local\report\column; +use html_writer; +use lang_string; +use moodle_url; +use pix_icon; +use core_reportbuilder\system_report; +use stdClass; + +/** + * Cohorts system report class implementation + * + * @package core_cohort + * @copyright 2021 David Matamoros + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class cohorts extends system_report { + + /** + * Initialise report, we need to set the main table, load our entities and set columns/filters + */ + protected function initialise(): void { + // Our main entity, it contains all of the column definitions that we need. + $cohortentity = new cohort(); + $entitymainalias = $cohortentity->get_table_alias('cohort'); + + $this->set_main_table('cohort', $entitymainalias); + $this->add_entity($cohortentity); + + // Any columns required by actions should be defined here to ensure they're always available. + $this->add_base_fields("{$entitymainalias}.id, {$entitymainalias}.contextid, {$entitymainalias}.visible"); + + // Check if report needs to show a specific category. + $contextid = $this->get_parameter('contextid', 0, PARAM_INT); + $showall = $this->get_parameter('showall', true, PARAM_BOOL); + if (!$showall) { + $paramcontextid = database::generate_param_name(); + $this->add_base_condition_sql("{$entitymainalias}.contextid = :$paramcontextid", [$paramcontextid => $contextid]); + } + + // Now we can call our helper methods to add the content we want to include in the report. + $this->add_columns($cohortentity); + $this->add_filters(); + $this->add_actions(); + + // Set if report can be downloaded. + $this->set_downloadable(false); + } + + /** + * Validates access to view this report + * + * @return bool + */ + protected function can_view(): bool { + $contextid = $this->get_parameter('contextid', 0, PARAM_INT); + if ($contextid) { + $context = context::instance_by_id($contextid, MUST_EXIST); + } else { + $context = context_system::instance(); + } + + return has_any_capability(['moodle/cohort:manage', 'moodle/cohort:view'], $context); + } + + /** + * Adds the columns we want to display in the report + * + * They are provided by the entities we previously added in the {@see initialise} method, referencing each by their + * unique identifier. If custom columns are needed just for this report, they can be defined here. + * + * @param cohort $cohortentity + */ + public function add_columns(cohort $cohortentity): void { + + $entitymainalias = $cohortentity->get_table_alias('cohort'); + $showall = $this->get_parameter('showall', false, PARAM_BOOL); + + // Category column. An extra callback is appended in order to extend the current column formatting. + if ($showall) { + $this->add_column_from_entity('cohort:context') + ->add_callback(static function(string $value, stdClass $cohort): string { + $context = context::instance_by_id($cohort->contextid); + if ($context instanceof context_coursecat) { + return html_writer::link(new moodle_url('/cohort/index.php', + ['contextid' => $cohort->contextid]), $value); + } + + return $value; + }); + } + + // Name column using the inplace editable component. + $this->add_column(new column( + 'editablename', + new lang_string('name', 'core_cohort'), + $cohortentity->get_entity_name() + )) + ->set_type(column::TYPE_TEXT) + ->set_is_sortable(true) + ->add_fields("{$entitymainalias}.name, {$entitymainalias}.id, {$entitymainalias}.contextid") + ->add_callback(static function(string $name, stdClass $cohort): string { + global $OUTPUT, $PAGE; + $renderer = $PAGE->get_renderer('core'); + + $template = new \core_cohort\output\cohortname($cohort); + return $renderer->render_from_template('core/inplace_editable', $template->export_for_template($OUTPUT)); + }); + + // ID Number column using the inplace editable component. + $this->add_column(new column( + 'editableidnumber', + new lang_string('idnumber', 'core_cohort'), + $cohortentity->get_entity_name() + )) + ->set_type(column::TYPE_TEXT) + ->set_is_sortable(true) + ->add_fields("{$entitymainalias}.idnumber, {$entitymainalias}.id, {$entitymainalias}.contextid") + ->add_callback(static function(string $idnumber, stdClass $cohort): string { + global $OUTPUT, $PAGE; + $renderer = $PAGE->get_renderer('core'); + + $template = new \core_cohort\output\cohortidnumber($cohort); + return $renderer->render_from_template('core/inplace_editable', $template->export_for_template($OUTPUT)); + }); + + // Description column. + $this->add_column_from_entity('cohort:description'); + + // Cohort size column using a custom SQL query to count cohort members. + $cm = database::generate_param_name(); + $sql = "(SELECT count($cm.id) as memberscount + FROM {cohort_members} $cm + WHERE $cm.cohortid = {$entitymainalias}.id)"; + $this->add_column(new column( + 'memberscount', + new lang_string('memberscount', 'cohort'), + $cohortentity->get_entity_name() + )) + ->set_type(column::TYPE_INTEGER) + ->set_is_sortable(true) + ->add_field($sql, 'memberscount'); + + // Component column. Override the display name of a column. + $this->add_column_from_entity('cohort:component') + ->set_title(new lang_string('source', 'core_plugin')); + + // It's possible to set a default initial sort direction for one column. + $this->set_initial_sort_column('cohort:editablename', SORT_ASC); + } + + /** + * Adds the filters we want to display in the report + * + * They are all provided by the entities we previously added in the {@see initialise} method, referencing each by their + * unique identifier + */ + protected function add_filters(): void { + $filters = [ + 'cohort:name', + 'cohort:idnumber', + 'cohort:description', + ]; + $this->add_filters_from_entities($filters); + } + + /** + * Add the system report actions. An extra column will be appended to each row, containing all actions added here + * + * Note the use of ":id" placeholder which will be substituted according to actual values in the row + */ + protected function add_actions(): void { + + $contextid = $this->get_parameter('contextid', 0, PARAM_INT); + $showall = $this->get_parameter('showall', true, PARAM_BOOL); + $returnurl = (new moodle_url('/cohort/index.php', + ['id' => ':id', 'contextid' => $contextid, 'showall' => $showall]))->out(false); + + // Hide action. It will be only shown if the property 'visible' is true and user has 'moodle/cohort:manage' capabillity. + $this->add_action((new action( + new moodle_url('/cohort/edit.php', ['id' => ':id', 'sesskey' => sesskey(), 'hide' => 1, 'returnurl' => $returnurl]), + new pix_icon('t/show', '', 'core'), + [], + false, + new lang_string('hide') + ))->add_callback(function($row) { + return $row->visible && has_capability('moodle/cohort:manage', context::instance_by_id($row->contextid)); + })); + + // Show action. It will be only shown if the property 'visible' is false and user has 'moodle/cohort:manage' capabillity. + $this->add_action((new action( + new moodle_url('/cohort/edit.php', ['id' => ':id', 'sesskey' => sesskey(), 'show' => 1, 'returnurl' => $returnurl]), + new pix_icon('t/hide', '', 'core'), + [], + false, + new lang_string('show') + ))->add_callback(function($row) { + return !$row->visible && has_capability('moodle/cohort:manage', context::instance_by_id($row->contextid)); + })); + + // Edit action. It will be only shown if user has 'moodle/cohort:manage' capabillity. + $this->add_action((new action( + new moodle_url('/cohort/edit.php', ['id' => ':id', 'returnurl' => $returnurl]), + new pix_icon('t/edit', '', 'core'), + [], + false, + new lang_string('edit') + ))->add_callback(function($row) { + return has_capability('moodle/cohort:manage', context::instance_by_id($row->contextid)); + })); + + // Delete action. It will be only shown if user has 'moodle/cohort:manage' capabillity. + $this->add_action((new action( + new moodle_url('/cohort/edit.php', ['id' => ':id', 'delete' => 1, 'returnurl' => $returnurl]), + new pix_icon('t/delete', '', 'core'), + [], + false, + new lang_string('delete') + ))->add_callback(function($row) { + return has_capability('moodle/cohort:manage', context::instance_by_id($row->contextid)); + })); + + // Assign members to cohort action. It will be only shown if user has 'moodle/cohort:assign' capabillity. + $this->add_action((new action( + new moodle_url('/cohort/assign.php', ['id' => ':id', 'returnurl' => $returnurl]), + new pix_icon('i/users', '', 'core'), + [], + false, + new lang_string('assign', 'core_cohort') + ))->add_callback(function($row) { + return has_capability('moodle/cohort:assign', context::instance_by_id($row->contextid)); + })); + } + + /** + * CSS class for the row + * + * @param stdClass $row + * @return string + */ + public function get_row_class(stdClass $row): string { + return (!$row->visible) ? 'text-muted' : ''; + } +} diff --git a/cohort/index.php b/cohort/index.php index 6b7746a69dc..9b40c5db09c 100644 --- a/cohort/index.php +++ b/cohort/index.php @@ -22,12 +22,15 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +use core_cohort\reportbuilder\local\systemreports\cohorts; +use core_reportbuilder\local\filters\text; +use core_reportbuilder\system_report_factory; + require('../config.php'); require_once($CFG->dirroot.'/cohort/lib.php'); require_once($CFG->libdir.'/adminlib.php'); $contextid = optional_param('contextid', 0, PARAM_INT); -$page = optional_param('page', 0, PARAM_INT); $searchquery = optional_param('search', '', PARAM_RAW); $showall = optional_param('showall', false, PARAM_BOOL); @@ -77,30 +80,15 @@ if ($category) { $PAGE->set_title($strallcohorts); $PAGE->navbar->add($strallcohorts, $PAGE->url); } else { - $PAGE->set_title(get_string('systemcohorts', 'cohort')); + $strsystemcohorts = get_string('systemcohorts', 'cohort'); + $PAGE->set_title($strsystemcohorts); } } echo $OUTPUT->header(); +echo $OUTPUT->heading($strallcohorts ?? $strsystemcohorts ?? $strcohorts); -if ($showall) { - $cohorts = cohort_get_all_cohorts($page, 25, $searchquery); -} else { - $cohorts = cohort_get_cohorts($context->id, $page, 25, $searchquery); -} - -$count = ''; -if ($cohorts['allcohorts'] > 0) { - if ($searchquery === '') { - $count = ' ('.$cohorts['allcohorts'].')'; - } else { - $count = ' ('.$cohorts['totalcohorts'].'/'.$cohorts['allcohorts'].')'; - } -} - -echo $OUTPUT->heading(get_string('cohortsin', 'cohort', $context->get_context_name()).$count); - -$params = array('page' => $page); +$params = []; if ($contextid) { $params['contextid'] = $contextid; } @@ -116,114 +104,16 @@ if ($editcontrols = cohort_edit_controls($context, $baseurl)) { echo $OUTPUT->render($editcontrols); } -// Add search form. -$hiddenfields = [ - (object) ['name' => 'contextid', 'value' => $contextid], - (object) ['name' => 'showall', 'value' => $showall] -]; +$reportparams = ['contextid' => $context->id, 'showall' => $showall]; +$report = system_report_factory::create(cohorts::class, $context, '', '', 0, $reportparams); -$data = [ - 'action' => new moodle_url('/cohort/index.php'), - 'inputname' => 'search', - 'searchstring' => get_string('search', 'cohort'), - 'query' => $searchquery, - 'hiddenfields' => $hiddenfields, - 'extraclasses' => 'mb-3' -]; - -echo $OUTPUT->render_from_template('core/search_input', $data); - -// Output pagination bar. -echo $OUTPUT->paging_bar($cohorts['totalcohorts'], $page, 25, $baseurl); - -$data = array(); -$editcolumnisempty = true; -foreach($cohorts['cohorts'] as $cohort) { - $line = array(); - $cohortcontext = context::instance_by_id($cohort->contextid); - $cohort->description = file_rewrite_pluginfile_urls($cohort->description, 'pluginfile.php', $cohortcontext->id, - 'cohort', 'description', $cohort->id); - if ($showall) { - if ($cohortcontext->contextlevel == CONTEXT_COURSECAT) { - $line[] = html_writer::link(new moodle_url('/cohort/index.php' , - array('contextid' => $cohort->contextid)), $cohortcontext->get_context_name(false)); - } else { - $line[] = $cohortcontext->get_context_name(false); - } - } - $tmpl = new \core_cohort\output\cohortname($cohort); - $line[] = $OUTPUT->render_from_template('core/inplace_editable', $tmpl->export_for_template($OUTPUT)); - $tmpl = new \core_cohort\output\cohortidnumber($cohort); - $line[] = $OUTPUT->render_from_template('core/inplace_editable', $tmpl->export_for_template($OUTPUT)); - $line[] = format_text($cohort->description, $cohort->descriptionformat); - - $line[] = $DB->count_records('cohort_members', array('cohortid'=>$cohort->id)); - - if (empty($cohort->component)) { - $line[] = get_string('nocomponent', 'cohort'); - } else { - $line[] = get_string('pluginname', $cohort->component); - } - - $buttons = array(); - if (empty($cohort->component)) { - $cohortmanager = has_capability('moodle/cohort:manage', $cohortcontext); - $cohortcanassign = has_capability('moodle/cohort:assign', $cohortcontext); - - $urlparams = array('id' => $cohort->id, 'returnurl' => $baseurl->out_as_local_url(false)); - $showhideurl = new moodle_url('/cohort/edit.php', $urlparams + array('sesskey' => sesskey())); - if ($cohortmanager) { - if ($cohort->visible) { - $showhideurl->param('hide', 1); - $visibleimg = $OUTPUT->pix_icon('t/hide', get_string('hide')); - $buttons[] = html_writer::link($showhideurl, $visibleimg, array('title' => get_string('hide'))); - } else { - $showhideurl->param('show', 1); - $visibleimg = $OUTPUT->pix_icon('t/show', get_string('show')); - $buttons[] = html_writer::link($showhideurl, $visibleimg, array('title' => get_string('show'))); - } - $buttons[] = html_writer::link(new moodle_url('/cohort/edit.php', $urlparams + array('delete' => 1)), - $OUTPUT->pix_icon('t/delete', get_string('delete')), - array('title' => get_string('delete'))); - $buttons[] = html_writer::link(new moodle_url('/cohort/edit.php', $urlparams), - $OUTPUT->pix_icon('t/edit', get_string('edit')), - array('title' => get_string('edit'))); - $editcolumnisempty = false; - } - if ($cohortcanassign) { - $buttons[] = html_writer::link(new moodle_url('/cohort/assign.php', $urlparams), - $OUTPUT->pix_icon('i/users', get_string('assign', 'core_cohort')), - array('title' => get_string('assign', 'core_cohort'))); - $editcolumnisempty = false; - } - } - $line[] = implode(' ', $buttons); - - $data[] = $row = new html_table_row($line); - if (!$cohort->visible) { - $row->attributes['class'] = 'dimmed_text'; - } +// Check if it needs to search by name. +if (!empty($searchquery)) { + $report->set_filter_values([ + 'cohort:name_operator' => text::CONTAINS, + 'cohort:name_value' => $searchquery, + ]); } -$table = new html_table(); -$table->head = array(get_string('name', 'cohort'), get_string('idnumber', 'cohort'), get_string('description', 'cohort'), - get_string('memberscount', 'cohort'), get_string('component', 'cohort')); -$table->colclasses = array('leftalign name', 'leftalign id', 'leftalign description', 'leftalign size','centeralign source'); -if ($showall) { - array_unshift($table->head, get_string('category')); - array_unshift($table->colclasses, 'leftalign category'); -} -if (!$editcolumnisempty) { - $table->head[] = get_string('edit'); - $table->colclasses[] = 'centeralign action'; -} else { - // Remove last column from $data. - foreach ($data as $row) { - array_pop($row->cells); - } -} -$table->id = 'cohorts'; -$table->attributes['class'] = 'admintable generaltable'; -$table->data = $data; -echo html_writer::table($table); -echo $OUTPUT->paging_bar($cohorts['totalcohorts'], $page, 25, $baseurl); + +echo $report->output(); echo $OUTPUT->footer(); diff --git a/cohort/tests/behat/add_cohort.feature b/cohort/tests/behat/add_cohort.feature index 7ba866d8588..b20e2417a73 100644 --- a/cohort/tests/behat/add_cohort.feature +++ b/cohort/tests/behat/add_cohort.feature @@ -42,8 +42,10 @@ Feature: Add cohorts of users Scenario: Add users to a cohort selecting them from the system users list When I add "First User (first@example.com)" user to "333" cohort members And I add "Second User (second@example.com)" user to "333" cohort members - Then I should see "2" in the "#cohorts" "css_element" - And I click on "Assign" "link" in the "Test cohort name" "table_row" + Then the following should exist in the "reportbuilder-table" table: + | Name | Cohort size | + | Test cohort name | 2 | + And I press "Assign" action in the "Test cohort name" report row And the "Current users" select box should contain "First User (first@example.com)" And the "Current users" select box should contain "Second User (second@example.com)" And the "Current users" select box should not contain "Forth User (forth@example.com)" @@ -52,7 +54,7 @@ Feature: Add cohorts of users Scenario: Add user to cohort using custom user field search Given the following config values are set as admin: | showuseridentity | email,profile_field_fruit | - When I click on "Assign" "link" in the "Test cohort name" "table_row" + When I press "Assign" action in the "Test cohort name" report row And I set the field "addselect_searchtext" to "Apple" And I wait "1" seconds Then the "Potential users" select box should contain "First User (first@example.com\, Apple)" @@ -70,7 +72,7 @@ Feature: Add cohorts of users | cohort | user | | 333 | user1 | | 333 | user2 | - When I click on "Assign" "link" in the "Test cohort name" "table_row" + When I press "Assign" action in the "Test cohort name" report row And I set the field "removeselect_searchtext" to "Apple" And I wait "1" seconds Then the "Current users" select box should not contain "Second User (second@example.com\, Banana)" @@ -90,8 +92,10 @@ Feature: Add cohorts of users And I set the field "Cohort" to "Test cohort name [333]" And I press "Add to cohort" And I navigate to "Users > Accounts > Cohorts" in site administration - Then I should see "2" in the "#cohorts" "css_element" - And I click on "Assign" "link" in the "Test cohort name" "table_row" + Then the following should exist in the "reportbuilder-table" table: + | Name | Cohort size | + | Test cohort name | 2 | + And I press "Assign" action in the "Test cohort name" report row And the "Current users" select box should contain "Third User (third@example.com)" And the "Current users" select box should contain "Forth User (forth@example.com)" And the "Current users" select box should not contain "First User (first@example.com)" diff --git a/cohort/tests/behat/behat_cohort.php b/cohort/tests/behat/behat_cohort.php index 1c375db32cf..4df3ab5fbfa 100644 --- a/cohort/tests/behat/behat_cohort.php +++ b/cohort/tests/behat/behat_cohort.php @@ -47,8 +47,8 @@ class behat_cohort extends behat_base { public function i_add_user_to_cohort_members($user, $cohortidnumber) { // If we are not in the cohorts management we should move there before anything else. - if (!$this->getSession()->getPage()->find('css', 'input#cohort_search_q')) { - + $cohortsurl = new moodle_url('/cohort/index.php'); + if (strpos($this->getSession()->getCurrentUrl(), $cohortsurl->out(false)) !== 0) { // With JS enabled we should expand a few tree nodes. $parentnodes = get_string('users', 'admin') . ' > ' . get_string('accounts', 'admin'); @@ -59,9 +59,8 @@ class behat_cohort extends behat_base { ); } - $this->execute('behat_general::i_click_on_in_the', - array(get_string('assign', 'cohort'), "link", $this->escape($cohortidnumber), "table_row") - ); + $this->execute('behat_reportbuilder::i_press_action_in_the_report_row', + [get_string('assign', 'cohort'), $this->escape($cohortidnumber)]); $this->execute("behat_forms::i_set_the_field_to", array(get_string('potusers', 'cohort'), $this->escape($user)) diff --git a/cohort/tests/behat/upload_cohort_users.feature b/cohort/tests/behat/upload_cohort_users.feature index 3d60ddfa876..a41f344d7fc 100644 --- a/cohort/tests/behat/upload_cohort_users.feature +++ b/cohort/tests/behat/upload_cohort_users.feature @@ -27,11 +27,11 @@ Feature: Upload users to a cohort And I press "Upload users" And I press "Continue" And I navigate to "Users > Accounts > Cohorts" in site administration - And I click on "Assign" "link" in the "Cohort 1" "table_row" + And I press "Assign" action in the "Cohort 1" report row Then the "Current users" select box should contain "Tom Jones (tomjones@example.com)" And the "Current users" select box should contain "Bob Jones (bobjones@example.com)" And I press "Back to cohorts" - And I click on "Assign" "link" in the "Cohort 2" "table_row" + And I press "Assign" action in the "Cohort 2" report row And the "Current users" select box should contain "Mary Smith (marysmith@example.com)" And the "Current users" select box should contain "Alice Smith (alicesmith@example.com)" And I am on the "Course 1" "enrolled users" page diff --git a/cohort/tests/behat/upload_cohorts.feature b/cohort/tests/behat/upload_cohorts.feature index 4143f5c61d4..1ef2899327f 100644 --- a/cohort/tests/behat/upload_cohorts.feature +++ b/cohort/tests/behat/upload_cohorts.feature @@ -29,12 +29,12 @@ Feature: A privileged user can create cohorts using a CSV file And I press "Upload cohorts" And I should see "Uploaded 6 cohorts" And I press "Continue" - And the following should exist in the "cohorts" table: + And the following should exist in the "reportbuilder-table" table: | Name | Cohort ID | Description | Cohort size | Source | | cohort name 1 | cohortid1 | first description | 0 | Created manually | | cohort name 2 | cohortid2 | | 0 | Created manually | And I follow "All cohorts" - And the following should exist in the "cohorts" table: + And the following should exist in the "reportbuilder-table" table: | Category | Name | Cohort ID | Description | Cohort size | Source | | System | cohort name 1 | cohortid1 | first description | 0 | Created manually | | System | cohort name 2 | cohortid2 | | 0 | Created manually | @@ -42,13 +42,13 @@ Feature: A privileged user can create cohorts using a CSV file | Cat 1 | cohort name 4 | cohortid4 | | 0 | Created manually | | Cat 2 | cohort name 5 | cohortid5 | | 0 | Created manually | | Cat 3 | cohort name 6 | cohortid6 | | 0 | Created manually | - And ".dimmed_text" "css_element" should not exist in the "cohort name 1" "table_row" - And ".dimmed_text" "css_element" should not exist in the "cohort name 2" "table_row" - And ".dimmed_text" "css_element" should exist in the "cohort name 3" "table_row" - And the "class" attribute of "cohort name 3" "table_row" should contain "dimmed_text" - And ".dimmed_text" "css_element" should not exist in the "cohort name 4" "table_row" - And the "class" attribute of "cohort name 5" "table_row" should contain "dimmed_text" - And ".dimmed_text" "css_element" should not exist in the "cohort name 6" "table_row" + And ".text-muted" "css_element" should not exist in the "cohort name 1" "table_row" + And ".text-muted" "css_element" should not exist in the "cohort name 2" "table_row" + And ".text-muted" "css_element" should exist in the "cohort name 3" "table_row" + And the "class" attribute of "cohort name 3" "table_row" should contain "text-muted" + And ".text-muted" "css_element" should not exist in the "cohort name 4" "table_row" + And the "class" attribute of "cohort name 5" "table_row" should contain "text-muted" + And ".text-muted" "css_element" should not exist in the "cohort name 6" "table_row" @javascript @_file_upload Scenario: Upload cohorts with default category context as admin @@ -69,10 +69,10 @@ Feature: A privileged user can create cohorts using a CSV file And I press "Upload cohorts" And I should see "Uploaded 6 cohorts" And I press "Continue" - And I should see "Category: Cat 3: available cohorts (3)" + And I should see "Cat 3" And I navigate to "Users > Accounts >Cohorts" in site administration And I follow "All cohorts" - And the following should exist in the "cohorts" table: + And the following should exist in the "reportbuilder-table" table: | Category | Name | Cohort ID | Description | Cohort size | Source | | Cat 3 | cohort name 1 | cohortid1 | first description | 0 | Created manually | | Cat 3 | cohort name 2 | cohortid2 | | 0 | Created manually | @@ -180,12 +180,12 @@ Feature: A privileged user can create cohorts using a CSV file And I press "Upload cohorts" And I should see "Uploaded 6 cohorts" And I press "Continue" - And the following should exist in the "cohorts" table: + And the following should exist in the "reportbuilder-table" table: | Name | Cohort ID | Description | Cohort size | Source | | cohort name 1 | cohortid1 | first description | 0 | Created manually | | cohort name 2 | cohortid2 | | 0 | Created manually | And I follow "All cohorts" - And the following should exist in the "cohorts" table: + And the following should exist in the "reportbuilder-table" table: | Category | Name | Cohort ID | Description | Cohort size | Source | | System | cohort name 1 | cohortid1 | first description | 0 | Created manually | | System | cohort name 2 | cohortid2 | | 0 | Created manually | diff --git a/cohort/tests/behat/view_cohorts.feature b/cohort/tests/behat/view_cohorts.feature index b901cc23cf5..e18bf968ca1 100644 --- a/cohort/tests/behat/view_cohorts.feature +++ b/cohort/tests/behat/view_cohorts.feature @@ -62,3 +62,22 @@ Feature: View cohort list And I should not see "Cohort in category 2" And I should not see "Cohort in category 3" And I log out + + @javascript + Scenario: Cohorts list can be filtered + When I log in as "admin" + And I navigate to "Users > Accounts > Cohorts" in site administration + And I follow "All cohorts" + And I click on "Filters" "button" + And I set the following fields in the "Name" "core_reportbuilder > Filter" to these values: + | Name operator | Contains | + | Name value | category 1 | + And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element" + Then the following should exist in the "reportbuilder-table" table: + | Category | Name | + | Cat 1 | Cohort in category 1 | + And the following should not exist in the "reportbuilder-table" table: + | Category | Name | + | Cat 2 | Cohort in category 2 | + | Cat 3 | Cohort in category 3 | + | System | System cohort | diff --git a/course/tests/behat/category_management.feature b/course/tests/behat/category_management.feature index 309cd5babdc..ee8845ba1a4 100644 --- a/course/tests/behat/category_management.feature +++ b/course/tests/behat/category_management.feature @@ -282,7 +282,7 @@ Feature: Test category management actions And I should see the "Course categories and courses" management page And I click on "cohorts" action for "Cat 1" in management category listing # Redirect - And I should see "Category: Cat 1: available cohorts" + And I should see "Cohorts" Scenario: Test configuring filters for a category Given the following "categories" exist: diff --git a/course/tests/behat/course_category_breadcrumbs.feature b/course/tests/behat/course_category_breadcrumbs.feature index fb27467ca0d..0dcea9c90da 100644 --- a/course/tests/behat/course_category_breadcrumbs.feature +++ b/course/tests/behat/course_category_breadcrumbs.feature @@ -164,7 +164,7 @@ Feature: Course category breadcrumbs navigation And I should see "Cat 1" in the ".breadcrumb" "css_element" And I should see "Cohorts" in the ".breadcrumb" "css_element" And I should see "Cat 1" in the ".page-context-header" "css_element" - And I should see "Category: Cat 1: available cohorts" in the "region-main" "region" + And I should see "Cohorts" in the "region-main" "region" And I should see "Cat 1" in the ".block_navigation .active_tree_node" "css_element" Scenario: Admin user navigates to category 'add new cohort' page diff --git a/enrol/cohort/tests/behat/unenrolactionsuspendonly.feature b/enrol/cohort/tests/behat/unenrolactionsuspendonly.feature index aab2806987a..45e06e0c55e 100644 --- a/enrol/cohort/tests/behat/unenrolactionsuspendonly.feature +++ b/enrol/cohort/tests/behat/unenrolactionsuspendonly.feature @@ -45,7 +45,7 @@ Feature: Unenrol action to disable course enrolment And I select "Disable course enrolment" from the "External unenrol action" singleselect And I press "Save changes" And I navigate to "Users > Accounts > Cohorts" in site administration - When I click on "Assign" "link" in the "System cohort" "table_row" + When I press "Assign" action in the "System cohort" report row And I set the field "removeselect_searchtext" to "Student 001" And I set the field "Current users" to "Student 001 (student001@example.com)" And I wait "1" seconds @@ -77,7 +77,7 @@ Feature: Unenrol action to disable course enrolment And I select "Disable course enrolment" from the "External unenrol action" singleselect And I press "Save changes" And I navigate to "Users > Accounts > Cohorts" in site administration - When I click on "Delete" "link" in the "System cohort" "table_row" + When I press "Delete" action in the "System cohort" report row And I press "Continue" And I am on "Course 001" course homepage And I navigate to course participants diff --git a/user/tests/behat/bulk_editenrolment.feature b/user/tests/behat/bulk_editenrolment.feature index 7786fff4299..a81510a8fb4 100644 --- a/user/tests/behat/bulk_editenrolment.feature +++ b/user/tests/behat/bulk_editenrolment.feature @@ -68,6 +68,6 @@ Feature: Bulk enrolments And I set the field "id_cohort" to "Cohort [cohortid1]" And I press "Add to cohort" And I navigate to "Users > Accounts > Cohorts" in site administration - And I click on "Assign" "link" + And I press "Assign" action in the "cohortid1" report row Then the "removeselect" select box should contain "Student 2 (student2@example.com)" And the "removeselect" select box should not contain "Student 1 (student1@example.com)"