Skip to content
Snippets Groups Projects
Commit 74f93e0b authored by sv's avatar sv Committed by Taras Kruts
Browse files

Issue #3365912 by SV: Add behat test coverage for export-users feature

parent 92501b8d
No related branches found
No related tags found
No related merge requests found
......@@ -49,7 +49,7 @@ class PostContext extends RawMinkContext {
*
* @Given posts with non-anonymous owner:
*/
public function createGroupsWithOwner(TableNode $postsTable) {
public function createPostWithOwner(TableNode $postsTable) {
// Create a new random user to own our groups, this ensures the author
// isn't anonymous.
$user = (object) [
......@@ -75,6 +75,27 @@ class PostContext extends RawMinkContext {
}
}
/**
* Create multiple posts at the start of a test with defined users as
* authors.
*
* Creates post of a given type provided in the form:
* | field_post | author | type | field_visibility | status | langcode
* | My description | Mark | post | 0 | 1 | en
* | ... | ... | ... | ... | ...
*
* @Given posts:
*/
public function createPosts(TableNode $postsTable) {
foreach ($postsTable->getHash() as $postHash) {
if (!isset($postHash['author'])) {
throw new \Exception("User is not specified as author when using the 'posts with defined author' step.");
}
$post = $this->postCreate($postHash);
$this->posts[$post->id()] = $post;
}
}
/**
* Select a post visibility.
*
......
......@@ -18,6 +18,7 @@ use Drupal\DrupalExtension\Hook\Scope\EntityScope;
class SocialDrupalContext extends DrupalContext {
use AvoidCleanupTrait;
use NodeTrait;
/**
* Prepares Big Pipe NOJS cookie if needed.
......@@ -450,4 +451,49 @@ class SocialDrupalContext extends DrupalContext {
$this->getSession()->wait(1800000, 'jQuery("#updateprogress").length === 0');
}
/**
* Add likes to node at the start of a test with existing users as authors.
*
* Creates like provided in the form:
* | title | bundle | user |
* | My event | event | Jane Doe |
* | ... | ... | ... |
*
* @Given likes node:
*/
public function createNodeLikes(TableNode $nodesTable): void {
$entity_manager = \Drupal::service('entity_type.manager');
/** @var \Drupal\votingapi\VoteTypeInterface $vote_type */
$vote_type = $entity_manager->getStorage('vote_type')->load('like');
/** @var \Drupal\votingapi\VoteStorageInterface $vote_storage */
$vote_storage = \Drupal::entityTypeManager()->getStorage('vote');
foreach ($nodesTable->getHash() as $nodeHash) {
if (!isset($nodeHash['author'])) {
throw new \Exception("User is not specified as author when using the 'like node with defined author:' step.");
}
$owner = user_load_by_name($nodeHash['author']);
if ($owner === FALSE) {
throw new \Exception(sprintf("User with username '%s' does not exist.", $nodeHash['author']));
}
$node_id = $this->getNodeIdFromTitle($nodeHash['bundle'], $nodeHash['title']);
if ($node_id === NULL) {
throw new \Exception("Node '%s' does not exist.", $nodeHash['title']);
}
/** @var \Drupal\votingapi\VoteInterface $vote */
$vote = $vote_storage->create(['type' => 'like']);
$vote->setVotedEntityId($node_id);
$vote->setVotedEntityType('node');
$vote->setValueType($vote_type->getValueType());
$vote->setValue(1);
$vote->setOwnerId($owner->id());
$vote->save();
}
}
}
......@@ -17,6 +17,42 @@ Feature: Export users
And I disable module social_private_message and its dependants
And I disable module social_profile_organization_tag and its dependants
Given topics:
| title | author | field_topic_type | body | field_content_visibility | langcode |
| Topic content 1| ExportUser1 | News | Body description text 1| public | en |
| Topic content 2| ExportUser2 | News | Body description text 2| public | en |
| Topic content 3| ExportUser3 | News | Body description text 3| public | en |
And "1" comments with text "Behat Comment [id]" for "Topic content 1"
And "1" comments with text "Behat Comment [id]" for "Topic content 2"
And "1" comments with text "Behat Comment [id]" for "Topic content 3"
Given events:
| title | author | field_event_date | body | field_content_visibility | langcode |
| Event content 1| ExportUser1 | 2100-01-01T12:00:00 | Body description text 1| public | en |
| Event content 2| ExportUser2 | 2100-01-01T12:00:00 | Body description text 2| public | en |
| Event content 3| ExportUser3 | 2100-01-01T12:00:00 | Body description text 3| public | en |
And event enrollees:
| event | user |
| Event content 1| ExportUser1 |
| Event content 2| ExportUser2 |
| Event content 3| ExportUser3 |
And likes node:
| title | bundle | author |
| Event content 1 | event | ExportUser1 |
Given posts:
| field_post | author | type | status | field_visibility | langcode |
| Post content 1| ExportUser1 | post | 1 | 0 | en |
| Post content 2| ExportUser2 | post | 1 | 0 | en |
| Post content 3| ExportUser3 | post | 1 | 0 | en |
Given groups:
| label | author | field_group_description | type | langcode | field_flexible_group_visibility |
| Test group 1 | ExportUser3 | Group description | flexible_group | en | public |
# Ensure the CSV file that people are using in their automation without
# customisation is the same between Open Social versions.
Scenario: The default export for a new installation
......@@ -44,10 +80,10 @@ Feature: Export users
And I should see the text "Action processing results: Export the selected users to CSV (3)."
And the file downloaded from "Download file" should have contents:
"""
"User ID",UUID,"First name","Last name",Username,"Display name",Email,"Last login","Last access","Registration date",Status,"Country code","Administrative address","Address locality","Postal code","Address line 1","Address line 2","Phone number",Nationality,Organization,Function,Skills,Interests,"Self introduction","Profile tag",Roles,"Posts created","Comments created","Topics created","Events created","Event enrollments","Groups created","Group memberships","Group memberships (specified)","Number of Likes"
4,5d0df1b9-ee3b-4356-9e48-8891fadfff85,,,ExportUser3,ExportUser3,exportuser3@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,"authenticated, verified",0,0,0,0,0,0,0,,0
3,34fff0f1-8897-4ca8-a682-707c9dd87501,,,ExportUser2,ExportUser2,exportuser2@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,"authenticated, verified",0,0,0,0,0,0,0,,0
2,85e14211-147c-4f01-ae18-b97300671de6,,,ExportUser1,ExportUser1,exportuser1@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,"authenticated, verified",0,0,0,0,0,0,0,,0
"User ID",UUID,"First name","Last name",Username,"Display name",Email,"Last login","Last access","Registration date",Status,"Country code","Administrative address","Address locality","Postal code","Address line 1","Address line 2","Phone number",Nationality,Organization,Function,Skills,Interests,"Self introduction","Profile tag",Roles,"Posts created","Comments created","Topics created","Events created","Event enrollments","Groups created","Group memberships","Group memberships (specified)","Number of Likes"
4,5d0df1b9-ee3b-4356-9e48-8891fadfff85,,,ExportUser3,ExportUser3,exportuser3@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,"authenticated, verified",1,1,1,1,1,1,1,"Test group 1 (1)",0
3,34fff0f1-8897-4ca8-a682-707c9dd87501,,,ExportUser2,ExportUser2,exportuser2@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,"authenticated, verified",1,1,1,1,1,0,0,,0
2,85e14211-147c-4f01-ae18-b97300671de6,,,ExportUser1,ExportUser1,exportuser1@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,"authenticated, verified",1,1,1,1,1,0,0,,1
"""
Scenario: The organization tag extension adds its profile field to the export
......@@ -77,9 +113,9 @@ Feature: Export users
And the file downloaded from "Download file" should have contents:
"""
"User ID",UUID,"First name","Last name",Username,"Display name",Email,"Last login","Last access","Registration date",Status,"Country code","Administrative address","Address locality","Postal code","Address line 1","Address line 2","Phone number",Nationality,Organization,Function,"Organization Tag",Skills,Interests,"Self introduction","Profile tag",Roles,"Posts created","Comments created","Topics created","Events created","Event enrollments","Groups created","Group memberships","Group memberships (specified)","Number of Likes"
4,5d0df1b9-ee3b-4356-9e48-8891fadfff85,,,ExportUser3,ExportUser3,exportuser3@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,,"authenticated, verified",0,0,0,0,0,0,0,,0
3,34fff0f1-8897-4ca8-a682-707c9dd87501,,,ExportUser2,ExportUser2,exportuser2@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,,"authenticated, verified",0,0,0,0,0,0,0,,0
2,85e14211-147c-4f01-ae18-b97300671de6,,,ExportUser1,ExportUser1,exportuser1@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,,"authenticated, verified",0,0,0,0,0,0,0,,0
4,5d0df1b9-ee3b-4356-9e48-8891fadfff85,,,ExportUser3,ExportUser3,exportuser3@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,,"authenticated, verified",1,1,1,1,1,1,1,"Test group 1 (1)",0
3,34fff0f1-8897-4ca8-a682-707c9dd87501,,,ExportUser2,ExportUser2,exportuser2@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,,"authenticated, verified",1,1,1,1,1,0,0,,0
2,85e14211-147c-4f01-ae18-b97300671de6,,,ExportUser1,ExportUser1,exportuser1@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,,"authenticated, verified",1,1,1,1,1,0,0,,1
"""
Scenario: The private message module adds a private message statistic to the export
......@@ -109,9 +145,9 @@ Feature: Export users
And the file downloaded from "Download file" should have contents:
"""
"User ID",UUID,"First name","Last name",Username,"Display name",Email,"Last login","Last access","Registration date",Status,"Country code","Administrative address","Address locality","Postal code","Address line 1","Address line 2","Phone number",Nationality,Organization,Function,Skills,Interests,"Self introduction","Profile tag",Roles,"Posts created","Comments created","Topics created","Events created","Event enrollments","Groups created","Group memberships","Group memberships (specified)","Number of Likes","Number of Private messages"
4,5d0df1b9-ee3b-4356-9e48-8891fadfff85,,,ExportUser3,ExportUser3,exportuser3@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,"authenticated, verified",0,0,0,0,0,0,0,,0,0
3,34fff0f1-8897-4ca8-a682-707c9dd87501,,,ExportUser2,ExportUser2,exportuser2@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,"authenticated, verified",0,0,0,0,0,0,0,,0,0
2,85e14211-147c-4f01-ae18-b97300671de6,,,ExportUser1,ExportUser1,exportuser1@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,"authenticated, verified",0,0,0,0,0,0,0,,0,0
4,5d0df1b9-ee3b-4356-9e48-8891fadfff85,,,ExportUser3,ExportUser3,exportuser3@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,"authenticated, verified",1,1,1,1,1,1,1,"Test group 1 (1)",0,0
3,34fff0f1-8897-4ca8-a682-707c9dd87501,,,ExportUser2,ExportUser2,exportuser2@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,"authenticated, verified",1,1,1,1,1,0,0,,0,0
2,85e14211-147c-4f01-ae18-b97300671de6,,,ExportUser1,ExportUser1,exportuser1@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,"authenticated, verified",1,1,1,1,1,0,0,,1,0
"""
Scenario: All profile features enabled
......@@ -155,9 +191,9 @@ Feature: Export users
And the file downloaded from "Download file" should have contents:
"""
"User ID",UUID,"First name","Last name",Username,"Display name",Nickname,Email,"Last login","Last access","Registration date",Status,"Country code","Administrative address","Address locality","Postal code","Address line 1","Address line 2","Phone number",Nationality,Organization,Function,Skills,Interests,"Self introduction","Profile tag",Roles,"Posts created","Comments created","Topics created","Events created","Event enrollments","Groups created","Group memberships","Group memberships (specified)","Number of Likes"
4,5d0df1b9-ee3b-4356-9e48-8891fadfff85,,,ExportUser3,ExportUser3,,exportuser3@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,"authenticated, verified",0,0,0,0,0,0,0,,0
3,34fff0f1-8897-4ca8-a682-707c9dd87501,,,ExportUser2,ExportUser2,,exportuser2@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,"authenticated, verified",0,0,0,0,0,0,0,,0
2,85e14211-147c-4f01-ae18-b97300671de6,,,ExportUser1,ExportUser1,,exportuser1@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,"authenticated, verified",0,0,0,0,0,0,0,,0
4,5d0df1b9-ee3b-4356-9e48-8891fadfff85,,,ExportUser3,ExportUser3,,exportuser3@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,"authenticated, verified",1,1,1,1,1,1,1,"Test group 1 (1)",0
3,34fff0f1-8897-4ca8-a682-707c9dd87501,,,ExportUser2,ExportUser2,,exportuser2@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,"authenticated, verified",1,1,1,1,1,0,0,,0
2,85e14211-147c-4f01-ae18-b97300671de6,,,ExportUser1,ExportUser1,,exportuser1@example.com,never,never,"02/17/2023 - 14:42",Active,,,,,,,,,,,,,,,"authenticated, verified",1,1,1,1,1,0,0,,1
"""
Scenario: All profile features disabled
......@@ -199,7 +235,7 @@ Feature: Export users
And the file downloaded from "Download file" should have contents:
"""
"User ID",UUID,Username,"Display name",Email,"Last login","Last access","Registration date",Status,Roles,"Posts created","Comments created","Topics created","Events created","Event enrollments","Groups created","Group memberships","Group memberships (specified)","Number of Likes"
4,5d0df1b9-ee3b-4356-9e48-8891fadfff85,ExportUser3,ExportUser3,exportuser3@example.com,never,never,"02/17/2023 - 14:42",Active,"authenticated, verified",0,0,0,0,0,0,0,,0
3,34fff0f1-8897-4ca8-a682-707c9dd87501,ExportUser2,ExportUser2,exportuser2@example.com,never,never,"02/17/2023 - 14:42",Active,"authenticated, verified",0,0,0,0,0,0,0,,0
2,85e14211-147c-4f01-ae18-b97300671de6,ExportUser1,ExportUser1,exportuser1@example.com,never,never,"02/17/2023 - 14:42",Active,"authenticated, verified",0,0,0,0,0,0,0,,0
4,5d0df1b9-ee3b-4356-9e48-8891fadfff85,ExportUser3,ExportUser3,exportuser3@example.com,never,never,"02/17/2023 - 14:42",Active,"authenticated, verified",1,1,1,1,1,1,1,"Test group 1 (1)",0
3,34fff0f1-8897-4ca8-a682-707c9dd87501,ExportUser2,ExportUser2,exportuser2@example.com,never,never,"02/17/2023 - 14:42",Active,"authenticated, verified",1,1,1,1,1,0,0,,0
2,85e14211-147c-4f01-ae18-b97300671de6,ExportUser1,ExportUser1,exportuser1@example.com,never,never,"02/17/2023 - 14:42",Active,"authenticated, verified",1,1,1,1,1,0,0,,1
"""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment