**Cassandane::TestUser**
************************


NAME
====

Cassandane::TestUser - a handle on a Cyrus user with test-related
methods


SYNOPSIS
========

Every test case gets one user created by default, and it's easy to
make more, either with or without setup actions:

   # get the default user, usually "cassandane"
   my $user = $test_case->default_user;

   # create a user and do some basic in-Cyrus setup
   my $user = $test_case->instance->create_user("someuser");

   # create a TestUser object, but don't touch Cyrus
   my $user = $test_case->instance->create_user_without_setup("someuser");

Once you have them, you can get pre-authenticated clients for various
protocols with the "jmap", "caldav", "carddav", or "imap" methods.

You can also easily create test data using the entity system, for
which see the Test Entities section below or Cassandane::TestEntity.


METHODS
=======


new_jmaptester
--------------

   my $tester = $user->new_jmaptester;

This returns a new "Cassandane::JMAPTester" authenticated as this
user.  A hashref can be passed as an argument, in which case it will
be used as additional arguments to the JMAPTester constructor.

If the argument is an arrayref, it will be used as the default "using"
for the JMAPTester.


new_jmaptester_ws
-----------------

   my $tester_ws = $user->new_jmaptester_ws;

This returns a new "Cassandane::JMAPTesterWS" authenticated as this
user. That's just a JMAPTester that uses websockets.

Otherwise, this method has the same behavior as new_jmaptester.


carddav
-------

   my $carddav = $user->carddav;

This returns a (possibly cached) Net::CardDAVTalk client for this
user.


caldav
------

   my $carddav = $user->caldav;

This returns a (possibly cached) Net::CalDAVTalk client for this user.


imap
----

   my $imap = $user->imap;

This returns a fresh Mail::IMAPTalk client for this user.  Because
IMAP is stateful, this method never returns a cached client.


Test Entities
-------------

Apart from making it easy to get protocol clients, one of the most
useful behaviors of a TestUser is the test entity system. This makes
it easy to create plausible test data without lots of tedious method
calls.

The following methods return factories for the relevant datatypes:

* addressbooks

   returns a Cassandane::TestEntity::DataType::AddressBook factory

* calendarevents

   returns a Cassandane::TestEntity::DataType::CalendarEvent factory

* calendars

   returns a Cassandane::TestEntity::DataType::Calendar factory

* contacts

   returns a Cassandane::TestEntity::DataType::ContactCard factory

* emails

   returns a Cassandane::TestEntity::DataType::Email factory

* mailboxes

   returns a Cassandane::TestEntity::DataType::Mailbox factory

With these factories, you do lots of useful things described in their
documentation, but most simply the operations below, which work for
every datatype.  Mailboxes are just used as an example.

   my $mailbox = $user->mailboxes->get($mailbox_id);
   my $new_mailbox = $user->mailboxes->create({ prop1 => val1, ... });

   $mailbox->update({ prop1 => val1 });
