From b421c1cd7037236aeb4fce576401ec1a210fb67a Mon Sep 17 00:00:00 2001 From: Stephen Bourget Date: Tue, 12 Apr 2016 10:44:22 +0800 Subject: [PATCH 1/2] MDL-52642 block_blog_menu: behat test --- .../behat/block_blog_menu_activity.feature | 222 ++++++++++++++++++ 1 file changed, 222 insertions(+) create mode 100644 blocks/blog_menu/tests/behat/block_blog_menu_activity.feature diff --git a/blocks/blog_menu/tests/behat/block_blog_menu_activity.feature b/blocks/blog_menu/tests/behat/block_blog_menu_activity.feature new file mode 100644 index 00000000000..7bfb0635840 --- /dev/null +++ b/blocks/blog_menu/tests/behat/block_blog_menu_activity.feature @@ -0,0 +1,222 @@ +@block @block_blog_menu +Feature: Enable Block blog menu in an activity + In order to enable the blog menu in an activity + As a teacher + I can add blog menu block to a course + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | idnumber | + | teacher1 | Teacher | 1 | teacher1@example.com | T1 | + | student1 | Student | 1 | student1@example.com | S1 | + | student2 | Student | 2 | student2@example.com | S2 | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + | student2 | C1 | student | + And I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I add a "Assignment" to section "1" and I fill the form with: + | Assignment name | Test assignment 1 | + | Description | Offline text | + | assignsubmission_file_enabled | 0 | + And I follow "Test assignment 1" + And I add the "Blog menu" block + And I log out + + Scenario: Students use the blog menu block to post blogs + Given I log in as "student1" + And I follow "Course 1" + And I follow "Test assignment 1" + And I follow "Add a new entry" + When I set the following fields to these values: + | Entry title | S1 First Blog | + | Blog entry body | This is my awesome blog! | + And I press "Save changes" + Then I should see "S1 First Blog" + And I should see "This is my awesome blog!" + And I follow "Dashboard" + And I follow "Course 1" + And I follow "Test assignment 1" + And I follow "Blog entries" + And I should see "S1 First Blog" + And I should see "This is my awesome blog!" + + Scenario: Students use the blog menu block to view their blogs about the activity + Given I log in as "student1" + And I follow "Course 1" + And I follow "Test assignment 1" + And I follow "Add an entry about this Assignment" + And I set the following fields to these values: + | Entry title | S1 First Blog | + | Blog entry body | This is my awesome blog about this Assignment! | + And I press "Save changes" + And I should see "S1 First Blog" + And I should see "This is my awesome blog about this Assignment!" + And I should see "Associated Assignment: Test assignment 1" + And I log out + And I log in as "student2" + And I follow "Course 1" + And I follow "Test assignment 1" + And I follow "Add a new entry" + And I set the following fields to these values: + | Entry title | S2 Second Blog | + | Blog entry body | My unrelated blog! | + And I press "Save changes" + And I should see "S2 Second Blog" + And I should see "My unrelated blog!" + And I should not see "Associated Assignment: Test assignment 1" + And I follow "Dashboard" + And I follow "Course 1" + And I follow "Test assignment 1" + And I follow "Add an entry about this Assignment" + And I set the following fields to these values: + | Entry title | S2 First Blog | + | Blog entry body | My course blog is better! | + And I press "Save changes" + And I should see "S2 First Blog" + And I should see "My course blog is better!" + And I should see "Associated Assignment: Test assignment 1" + And I follow "Dashboard" + And I follow "Course 1" + And I follow "Test assignment 1" + When I follow "View my entries about this Assignment" + Then I should see "S2 First Blog" + And I should not see "S2 Second Blog" + And I should not see "S1 First Blog" + + Scenario: Students use the blog menu block to view all blogs about the assignment + Given I log in as "student1" + And I follow "Course 1" + And I follow "Test assignment 1" + And I follow "Add an entry about this Assignment" + And I set the following fields to these values: + | Entry title | S1 First Blog | + | Blog entry body | This is my awesome blog about this Assignment! | + And I press "Save changes" + And I should see "S1 First Blog" + And I should see "This is my awesome blog about this Assignment!" + And I should see "Associated Assignment: Test assignment 1" + And I log out + And I log in as "student2" + And I follow "Course 1" + And I follow "Test assignment 1" + And I follow "Add a new entry" + And I set the following fields to these values: + | Entry title | S2 Second Blog | + | Blog entry body | My unrelated blog! | + And I press "Save changes" + And I should see "S2 Second Blog" + And I should see "My unrelated blog!" + And I should not see "Associated Assignment: Test assignment 1" + And I follow "Dashboard" + And I follow "Course 1" + And I follow "Test assignment 1" + And I follow "Add an entry about this Assignment" + And I set the following fields to these values: + | Entry title | S2 First Blog | + | Blog entry body | My course blog is better! | + And I press "Save changes" + And I should see "S2 First Blog" + And I should see "My course blog is better!" + And I should see "Associated Assignment: Test assignment 1" + And I follow "Dashboard" + And I follow "Course 1" + And I follow "Test assignment 1" + When I follow "View all entries about this Assignment" + Then I should see "S1 First Blog" + And I should see "S2 First Blog" + And I should not see "S2 Second Blog" + + Scenario: Students use the blog menu block to view all their blog entries + Given I log in as "student1" + And I follow "Course 1" + And I follow "Test assignment 1" + And I follow "Add an entry about this Assignment" + And I set the following fields to these values: + | Entry title | S1 First Blog | + | Blog entry body | This is my awesome blog about this Assignment! | + And I press "Save changes" + And I should see "S1 First Blog" + And I should see "This is my awesome blog about this Assignment!" + And I should see "Associated Assignment: Test assignment 1" + And I log out + And I log in as "student2" + And I follow "Course 1" + And I follow "Test assignment 1" + And I follow "Add a new entry" + And I set the following fields to these values: + | Entry title | S2 Second Blog | + | Blog entry body | My unrelated blog! | + And I press "Save changes" + And I should see "S2 Second Blog" + And I should see "My unrelated blog!" + And I should not see "Associated Assignment: Test assignment 1" + And I follow "Dashboard" + And I follow "Course 1" + And I follow "Test assignment 1" + And I follow "Add an entry about this Assignment" + And I set the following fields to these values: + | Entry title | S2 First Blog | + | Blog entry body | My course blog is better! | + And I press "Save changes" + And I should see "S2 First Blog" + And I should see "My course blog is better!" + And I should see "Associated Assignment: Test assignment 1" + And I follow "Dashboard" + And I follow "Course 1" + And I follow "Test assignment 1" + When I follow "Blog entries" + Then I should see "S2 First Blog" + And I should see "S2 Second Blog" + And I should not see "S1 First Blog" + + Scenario: Teacher searches for student blogs + Given I log in as "student1" + And I follow "Course 1" + And I follow "Test assignment 1" + And I follow "Add an entry about this Assignment" + And I set the following fields to these values: + | Entry title | S1 First Blog | + | Blog entry body | This is my awesome blog about this Assignment! | + And I press "Save changes" + And I should see "S1 First Blog" + And I should see "This is my awesome blog about this Assignment!" + And I should see "Associated Assignment: Test assignment 1" + And I log out + And I log in as "student2" + And I follow "Course 1" + And I follow "Test assignment 1" + And I follow "Add a new entry" + And I set the following fields to these values: + | Entry title | S2 Second Blog | + | Blog entry body | My unrelated blog! | + And I press "Save changes" + And I should see "S2 Second Blog" + And I should see "My unrelated blog!" + And I should not see "Associated Assignment: Test assignment 1" + And I follow "Dashboard" + And I follow "Course 1" + And I follow "Test assignment 1" + And I follow "Add an entry about this Assignment" + And I set the following fields to these values: + | Entry title | S2 First Blog | + | Blog entry body | My course blog is better! | + And I press "Save changes" + And I should see "S2 First Blog" + And I should see "My course blog is better!" + And I should see "Associated Assignment: Test assignment 1" + And I log out + When I log in as "teacher1" + And I follow "Course 1" + And I follow "Test assignment 1" + And I set the field "blogsearchquery" to "First" + And I press "Search" + Then I should see "S1 First Blog" + And I should see "S2 First Blog" + And I should not see "S2 Second Blog" \ No newline at end of file From 4b1de0b64b78bb6e42ca61292eb90643e7e35cf1 Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Tue, 12 Apr 2016 11:53:34 +0800 Subject: [PATCH 2/2] MDL-52642 blog: Fix notices for swapping contexts in activities. --- blog/edit.php | 10 +++++++--- blog/index.php | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/blog/edit.php b/blog/edit.php index 686962d4a9f..27c412fe89e 100644 --- a/blog/edit.php +++ b/blog/edit.php @@ -63,9 +63,13 @@ if ($id) { $sitecontext = context_system::instance(); $usercontext = context_user::instance($userid); -$PAGE->set_context($usercontext); -$blognode = $PAGE->settingsnav->find('blogadd', null); -$blognode->make_active(); +if ($modid) { + $PAGE->set_context($sitecontext); +} else { + $PAGE->set_context($usercontext); + $blognode = $PAGE->settingsnav->find('blogadd', null); + $blognode->make_active(); +} require_login($courseid); diff --git a/blog/index.php b/blog/index.php index 56ab7eb8b91..4d2209bfea0 100644 --- a/blog/index.php +++ b/blog/index.php @@ -63,7 +63,7 @@ if ($entryid and !isset($userid)) { $userid = $entry->userid; } -if (isset($userid) && empty($courseid)) { +if (isset($userid) && empty($courseid) && empty($modid)) { $context = context_user::instance($userid); } else if (!empty($courseid) && $courseid != SITEID) { $context = context_course::instance($courseid);