From af321e0f20c934d9fb912c5f6fb1d2c4e689ddd9 Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Tue, 15 Oct 2013 09:19:03 +1300 Subject: [PATCH] MDL-42294 course: fixed delete script ordering Added a behat test for the creation and deletion of a new course. This should turn up any such errors like this during automated testing in the future. --- course/delete.php | 8 +- .../tests/behat/create_delete_course.feature | 73 +++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 course/tests/behat/create_delete_course.feature diff --git a/course/delete.php b/course/delete.php index 185a05e11c682..2f720f5068539 100644 --- a/course/delete.php +++ b/course/delete.php @@ -50,9 +50,6 @@ if ($delete === md5($course->timemodified)) { // We do - time to delete the course. require_sesskey(); - delete_course($course); - // Update course count in categories. - fix_course_sortorder(); $strdeletingcourse = get_string("deletingcourse", "", $courseshortname); @@ -62,9 +59,14 @@ echo $OUTPUT->header(); echo $OUTPUT->heading($strdeletingcourse); + // We do this here because it spits out feedback as it goes. + delete_course($course); echo $OUTPUT->heading( get_string("deletedcourse", "", $courseshortname) ); + // Update course count in categories. + fix_course_sortorder(); echo $OUTPUT->continue_button($categoryurl); echo $OUTPUT->footer(); + exit; // We must exit here!!! } $strdeletecheck = get_string("deletecheck", "", $courseshortname); diff --git a/course/tests/behat/create_delete_course.feature b/course/tests/behat/create_delete_course.feature new file mode 100644 index 0000000000000..d8e7d4d2b7079 --- /dev/null +++ b/course/tests/behat/create_delete_course.feature @@ -0,0 +1,73 @@ +@core @core_course +Feature: Test we can both create and delete a course. + As a Moodle admin + I need to test I can create a course + I need to test I can delete a course + + Scenario: Create a course + Given the following "categories" exists: + | name | category 0| idnumber | + | Cat 1 | 0 | CAT1 | + + 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 click on category "Cat 1" in the management interface + # Redirect + And I should see the "Course categories and courses" management page + And I should see "Cat 1" in the "#category-listing" "css_element" + And I should see "No courses in this category" in the "#course-listing" "css_element" + And I click on "New course" "link" in the ".course-listing-actions" "css_element" + And I fill the moodle form with: + | Course full name | Test course: create a course | + | Course short name | TCCAC | + | Course ID number | TC3401 | + | Course summary | This course has been created by automated tests. | + And I press "Save changes" + # Redirect + And I go to the courses management page + And I should see the "Course categories" management page + And I click on category "Cat 1" in the management interface + # Redirect + And I should see the "Course categories and courses" management page + And I should see "Cat 1" in the "#category-listing" "css_element" + And I should see "Test course: create a course" in the "#course-listing" "css_element" + + Scenario: Delete a course + Given the following "categories" exists: + | name | category 0| idnumber | + | Cat 1 | 0 | CAT1 | + And the following "courses" exists: + | category | fullname | shortname | idnumber | + | CAT1 | Test course: create a course | TCCAC | TC3401 | + | CAT1 | Test course 2: create another course | TC2CAC | TC3402 | + + 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 click on category "Cat 1" in the management interface + # Redirect + And I should see the "Course categories and courses" management page + And I should see "Cat 1" in the "#category-listing" "css_element" + And I should see "Test course: create a course" in the "#course-listing" "css_element" + And I should see "Test course 2: create another course" in the "#course-listing" "css_element" + And I click on course "Test course: create a course" in the management interface + # Redirect + And I should see the "Course categories and courses" management page with a course selected + And I should see "Cat 1" in the "#category-listing" "css_element" + And I should see "Test course: create a course" in the "#course-listing" "css_element" + And I should see "Test course 2: create another course" in the "#course-listing" "css_element" + And I should see "Test course: create a course" in the "#course-detail" "css_element" + And I click on "Delete" "link" in the ".course-detail-listing-actions" "css_element" + # Redirect + And I should see "Delete TCCAC" + And I should see "Test course: create a course (TCCAC)" + And I press "Continue" + # Redirect + And I should see "Deleting TCCAC" + And I should see "TCCAC has been completely deleted" + And I press "Continue" + # Redirect + And I should see the "Course categories and courses" management page + And I should see "Cat 1" in the "#category-listing" "css_element" + And I should see "Test course 2: create another course" in the "#course-listing" "css_element" \ No newline at end of file