
########################
**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:


.. code-block:: perl

     # 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 :doc:`Cassandane::TestEntity </developer/cassandane-api/Cassandane/TestEntity>`.


*******
METHODS
*******


new_jmaptester
==============



.. code-block:: perl

     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
=================



.. code-block:: perl

     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
=======



.. code-block:: perl

     my $carddav = $user->carddav;


This returns a (possibly cached) `Net::CardDAVTalk <https://metacpan.org/pod/Net::CardDAVTalk>`_ client for this user.


caldav
======



.. code-block:: perl

     my $carddav = $user->caldav;


This returns a (possibly cached) `Net::CalDAVTalk <https://metacpan.org/pod/Net::CalDAVTalk>`_ client for this user.


imap
====



.. code-block:: perl

     my $imap = $user->imap;


This returns a fresh `Mail::IMAPTalk <https://metacpan.org/pod/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 :doc:`test entity system </developer/cassandane-api/Cassandane/TestEntity>`.
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 :doc:`Cassandane::TestEntity::DataType::AddressBook </developer/cassandane-api/Cassandane/TestEntity/DataType/AddressBook>` factory
 


- calendarevents
 
 returns a :doc:`Cassandane::TestEntity::DataType::CalendarEvent </developer/cassandane-api/Cassandane/TestEntity/DataType/CalendarEvent>` factory
 


- calendars
 
 returns a :doc:`Cassandane::TestEntity::DataType::Calendar </developer/cassandane-api/Cassandane/TestEntity/DataType/Calendar>` factory
 


- contacts
 
 returns a :doc:`Cassandane::TestEntity::DataType::ContactCard </developer/cassandane-api/Cassandane/TestEntity/DataType/ContactCard>` factory
 


- emails
 
 returns a :doc:`Cassandane::TestEntity::DataType::Email </developer/cassandane-api/Cassandane/TestEntity/DataType/Email>` factory
 


- mailboxes
 
 returns a :doc:`Cassandane::TestEntity::DataType::Mailbox </developer/cassandane-api/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.


.. code-block:: perl

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



