From c10bfee49fd9baa5aa424ef961c8bfa7352238ef Mon Sep 17 00:00:00 2001 From: Neill Magill Date: Mon, 31 Oct 2016 15:43:54 +0000 Subject: [PATCH] MDL-55209 coursecat: Should be able to remove category idnumber test A user should be able to remove an idnumber from a category, also 0 should not be allowed multiple times. --- course/tests/behat/category_management.feature | 17 +++++++++++++++++ lib/tests/coursecatlib_test.php | 15 +++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/course/tests/behat/category_management.feature b/course/tests/behat/category_management.feature index b90a8f8f639..5824254e822 100644 --- a/course/tests/behat/category_management.feature +++ b/course/tests/behat/category_management.feature @@ -348,3 +348,20 @@ Feature: Test category management actions | Category ID number | CAT1 | When I press "Create category" Then I should see "ID number is already used for another category" + + Scenario: Test that is possible to remove an idnumber from a course category + Given the following "categories" exist: + | name | category | idnumber | + | Cat 1 | 0 | CAT1 | + | Cat 2 | 0 || + And I log in as "admin" + And I go to the courses management page + And I should see "CAT1" in the "#category-listing" "css_element" + When I click on "edit" action for "Cat 1" in management category listing + And I set the following fields to these values: + | Category name | Category 1 (edited) | + | Category ID number || + And I press "Save changes" + # Redirect + Then I should see "Category 1 (edited)" in the "#category-listing" "css_element" + And I should not see "CAT1" in the "#course-listing" "css_element" diff --git a/lib/tests/coursecatlib_test.php b/lib/tests/coursecatlib_test.php index b219753d136..10b3cdbfee0 100644 --- a/lib/tests/coursecatlib_test.php +++ b/lib/tests/coursecatlib_test.php @@ -128,6 +128,21 @@ class core_coursecatlib_testcase extends advanced_testcase { } catch (moodle_exception $e) { $this->assertInstanceOf('moodle_exception', $e); } + // Test that duplicates with an idnumber of 0 cannot be created. + coursecat::create(array('name' => 'Cat3', 'idnumber' => '0')); + try { + coursecat::create(array('name' => 'Cat4', 'idnumber' => '0')); + $this->fail('Duplicate idnumber "0" exception expected in coursecat::create'); + } catch (moodle_exception $e) { + $this->assertInstanceOf('moodle_exception', $e); + } + // Test an update cannot make a duplicate idnumber of 0. + try { + $cat2->update(array('idnumber' => '0')); + $this->fail('Duplicate idnumber "0" exception expected in coursecat::update'); + } catch (Exception $e) { + $this->assertInstanceOf('moodle_exception', $e); + } } public function test_visibility() {