From 9a7e39866460842f9f8247af5b72f2e505495f08 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Sat, 18 Jul 2015 22:43:48 +0800 Subject: [PATCH] MDL-50874 block: basic tests for tag-related blocks --- blocks/blog_tags/tests/behat/blogtag.feature | 51 ++++++++++++++++ blocks/tags/tests/behat/coursetags.feature | 64 ++++++++++++++++++++ blocks/tags/tests/behat/tagcloud.feature | 59 ++++++++++++++++++ lib/testing/generator/data_generator.php | 15 +++-- lib/tests/behat/behat_data_generators.php | 4 ++ 5 files changed, 189 insertions(+), 4 deletions(-) create mode 100644 blocks/blog_tags/tests/behat/blogtag.feature create mode 100644 blocks/tags/tests/behat/coursetags.feature create mode 100644 blocks/tags/tests/behat/tagcloud.feature diff --git a/blocks/blog_tags/tests/behat/blogtag.feature b/blocks/blog_tags/tests/behat/blogtag.feature new file mode 100644 index 0000000000000..88bf5b97aa5a8 --- /dev/null +++ b/blocks/blog_tags/tests/behat/blogtag.feature @@ -0,0 +1,51 @@ +@block @block_blog_tag @core_blog @core_tag +Feature: Adding blog tag block + In order to search blog post by tag + As a user + I need to be able to use block blog tag + + Scenario: Adding block blog tag to the course + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + | student1 | Student | 1 | student1@example.com | + And the following "courses" exist: + | fullname | shortname | + | Course 1 | c1 | + And the following "tags" exist: + | name | tagtype | + | Neverusedtag | official | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | c1 | editingteacher | + | student1 | c1 | student | + When I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I add the "Blog tags" block + + And I navigate to "Course blogs" node in "Current course > c1 > Participants" + And I follow "Blog about this Course" + 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) | Cats, dogs | + And I press "Save changes" + And I log out + And I log in as "student1" + And I follow "Course 1" + And I navigate to "Course blogs" node in "Current course > c1 > Participants" + And I follow "Blog about this Course" + And I set the following fields to these values: + | Entry title | Blog post from student | + | Blog entry body | Student blog post content | + | Other tags (enter tags separated by commas) | DOGS, mice | + And I press "Save changes" + And I follow "c1" + Then I should see "Cats" in the "Blog tags" "block" + And I should see "dogs" in the "Blog tags" "block" + And I should see "mice" in the "Blog tags" "block" + And I click on "Cats" "link" in the "Blog tags" "block" + And I should see "Blog post from teacher" + And I should see "Teacher blog post content" + And I log out diff --git a/blocks/tags/tests/behat/coursetags.feature b/blocks/tags/tests/behat/coursetags.feature new file mode 100644 index 0000000000000..c5f9c552166c3 --- /dev/null +++ b/blocks/tags/tests/behat/coursetags.feature @@ -0,0 +1,64 @@ +@block @block_tags @core_tag +Feature: Block tags displaying course tags + In order to tag courses + As a user + I need to be able to use the block tags + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + | student1 | Student | 1 | student1@example.com | + | student2 | Student | 2 | student2@example.com | + And the following "courses" exist: + | fullname | shortname | + | Course 1 | c1 | + And the following "tags" exist: + | name | tagtype | + | Neverusedtag | official | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | c1 | editingteacher | + | student1 | c1 | student | + | student2 | c1 | student | + And I log in as "admin" + And I set the following administration settings values: + | Show course tags | 1 | + And I log out + + Scenario: Add Tags block to tag courses in a course + When I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I add the "Tags" block + And I log out + And I log in as "student1" + And I follow "Course 1" + And I should not see "Neverusedtag" in the "Tags" "block" + And I click on "more..." "link" in the "Tags" "block" + And I should not see "Neverusedtag" + And I follow "c1" + And I set the field "coursetag_new_tag" to "Dogs, Mice" + And I press "Add" + And I should see "Dogs" in the "Tags" "block" + And I should see "Mice" in the "Tags" "block" + And I log out + And I log in as "student2" + And I follow "Course 1" + And I should see "Dogs" in the "Tags" "block" + And I set the field "coursetag_new_tag" to "Cats, Dogs" + And I press "Add" + And I should see "Dogs" in the "Tags" "block" + And I should see "Cats" in the "Tags" "block" + And I click on "more..." "link" in the "Tags" "block" + And "Cats" "link" should appear before "Dogs" "link" + And "Dogs" "link" should appear before "Mice" "link" + And I follow "My tags" + And I should see "Dogs" + And I should see "Cats" + And I should not see "Mice" + And I follow "All tags" + And I follow "Popularity" + And "Mice" "link" should appear before "Dogs" "link" + And I should not see "Neverusedtag" + And I log out diff --git a/blocks/tags/tests/behat/tagcloud.feature b/blocks/tags/tests/behat/tagcloud.feature new file mode 100644 index 0000000000000..0265fe9f5c13f --- /dev/null +++ b/blocks/tags/tests/behat/tagcloud.feature @@ -0,0 +1,59 @@ +@block @block_tags @core_tag +Feature: Block tags displaying tag cloud + In order to view system tags + As a user + I need to be able to use the block tags + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + | student1 | Student | 1 | student1@example.com | + And the following "courses" exist: + | fullname | shortname | + | Course 1 | c1 | + And the following "tags" exist: + | name | tagtype | + | Neverusedtag | official | + And the following "course enrolments" exist: + | 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 + + @javascript + Scenario: Add Tags block on a front page + When I log in as "admin" + And I am on site homepage + And I follow "Turn editing on" + And I add the "Tags" block + And I log out + And I am on site homepage + Then I should see "Dogs" in the "Tags" "block" + And I should see "Cats" in the "Tags" "block" + And I should not see "Neverusedtag" in the "Tags" "block" + And I click on "Dogs" "link" in the "Tags" "block" + And I should see "Log in to the site" in the ".breadcrumb" "css_element" + + @javascript + Scenario: Add Tags block in a course + When I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I add the "Tags" block + And I log out + And I log in as "student1" + And I follow "Course 1" + Then I should see "Dogs" in the "Tags" "block" + And I should see "Cats" in the "Tags" "block" + And I should not see "Neverusedtag" in the "Tags" "block" + And I click on "Dogs" "link" in the "Tags" "block" + And I should see "Users tagged with \"Dogs\": 1" + And I should see "Teacher 1" + And I log out diff --git a/lib/testing/generator/data_generator.php b/lib/testing/generator/data_generator.php index f12f6164017cd..44ccaba9d8c5b 100644 --- a/lib/testing/generator/data_generator.php +++ b/lib/testing/generator/data_generator.php @@ -792,12 +792,19 @@ public function create_tag($record = null) { $record['userid'] = $USER->id; } - if (!isset($record['name'])) { - $record['name'] = 'Tag name ' . $i; + if (!isset($record['rawname'])) { + if (isset($record['name'])) { + $record['rawname'] = $record['name']; + } else { + $record['rawname'] = 'Tag name ' . $i; + } } - if (!isset($record['rawname'])) { - $record['rawname'] = 'Raw tag name ' . $i; + // Attribute 'name' should be a lowercase version of 'rawname', if not set. + if (!isset($record['name'])) { + $record['name'] = core_text::strtolower($record['rawname']); + } else { + $record['name'] = core_text::strtolower($record['name']); } if (!isset($record['tagtype'])) { diff --git a/lib/tests/behat/behat_data_generators.php b/lib/tests/behat/behat_data_generators.php index a2ce75f044a95..b2fa5871ac870 100644 --- a/lib/tests/behat/behat_data_generators.php +++ b/lib/tests/behat/behat_data_generators.php @@ -166,6 +166,10 @@ class behat_data_generators extends behat_base { 'required' => array('qtype', 'questioncategory', 'name'), 'switchids' => array('questioncategory' => 'category', 'user' => 'createdby') ), + 'tags' => array( + 'datagenerator' => 'tag', + 'required' => array('name') + ), ); /**