MDL-42492 course: Show option to move category to top level

added behat to test move category
This commit is contained in:
Rajesh Taneja 2013-10-24 09:57:26 +08:00 committed by Marina Glancy
parent df27570b93
commit 3b732cd6cc
6 changed files with 119 additions and 4 deletions

View File

@ -384,7 +384,11 @@ class core_course_management_renderer extends plugin_renderer_base {
);
}
if (coursecat::can_change_parent_any()) {
$options = coursecat::make_categories_list('moodle/category:manage');
$options = array();
if (has_capability('moodle/category:manage', context_system::instance())) {
$options[0] = coursecat::get(0)->get_formatted_name();
}
$options += coursecat::make_categories_list('moodle/category:manage');
$select = html_writer::select(
$options,
'movecategoriesto',

View File

@ -324,12 +324,20 @@ if ($action !== false && confirm_sesskey()) {
$a = new stdClass;
$a->count = $movecount;
$a->to = $movetocat->get_formatted_name();
$notificationspass[] = get_string('movecategoriessuccess', 'moodle', $a);
$movesuccessstrkey = 'movecategoriessuccess';
if ($movetocatid == 0) {
$movesuccessstrkey = 'movecategoriestotopsuccess';
}
$notificationspass[] = get_string($movesuccessstrkey, 'moodle', $a);
} else if ($movecount === 1) {
$a = new stdClass;
$a->moved = $cattomove->get_formatted_name();
$a->to = $movetocat->get_formatted_name();
$notificationspass[] = get_string('movecategorysuccess', 'moodle', $a);
$movesuccessstrkey = 'movecategorysuccess';
if ($movetocatid == 0) {
$movesuccessstrkey = 'movecategorytotopsuccess';
}
$notificationspass[] = get_string($movesuccessstrkey, 'moodle', $a);
}
} else if ($bulkresortcategories) {
// Bulk resort selected categories.

View File

@ -974,6 +974,80 @@ class behat_course extends behat_base {
$node->click();
}
/**
* Clicks on a category checkbox in the management interface.
*
* @Given /^I select category "(?P<name>[^"]*)" in the management interface$/
* @param string $name
*/
public function i_select_category_in_the_management_interface($name) {
$node = $this->get_management_category_listing_node_by_name($name);
$node->checkField('bcat[]');
}
/**
* Clicks course checkbox in the management interface.
*
* @Given /^I select course "(?P<name>[^"]*)" in the management interface$/
* @param string $name
*/
public function i_select_course_in_the_management_interface($name) {
$node = $this->get_management_course_listing_node_by_name($name);
$node->checkField('bc[]');
}
/**
* Move selected categories to top level in the management interface.
*
* @Given /^I move category "(?P<idnumber>[^"]*)" to top level in the management interface$/
* @param string $idnumber
* @return Given[]
*/
public function i_move_category_to_top_level_in_the_management_interface($idnumber) {
$id = $this->get_category_id($idnumber);
$selector = sprintf('.listitem-category[data-id="%d"] > div', $id);
$node = $this->find('css', $selector);
$node->checkField('bcat[]');
return array(
new Given('I select "' . coursecat::get(0)->get_formatted_name() . '" from "menumovecategoriesto"'),
new Given('I press "bulkmovecategories"'),
);
}
/**
* Checks that a category is a subcategory of specific category.
*
* @Given /^I should see category "(?P<subcatidnumber>[^"]*)" as subcategory of "(?P<catidnumber>[^"]*)" in the management interface$/
* @throws ExpectationException
* @param string $subcatidnumber
* @param string $catidnumber
*/
public function i_should_see_category_as_subcategory_of_in_the_management_interface($subcatidnumber, $catidnumber) {
$categorynodeid = $this->get_category_id($catidnumber);
$subcategoryid = $this->get_category_id($subcatidnumber);
$exception = new ExpectationException('The category '.$subcatidnumber.' is not a subcategory of '.$catidnumber, $this->getSession());
$selector = sprintf('#category-listing .listitem-category[data-id="%d"] .listitem-category[data-id="%d"]', $categorynodeid, $subcategoryid);
$this->find('css', $selector, $exception);
}
/**
* Checks that a category is not a subcategory of specific category.
*
* @Given /^I should not see category "(?P<subcatidnumber>[^"]*)" as subcategory of "(?P<catidnumber>[^"]*)" in the management interface$/
* @throws ExpectationException
* @param string $subcatidnumber
* @param string $catidnumber
*/
public function i_should_not_see_category_as_subcategory_of_in_the_management_interface($subcatidnumber, $catidnumber) {
try {
$this->i_should_see_category_as_subcategory_of_in_the_management_interface($subcatidnumber, $catidnumber);
} catch (ExpectationException $e) {
// ExpectedException means that it is not highlighted.
return;
}
throw new ExpectationException('The category '.$subcatidnumber.' is a subcategory of '.$catidnumber, $this->getSession());
}
/**
* Click to expand a category revealing its sub categories within the management UI.
*

View File

@ -5,6 +5,7 @@ Feature: Test category management actions
Test we can create a sub category
Test we can edit a category
Test we can delete a category
Test we can move a category
Test we can assign roles within a category
Test we can set permissions on a category
Test we can manage cohorts within a category
@ -210,3 +211,29 @@ Feature: Test category management actions
And I should see category listing "Cat 1" before "Test category 2"
And I should see "No courses in this category"
@javascript
Scenario: Test moving a categories through the management interface.
Given the following "categories" exists:
| name | category | idnumber |
| Cat 1 | 0 | CAT1 |
| Cat 2 | 0 | CAT2 |
| Cat 3 | 0 | CAT3 |
And I log in as "admin"
And I go to the courses management page
And I should see the "Course categories" management page
And I should see "Cat 1" in the "#category-listing ul.ml" "css_element"
And I should see "Cat 2" in the "#category-listing ul.ml" "css_element"
And I should see "Cat 3" in the "#category-listing ul.ml" "css_element"
And I select category "Cat 2" in the management interface
And I select category "Cat 3" in the management interface
And I select "Cat 1" from "menumovecategoriesto"
When I press "bulkmovecategories"
# Redirect
And I click on category "Cat 1" in the management interface
# Redirect
Then I should see category "CAT3" as subcategory of "CAT1" in the management interface
And I move category "CAT3" to top level in the management interface
# Redirect
And I should not see category "CAT3" as subcategory of "CAT1" in the management interface
Then I should see category "CAT2" as subcategory of "CAT1" in the management interface

View File

@ -1145,6 +1145,8 @@ $string['movecontent'] = 'Move {$a}';
$string['movecategorycontentto'] = 'Move into';
$string['movecategorysuccess'] = 'Successfully moved category \'{$a->moved}\' into category \'{$a->to}\'';
$string['movecategoriessuccess'] = 'Successfully moved {$a->count} categories into category \'{$a->to}\'';
$string['movecategorytotopsuccess'] = 'Successfully moved category \'{$a->moved}\' to top level';
$string['movecategoriestotopsuccess'] = 'Successfully moved {$a->count} categories to top level';
$string['movecategoryto'] = 'Move category to:';
$string['movecontentstoanothercategory'] = 'Move contents to another category';
$string['movecourseto'] = 'Move course to:';

View File

@ -2043,7 +2043,7 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate {
$context = $this->get_context();
return format_string($this->name, true, array('context' => $context) + $options);
} else {
return ''; // TODO 'Top'?.
return get_string('top');
}
}