<?xml version="1.0" standalone="no"?>

<!DOCTYPE caldavtest SYSTEM "caldavtest.dtd">

<caldavtest>
	<description>Test addressbook sharing</description>

	<require-feature>
		<feature>carddav</feature>
	</require-feature>

	<start>
	</start>
	
	<test-suite name='Read-write addressbook'>
		<test name='1'>
			<description>POST invitation</description>
			<request>
				<method>POST</method>
				<ruri>$addressbookhome1:/addressbook/</ruri>
				<data>
					<content-type>text/xml; charset=utf-8</content-type>
					<filepath>Resource/CardDAV/sharing/read-write/1.xml</filepath>
				</data>
				<verify>
					<callback>statusCode</callback>
				</verify>
			</request>
		</test>
		<test name='4'>
			<description>Shared addressbook exists</description>
			<request user="$userid2:" pswd="$pswd2:">
				<method>PROPFIND</method>
				<ruri>$addressbookhome2:/addressbook_shared_by_user01/</ruri>
				<header>
					<name>Depth</name>
					<value>0</value>
				</header>
				<data>
					<content-type>text/xml; charset=utf-8</content-type>
					<filepath>Resource/CardDAV/sharing/read-write/4.xml</filepath>
				</data>
				<verify>
					<callback>xmlElementMatch</callback>
					<arg>
						<name>exists</name>
						<value>$verify-property-prefix:/{DAV:}owner/{DAV:}href[=$principaluri1:]</value>
						<value>$verify-property-prefix:/{DAV:}resourcetype/{DAV:}collection</value>
						<value>$verify-property-prefix:/{DAV:}resourcetype/{urn:ietf:params:xml:ns:carddav}addressbook</value>
						<value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}read</value>
						<value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}write</value>
						<value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}bind</value>
						<value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}unbind</value>
					</arg>
					<arg>
						<name>notexists</name>
						<value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}admin</value>
						<value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}all</value>
					</arg>
				</verify>
			</request>
		</test>

		<test name='4a'>
			<description>Shared addressbook exists Depth:1</description>
			<request user="$userid2:" pswd="$pswd2:">
				<method>PROPFIND</method>
				<ruri>$addressbookhome2:/</ruri>
				<header>
					<name>Depth</name>
					<value>1</value>
				</header>
				<data>
					<content-type>text/xml; charset=utf-8</content-type>
					<filepath>Resource/CardDAV/sharing/read-write/4.xml</filepath>
				</data>
				<verify>
					<callback>xmlElementMatch</callback>
					<arg>
						<name>parent</name>
						<value>$multistatus-response-prefix:[^{DAV:}href=$addressbookhome2:/addressbook_shared_by_user01/]</value>
					</arg>
					<arg>
						<name>exists</name>
						<!--<value>$verify-response-prefix:/{DAV:}owner/{DAV:}href[=$principaluri1:]</value>-->
						<value>$verify-response-prefix:/{DAV:}resourcetype/{DAV:}collection</value>
						<value>$verify-response-prefix:/{DAV:}resourcetype/{urn:ietf:params:xml:ns:carddav}addressbook</value>
						<value>$verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}read</value>
						<value>$verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}write</value>
						<value>$verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}bind</value>
						<value>$verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}unbind</value>
					</arg>
					<arg>
						<name>notexists</name>
						<value>$verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}admin</value>
						<value>$verify-response-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}all</value>
					</arg>
				</verify>
			</request>
		</test>

		<test name='5'>
			<description>Original addressbook unchanged</description>
			<request>
				<method>PROPFIND</method>
				<ruri>$addressbookpath1:</ruri>
				<header>
					<name>Depth</name>
					<value>0</value>
				</header>
				<data>
					<content-type>text/xml; charset=utf-8</content-type>
					<filepath>Resource/CardDAV/sharing/read-write/4.xml</filepath>
				</data>
				<verify>
					<callback>xmlElementMatch</callback>
					<arg>
						<name>exists</name>
						<value>$verify-property-prefix:/{DAV:}owner/{DAV:}href[=$principaluri1:]</value>
					</arg>
				</verify>
			</request>
		</test>

		<test name='6'>
			<description>Sharee creates contact</description>
			<request user="$userid2:" pswd="$pswd2:">
				<method>PUT</method>
				<ruri>$addressbookhome2:/addressbook_shared_by_user01/1.vcf</ruri>
				<data>
					<content-type>text/vcard; charset=utf-8</content-type>
					<filepath>Resource/CardDAV/sharing/read-write/6.vcf</filepath>
				</data>
				<verify>
					<callback>statusCode</callback>
				</verify>
			</request>
		</test>

		<test name='7'>
			<description>Sharer sees contact</description>
			<request>
				<method>GET</method>
				<ruri>$addressbookpath1:/1.vcf</ruri>
				<verify>
					<callback>addressDataMatch</callback>
					<arg>
						<name>filepath</name>
						<value>Resource/CardDAV/sharing/read-write/6.vcf</value>
					</arg>
				</verify>
			</request>
		</test>

		<test name='8'>
			<description>Sharer changes contact</description>
			<request>
				<method>PUT</method>
				<ruri>$addressbookpath1:/1.vcf</ruri>
				<data>
					<content-type>text/vcard; charset=utf-8</content-type>
					<filepath>Resource/CardDAV/sharing/read-write/7.vcf</filepath>
				</data>
				<verify>
					<callback>statusCode</callback>
				</verify>
			</request>
		</test>

		<test name='9'>
			<description>Sharee sees changed contact</description>
			<request user="$userid2:" pswd="$pswd2:">
				<method>GET</method>
				<ruri>$addressbookhome2:/addressbook_shared_by_user01/1.vcf</ruri>
				<verify>
					<callback>addressDataMatch</callback>
					<arg>
						<name>filepath</name>
						<value>Resource/CardDAV/sharing/read-write/7.vcf</value>
					</arg>
				</verify>
			</request>
		</test>

		<test name='10'>
			<description>Sharer creates contact</description>
			<request>
				<method>PUT</method>
				<ruri>$addressbookpath1:/2.vcf</ruri>
				<data>
					<content-type>text/vcard; charset=utf-8</content-type>
					<filepath>Resource/CardDAV/sharing/read-write/8.vcf</filepath>
				</data>
				<verify>
					<callback>statusCode</callback>
				</verify>
			</request>
		</test>
		<test name='11'>
			<description>Sharee sees new contact</description>
			<request user="$userid2:" pswd="$pswd2:">
				<method>GET</method>
				<ruri>$addressbookhome2:/addressbook_shared_by_user01/2.vcf</ruri>
				<verify>
					<callback>addressDataMatch</callback>
					<arg>
						<name>filepath</name>
						<value>Resource/CardDAV/sharing/read-write/8.vcf</value>
					</arg>
				</verify>
			</request>
		</test>
		<test name='12'>
			<description>Sharee changes contact</description>
			<request user="$userid2:" pswd="$pswd2:">
				<method>PUT</method>
				<ruri>$addressbookhome2:/addressbook_shared_by_user01/2.vcf</ruri>
				<data>
					<content-type>text/vcard; charset=utf-8</content-type>
					<filepath>Resource/CardDAV/sharing/read-write/9.vcf</filepath>
				</data>
				<verify>
					<callback>statusCode</callback>
				</verify>
			</request>
		</test>
		<test name='13'>
			<description>Sharer sees changed contact</description>
			<request>
				<method>GET</method>
				<ruri>$addressbookpath1:/2.vcf</ruri>
				<verify>
					<callback>addressDataMatch</callback>
					<arg>
						<name>filepath</name>
						<value>Resource/CardDAV/sharing/read-write/9.vcf</value>
					</arg>
				</verify>
			</request>
		</test>
		<test name='14'>
			<description>Un-share by delete</description>
			<request user="$userid2:" pswd="$pswd2:">
				<method>DELETE</method>
				<ruri>$addressbookhome2:/addressbook_shared_by_user01/</ruri>
				<verify>
					<callback>statusCode</callback>
				</verify>
			</request>
		</test>
		<test name='15'>
			<description>Original address book still exists</description>
			<request>
				<method>PROPFIND</method>
				<ruri>$addressbookhome1:/addressbook/</ruri>
				<header>
					<name>Depth</name>
					<value>0</value>
				</header>
				<data>
					<content-type>text/xml; charset=utf-8</content-type>
					<filepath>Resource/CardDAV/sharing/read-write/4.xml</filepath>
				</data>
				<verify>
					<callback>xmlElementMatch</callback>
					<arg>
						<name>exists</name>
						<value>$verify-property-prefix:/{DAV:}owner/{DAV:}href[=$principaluri1:]</value>
						<value>$verify-property-prefix:/{DAV:}resourcetype/{DAV:}collection</value>
						<value>$verify-property-prefix:/{DAV:}resourcetype/{urn:ietf:params:xml:ns:carddav}addressbook</value>
						<value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}read</value>
						<value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}write</value>
						<value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}bind</value>
						<value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}unbind</value>
					</arg>
					<arg>
						<name>notexists</name>
						<value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}admin</value>
						<value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}all</value>
					</arg>
				</verify>			</request>
		</test>
		<test name='16'>
			<description>Shared addressbook no longer exists Depth:1</description>
			<request user="$userid2:" pswd="$pswd2:">
				<method>PROPFIND</method>
				<ruri>$addressbookhome2:</ruri>
				<header>
					<name>Depth</name>
					<value>1</value>
				</header>
				<data>
					<content-type>text/xml; charset=utf-8</content-type>
					<filepath>Resource/CardDAV/sharing/read-write/4.xml</filepath>
				</data>
				<verify>
					<callback>xmlElementMatch</callback>
					<arg>
						<name>notexists</name>
						<value>$multistatus-response-prefix:[^{DAV:}href=$addressbookhome2:/addressbook_shared_by_user01/]</value>
					</arg>
				</verify>
			</request>
		</test>	</test-suite>
	
	<end>
	</end>

</caldavtest>
