mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-51636 core_tag: allow setting tags in generators
This commit is contained in:
parent
35d3e8b00b
commit
810805da9e
@ -6,9 +6,9 @@ Feature: Block tags displaying tag cloud
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
| student1 | Student | 1 | student1@example.com |
|
||||
| username | firstname | lastname | email | interests |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com | Dogs, Cats |
|
||||
| student1 | Student | 1 | student1@example.com | |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname |
|
||||
| Course 1 | c1 |
|
||||
@ -19,13 +19,6 @@ Feature: Block tags displaying tag cloud
|
||||
| user | course | role |
|
||||
| teacher1 | c1 | editingteacher |
|
||||
| student1 | c1 | student |
|
||||
And I log in as "teacher1"
|
||||
And I follow "Preferences" in the user menu
|
||||
And I follow "Edit profile"
|
||||
And I expand all fieldsets
|
||||
And I set the field "Enter tags separated by commas" to "Dogs, Cats"
|
||||
And I press "Update profile"
|
||||
And I log out
|
||||
|
||||
Scenario: Add Tags block on a front page
|
||||
When I log in as "admin"
|
||||
|
@ -272,7 +272,17 @@ EOD;
|
||||
context_user::instance($userid);
|
||||
}
|
||||
|
||||
return $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
|
||||
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
|
||||
|
||||
if (!$record['deleted'] && isset($record['interests'])) {
|
||||
require_once($CFG->dirroot . '/user/editlib.php');
|
||||
if (!is_array($record['interests'])) {
|
||||
$record['interests'] = preg_split('/\s*,\s*/', trim($record['interests']), -1, PREG_SPLIT_NO_EMPTY);
|
||||
}
|
||||
useredit_update_interests($user, $record['interests']);
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -405,6 +415,10 @@ EOD;
|
||||
$record['category'] = $DB->get_field_select('course_categories', "MIN(id)", "parent=0");
|
||||
}
|
||||
|
||||
if (isset($record['tags']) && !is_array($record['tags'])) {
|
||||
$record['tags'] = preg_split('/\s*,\s*/', trim($record['tags']), -1, PREG_SPLIT_NO_EMPTY);
|
||||
}
|
||||
|
||||
$course = create_course((object)$record);
|
||||
context_course::instance($course->id);
|
||||
if (!empty($options['createsections'])) {
|
||||
|
@ -55,6 +55,7 @@ class core_test_generator_testcase extends advanced_testcase {
|
||||
|
||||
public function test_create_user() {
|
||||
global $DB, $CFG;
|
||||
require_once($CFG->dirroot.'/user/lib.php');
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
$generator = $this->getDataGenerator();
|
||||
@ -124,6 +125,11 @@ class core_test_generator_testcase extends advanced_testcase {
|
||||
$this->assertSame('', $user->idnumber);
|
||||
$this->assertSame(md5($record['username']), $user->email);
|
||||
$this->assertFalse(context_user::instance($user->id, IGNORE_MISSING));
|
||||
|
||||
// Test generating user with interests.
|
||||
$user = $generator->create_user(array('interests' => 'Cats, Dogs'));
|
||||
$userdetails = user_get_user_details($user);
|
||||
$this->assertSame('Cats, Dogs', $userdetails['interests']);
|
||||
}
|
||||
|
||||
public function test_create() {
|
||||
@ -167,6 +173,9 @@ class core_test_generator_testcase extends advanced_testcase {
|
||||
$section = $generator->create_course_section(array('course'=>$course->id, 'section'=>3));
|
||||
$this->assertEquals($course->id, $section->course);
|
||||
|
||||
$course = $generator->create_course(array('tags' => 'Cat, Dog'));
|
||||
$this->assertEquals('Cat, Dog', tag_get_tags_csv('course', $course->id, TAG_RETURN_TEXT));
|
||||
|
||||
$scale = $generator->create_scale();
|
||||
$this->assertNotEmpty($scale);
|
||||
}
|
||||
|
@ -6,24 +6,15 @@ Feature: Manager is able to delete tags
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| manager1 | Manager | 1 | manager1@example.com |
|
||||
| user1 | User | 1 | user1@example.com |
|
||||
| username | firstname | lastname | email | interests |
|
||||
| manager1 | Manager | 1 | manager1@example.com | |
|
||||
| user1 | User | 1 | user1@example.com | Cat,Dog,Turtle |
|
||||
And the following "system role assigns" exist:
|
||||
| user | course | role |
|
||||
| manager1 | Acceptance test site | manager |
|
||||
And the following "tags" exist:
|
||||
| name | tagtype |
|
||||
| Neverusedtag | official |
|
||||
And I log in as "user1"
|
||||
And I navigate to "Site blogs" node in "Site pages"
|
||||
And I follow "Add a new entry"
|
||||
And I set the following fields to these values:
|
||||
| Entry title | Blog post header |
|
||||
| Blog entry body | Blog post content |
|
||||
| Other tags (enter tags separated by commas) | Cat,Dog,Turtle |
|
||||
And I press "Save changes"
|
||||
And I log out
|
||||
|
||||
Scenario: Deleting a tag with javascript disabled
|
||||
When I log in as "manager1"
|
||||
@ -31,7 +22,8 @@ Feature: Manager is able to delete tags
|
||||
And I click on "Delete" "link" in the "Dog" "table_row"
|
||||
And I should see "Tag(s) deleted"
|
||||
Then I should not see "Dog"
|
||||
And I navigate to "Site blogs" node in "Site pages"
|
||||
And I navigate to "Participants" node in "Site pages"
|
||||
And I follow "User 1"
|
||||
And I should see "Cat"
|
||||
And I should not see "Dog"
|
||||
And I log out
|
||||
@ -46,7 +38,8 @@ Feature: Manager is able to delete tags
|
||||
Then I should see "Tag(s) deleted"
|
||||
And I should not see "Dog"
|
||||
And I should not see "Neverusedtag"
|
||||
And I navigate to "Site blogs" node in "Site pages"
|
||||
And I navigate to "Participants" node in "Site pages"
|
||||
And I follow "User 1"
|
||||
And I should see "Cat"
|
||||
And I should not see "Dog"
|
||||
And I log out
|
||||
@ -67,7 +60,8 @@ Feature: Manager is able to delete tags
|
||||
And I should not see "Dog"
|
||||
And I follow "Manage tags"
|
||||
And I should not see "Dog"
|
||||
And I navigate to "Site blogs" node in "Site pages"
|
||||
And I navigate to "Participants" node in "Site pages"
|
||||
And I follow "User 1"
|
||||
And I should see "Cat"
|
||||
And I should not see "Dog"
|
||||
And I log out
|
||||
@ -99,7 +93,8 @@ Feature: Manager is able to delete tags
|
||||
And I follow "Manage tags"
|
||||
And I should not see "Dog"
|
||||
And I should not see "Neverusedtag"
|
||||
And I navigate to "Site blogs" node in "Site pages"
|
||||
And I navigate to "Participants" node in "Site pages"
|
||||
And I follow "User 1"
|
||||
And I should see "Cat"
|
||||
And I should not see "Dog"
|
||||
And I log out
|
||||
|
@ -6,10 +6,10 @@ Feature: Users can edit tags to add description or rename
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| manager1 | Manager | 1 | manager1@example.com |
|
||||
| user1 | User | 1 | user1@example.com |
|
||||
| editor1 | Editor | 1 | editor1@example.com |
|
||||
| username | firstname | lastname | email | interests |
|
||||
| manager1 | Manager | 1 | manager1@example.com | |
|
||||
| user1 | User | 1 | user1@example.com | Cat,Dog,Turtle |
|
||||
| editor1 | Editor | 1 | editor1@example.com | |
|
||||
Given the following "roles" exist:
|
||||
| name | shortname |
|
||||
| Tag editor | tageditor |
|
||||
@ -20,24 +20,18 @@ Feature: Users can edit tags to add description or rename
|
||||
And the following "tags" exist:
|
||||
| name | tagtype |
|
||||
| Neverusedtag | official |
|
||||
And I log in as "user1"
|
||||
And I navigate to "Site blogs" node in "Site pages"
|
||||
And I follow "Add a new entry"
|
||||
And I set the following fields to these values:
|
||||
| Entry title | Blog post header |
|
||||
| Blog entry body | Blog post content |
|
||||
| Other tags (enter tags separated by commas) | Cat,Dog,Turtle |
|
||||
And I press "Save changes"
|
||||
And I log out
|
||||
|
||||
Scenario: User with tag editing capability can change tag description
|
||||
Given I log in as "admin"
|
||||
And I set the following system permissions of "Tag editor" role:
|
||||
| capability | permission |
|
||||
| moodle/tag:edit | Allow |
|
||||
| capability | permission |
|
||||
| moodle/tag:edit | Allow |
|
||||
| moodle/site:viewparticipants | Allow |
|
||||
| moodle/user:viewdetails | Allow |
|
||||
And I log out
|
||||
When I log in as "editor1"
|
||||
And I navigate to "Site blogs" node in "Site pages"
|
||||
And I navigate to "Participants" node in "Site pages"
|
||||
And I follow "User 1"
|
||||
And I follow "Cat"
|
||||
And I follow "Edit this tag"
|
||||
And I should not see "Tag name"
|
||||
@ -53,7 +47,8 @@ Feature: Users can edit tags to add description or rename
|
||||
|
||||
Scenario: Manager can change tag description, related tags and rename the tag from tag view page
|
||||
When I log in as "manager1"
|
||||
And I navigate to "Site blogs" node in "Site pages"
|
||||
And I navigate to "Participants" node in "Site pages"
|
||||
And I follow "User 1"
|
||||
And I follow "Cat"
|
||||
And I follow "Edit this tag"
|
||||
And I set the following fields to these values:
|
||||
@ -77,7 +72,8 @@ Feature: Users can edit tags to add description or rename
|
||||
|
||||
Scenario: Renaming the tag from tag view page
|
||||
When I log in as "manager1"
|
||||
And I navigate to "Site blogs" node in "Site pages"
|
||||
And I navigate to "Participants" node in "Site pages"
|
||||
And I follow "User 1"
|
||||
And I follow "Cat"
|
||||
And I follow "Edit this tag"
|
||||
And I set the following fields to these values:
|
||||
|
@ -6,40 +6,40 @@ Feature: Users can flag tags and manager can reset flags
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| manager1 | Manager | 1 | manager1@example.com |
|
||||
| user1 | User | 1 | user1@example.com |
|
||||
| user2 | User | 2 | user2@example.com |
|
||||
| user3 | User | 3 | user3@example.com |
|
||||
| username | firstname | lastname | email | interests |
|
||||
| manager1 | Manager | 1 | manager1@example.com | |
|
||||
| user1 | User | 1 | user1@example.com | Nicetag, Badtag, Sweartag |
|
||||
| user2 | User | 2 | user2@example.com | |
|
||||
| user3 | User | 3 | user3@example.com | |
|
||||
And the following "system role assigns" exist:
|
||||
| user | course | role |
|
||||
| manager1 | Acceptance test site | manager |
|
||||
And the following "tags" exist:
|
||||
| name | tagtype |
|
||||
| Neverusedtag | official |
|
||||
And I log in as "user1"
|
||||
And I navigate to "Site blogs" node in "Site pages"
|
||||
And I follow "Add a new entry"
|
||||
And I set the following fields to these values:
|
||||
| Entry title | Blog post from teacher |
|
||||
| Blog entry body | Teacher blog post content |
|
||||
| Other tags (enter tags separated by commas) | Nicetag, Badtag, Sweartag |
|
||||
And I press "Save changes"
|
||||
And I log in as "admin"
|
||||
And I set the following system permissions of "Authenticated user" role:
|
||||
| capability | permission |
|
||||
| moodle/site:viewparticipants | Allow |
|
||||
| moodle/user:viewdetails | Allow |
|
||||
And I log out
|
||||
And I log in as "user2"
|
||||
And I navigate to "Site blogs" node in "Site pages"
|
||||
And I navigate to "Participants" node in "Site pages"
|
||||
And I follow "User 1"
|
||||
And I follow "Badtag"
|
||||
And I follow "Flag as inappropriate"
|
||||
And I should see "The person responsible will be notified"
|
||||
And I follow "Continue"
|
||||
And I navigate to "Site blogs" node in "Site pages"
|
||||
And I navigate to "Participants" node in "Site pages"
|
||||
And I follow "User 1"
|
||||
And I follow "Sweartag"
|
||||
And I follow "Flag as inappropriate"
|
||||
And I should see "The person responsible will be notified"
|
||||
And I follow "Continue"
|
||||
And I log out
|
||||
And I log in as "user3"
|
||||
And I navigate to "Site blogs" node in "Site pages"
|
||||
And I navigate to "Participants" node in "Site pages"
|
||||
And I follow "User 1"
|
||||
And I follow "Sweartag"
|
||||
And I follow "Flag as inappropriate"
|
||||
And I should see "The person responsible will be notified"
|
||||
|
@ -264,6 +264,8 @@ function useredit_update_trackforums($user, $usernew) {
|
||||
* @param array $interests
|
||||
*/
|
||||
function useredit_update_interests($user, $interests) {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/tag/lib.php');
|
||||
tag_set('user', $user->id, $interests, 'core', context_user::instance($user->id)->id);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user