Vanilla has various traits for easily creating and testing data through API endpoints. These generally have a suffix ApiTestTrait
. The expect to be used on test cases that use SiteTestTrait
or AbstractApiV2Test
.
Structure of the Traits
The traits generally all have the following in common.
- Easy
createThing()
methods for common resources. - All parameters are always defaulted.
- Any parameter can be overridden by passing an array of overrides. For example
createCategory([ 'name' => 'myName' ])
; - Parameters that have a unique constraint will have a new unique default value for every record created.
- When records have a parent -> child relation ship or dependency, the default parent/relationship will be automatically configured. For example, when creating a discussion, it will automatically be created in the last created category.
Available Traits
CommunityApiTestTrait
createCategory()
createDiscussion()
createComments()
createPermissionedCategory($overrides, $viewRoleIDs)
- Create a category that is only viewable by to the passed roleIDs.
Note: Please do not use the deprecated CategoryAndDiscussionApiTestTrait
.
UsersAndRolesApiTestTrait
createUser()
updateUser()
createRole()
runWithPermissions($callable, ...$permissions)
- Run some callback with a user that has the given permissions. Supports global, and resource specific permissions.
Cloud Only Trait
The following traits are only available with access to some Vanilla Cloud only plugins.
GroupsAndEventsApiTestTrait
createGroup()
inviteGroup($userIDs)
joinGroup()
createEventCategory()
createGroupDiscussion()
createEvent()
createGroupHydrated()
- Create a group with some content in it by default.clearEvents()
- Delete events from a category or group.
KbApiTestTrait
createKnowledgeBase()
createKnowledgeCategory()
createArticle()
translateKnowledgeBase()
- Translate a knowledge base into some preset languages.
RanksApiTestTrait
SubcommunityTestTrait
createSubcommunity()
createProduct()