refactor: replace custom CRM with Monica fork
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s

This commit is contained in:
Kroonk
2026-05-22 16:19:55 +02:00
parent 38cc4c09ca
commit a213a1dba0
2215 changed files with 242567 additions and 6015 deletions

View File

@@ -0,0 +1,294 @@
<?php
namespace Tests\Api\DAV;
use Carbon\Carbon;
use Tests\ApiTestCase;
use Illuminate\Support\Str;
use App\Models\User\SyncToken;
use App\Models\Contact\Contact;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class CalDAVBirthdaysTest extends ApiTestCase
{
use DatabaseTransactions, CardEtag;
/**
* @group dav
*/
public function test_caldav_birthdays_propfind()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$specialDate = $contact->setSpecialDate('birthdate', 1983, 03, 04);
$response = $this->call('PROPFIND', "/dav/calendars/{$user->email}/birthdays");
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee("<d:response><d:href>/dav/calendars/{$user->email}/birthdays/</d:href>", false);
$specialDate->refresh();
$response->assertSee("<d:response><d:href>/dav/calendars/{$user->email}/birthdays/{$specialDate->uuid}.ics</d:href>", false);
}
public function test_caldav_birthdays_propfind_with_props()
{
$user = $this->signin();
$response = $this->call('PROPFIND', "/dav/calendars/{$user->email}/birthdays/", [], [], [],
[
'HTTP_DEPTH' => 0,
],
'<d:propfind xmlns:d="DAV:">
<d:prop>
<d:displayname />
</d:prop>
</d:propfind>'
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">'.
'<d:response>'.
"<d:href>/dav/calendars/{$user->email}/birthdays/</d:href>".
'<d:propstat>'.
'<d:prop>'.
'<d:displayname>Birthdays</d:displayname>'.
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>'.
'</d:multistatus', false);
}
/**
* @group dav
*/
public function test_caldav_birthdays_propfind_one_birthday()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$specialDate = $contact->setSpecialDate('birthdate', 1983, 03, 04);
$specialDate->uuid = Str::uuid();
$specialDate->save();
$response = $this->call('PROPFIND', "/dav/calendars/{$user->email}/birthdays/{$specialDate->uuid}.ics");
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee("<d:response><d:href>/dav/calendars/{$user->email}/birthdays/{$specialDate->uuid}.ics</d:href>", false);
}
public function test_caldav_birthdays_getctag()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$specialDate = $contact->setSpecialDate('birthdate', 1983, 03, 04);
$specialDate->uuid = Str::uuid();
$specialDate->save();
$response = $this->call('PROPFIND', "/dav/calendars/{$user->email}/", [], [], [],
[
'HTTP_DEPTH' => '1',
'content-type' => 'application/xml; charset=utf-8',
],
"<propfind xmlns='DAV:' xmlns:cs='http://calendarserver.org/ns/' xmlns:s='http://sabredav.org/ns'>
<prop>
<cs:getctag />
<sync-token />
<s:sync-token />
</prop>
</propfind>"
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$tokens = SyncToken::where([
'account_id' => $user->account_id,
'user_id' => $user->id,
'name' => 'birthdays',
])->orderBy('created_at')->get();
$this->assertGreaterThan(0, $tokens->count());
$token = $tokens->last();
$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">', false);
$response->assertSee('<d:response>'.
"<d:href>/dav/calendars/{$user->email}/birthdays/</d:href>".
'<d:propstat>'.
'<d:prop>'.
"<cs:getctag>http://sabre.io/ns/sync/{$token->id}</cs:getctag>".
"<d:sync-token>http://sabre.io/ns/sync/{$token->id}</d:sync-token>".
"<s:sync-token>http://sabre.io/ns/sync/{$token->id}</s:sync-token>".
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>', false);
}
public function test_caldav_birthdays_getctag_birthday()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$specialDate = $contact->setSpecialDate('birthdate', 1983, 03, 04);
$specialDate->uuid = Str::uuid();
$specialDate->save();
$response = $this->call('PROPFIND', "/dav/calendars/{$user->email}/birthdays/", [], [], [],
[
'HTTP_DEPTH' => '0',
'content-type' => 'application/xml; charset=utf-8',
],
"<propfind xmlns='DAV:' xmlns:cs='http://calendarserver.org/ns/' xmlns:s='http://sabredav.org/ns'>
<prop>
<cs:getctag />
<sync-token />
<s:sync-token />
</prop>
</propfind>"
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$tokens = SyncToken::where([
'account_id' => $user->account_id,
'user_id' => $user->id,
'name' => 'birthdays',
])->orderBy('created_at')->get();
$this->assertGreaterThan(0, $tokens->count());
$token = $tokens->last();
$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">', false);
$response->assertSee('<d:response>'.
"<d:href>/dav/calendars/{$user->email}/birthdays/</d:href>".
'<d:propstat>'.
'<d:prop>'.
"<cs:getctag>http://sabre.io/ns/sync/{$token->id}</cs:getctag>".
"<d:sync-token>http://sabre.io/ns/sync/{$token->id}</d:sync-token>".
"<s:sync-token>http://sabre.io/ns/sync/{$token->id}</s:sync-token>".
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>', false);
}
public function test_caldav_birthdays_sync_collection_with_token()
{
Carbon::setTestNow(Carbon::create(2019, 1, 1, 9, 0, 0));
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$specialDate = $contact->setSpecialDate('birthdate', 1983, 03, 04);
$specialDate->uuid = Str::uuid();
$specialDate->save();
Carbon::setTestNow(Carbon::create(2019, 1, 1, 8, 0, 0));
$token = factory(SyncToken::class)->create([
'account_id' => $user->account_id,
'user_id' => $user->id,
'name' => 'birthdays',
'timestamp' => now(),
]);
$response = $this->call('REPORT', "/dav/calendars/{$user->email}/birthdays/", [], [], [],
[
'content-type' => 'application/xml; charset=utf-8',
],
"<sync-collection xmlns='DAV:'>
<sync-token>http://sabre.io/ns/sync/{$token->id}</sync-token>
<sync-level>1</sync-level>
<prop>
<getetag />
</prop>
</sync-collection>"
);
$response->assertStatus(207);
$token = SyncToken::where([
'account_id' => $user->account_id,
'user_id' => $user->id,
'name' => 'birthdays',
])
->orderBy('created_at')
->get()
->last();
$response->assertSee("<d:multistatus xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\" xmlns:card=\"urn:ietf:params:xml:ns:carddav\" xmlns:cal=\"urn:ietf:params:xml:ns:caldav\" xmlns:cs=\"http://calendarserver.org/ns/\">
<d:response>
<d:href>/dav/calendars/{$user->email}/birthdays/{$specialDate->uuid}.ics</d:href>
<d:propstat>
<d:prop>
<d:getetag>&quot;{$this->getEtag($specialDate)}&quot;</d:getetag>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
<d:sync-token>http://sabre.io/ns/sync/{$token->id}</d:sync-token>
</d:multistatus>", false);
}
public function test_caldav_birthdays_sync_collection_init()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$specialDate = $contact->setSpecialDate('birthdate', 1983, 03, 04);
$specialDate->uuid = Str::uuid();
$specialDate->save();
$response = $this->call('REPORT', "/dav/calendars/{$user->email}/birthdays/", [], [], [],
[
'content-type' => 'application/xml; charset=utf-8',
],
"<sync-collection xmlns='DAV:'>
<sync-token />
<sync-level>1</sync-level>
<prop>
<getetag />
</prop>
</sync-collection>"
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$tokens = SyncToken::where([
'account_id' => $user->account_id,
'user_id' => $user->id,
'name' => 'birthdays',
])->orderBy('created_at')->get();
$this->assertGreaterThan(0, $tokens->count());
$token = $tokens->last();
$response->assertSee("<d:multistatus xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\" xmlns:card=\"urn:ietf:params:xml:ns:carddav\" xmlns:cal=\"urn:ietf:params:xml:ns:caldav\" xmlns:cs=\"http://calendarserver.org/ns/\">
<d:response>
<d:href>/dav/calendars/{$user->email}/birthdays/{$specialDate->uuid}.ics</d:href>
<d:propstat>
<d:prop>
<d:getetag>&quot;{$this->getEtag($specialDate)}&quot;</d:getetag>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
<d:sync-token>http://sabre.io/ns/sync/{$token->id}</d:sync-token>
</d:multistatus>", false);
}
}

View File

@@ -0,0 +1,303 @@
<?php
namespace Tests\Api\DAV;
use Carbon\Carbon;
use Tests\ApiTestCase;
use App\Models\Contact\Task;
use App\Models\User\SyncToken;
use App\Models\Contact\Contact;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class CalDAVTasksTest extends ApiTestCase
{
use DatabaseTransactions, CardEtag;
/**
* @group dav
*/
public function test_caldav_tasks_propfind()
{
$user = $this->signin();
$task = factory(Task::class)->create([
'account_id' => $user->account_id,
'contact_id' => null,
'created_at' => now(),
'updated_at' => now(),
]);
$response = $this->call('PROPFIND', "/dav/calendars/{$user->email}/tasks");
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee("<d:response><d:href>/dav/calendars/{$user->email}/tasks/</d:href>", false);
$response->assertSee("<d:response><d:href>/dav/calendars/{$user->email}/tasks/{$task->uuid}.ics</d:href>", false);
}
public function test_caldav_tasks_propfind_with_props()
{
$user = $this->signin();
$response = $this->call('PROPFIND', "/dav/calendars/{$user->email}/tasks/", [], [], [],
[
'HTTP_DEPTH' => 0,
],
'<d:propfind xmlns:d="DAV:">
<d:prop>
<d:displayname />
</d:prop>
</d:propfind>'
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">'.
'<d:response>'.
"<d:href>/dav/calendars/{$user->email}/tasks/</d:href>".
'<d:propstat>'.
'<d:prop>'.
'<d:displayname>Tasks</d:displayname>'.
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>'.
'</d:multistatus', false);
}
/**
* @group dav
*/
public function test_caldav_tasks_propfind_one_task()
{
$user = $this->signin();
$task = factory(Task::class)->create([
'account_id' => $user->account_id,
'created_at' => now(),
'updated_at' => now(),
]);
$response = $this->call('PROPFIND', "/dav/calendars/{$user->email}/tasks/{$task->uuid}.ics");
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee("<d:response><d:href>/dav/calendars/{$user->email}/tasks/{$task->uuid}.ics</d:href>", false);
}
public function test_caldav_tasks_getctag()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$task = factory(Task::class)->create([
'account_id' => $user->account_id,
'contact_id' => $contact->id,
]);
$response = $this->call('PROPFIND', "/dav/calendars/{$user->email}/", [], [], [],
[
'HTTP_DEPTH' => '1',
'content-type' => 'application/xml; charset=utf-8',
],
"<propfind xmlns='DAV:' xmlns:cs='http://calendarserver.org/ns/' xmlns:s='http://sabredav.org/ns'>
<prop>
<cs:getctag />
<sync-token />
<s:sync-token />
</prop>
</propfind>"
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$tokens = SyncToken::where([
'account_id' => $user->account_id,
'user_id' => $user->id,
'name' => 'tasks',
])->orderBy('created_at')->get();
$this->assertGreaterThan(0, $tokens->count());
$token = $tokens->last();
$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">', false);
$response->assertSee('<d:response>'.
"<d:href>/dav/calendars/{$user->email}/tasks/</d:href>".
'<d:propstat>'.
'<d:prop>'.
"<cs:getctag>http://sabre.io/ns/sync/{$token->id}</cs:getctag>".
"<d:sync-token>http://sabre.io/ns/sync/{$token->id}</d:sync-token>".
"<s:sync-token>http://sabre.io/ns/sync/{$token->id}</s:sync-token>".
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>', false);
}
public function test_caldav_tasks_getctag_task()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$task = factory(Task::class)->create([
'account_id' => $user->account_id,
'contact_id' => $contact->id,
'created_at' => now(),
'updated_at' => now(),
]);
$response = $this->call('PROPFIND', "/dav/calendars/{$user->email}/tasks/", [], [], [],
[
'HTTP_DEPTH' => '0',
'content-type' => 'application/xml; charset=utf-8',
],
"<propfind xmlns='DAV:' xmlns:cs='http://calendarserver.org/ns/' xmlns:s='http://sabredav.org/ns'>
<prop>
<cs:getctag />
<sync-token />
<s:sync-token />
</prop>
</propfind>"
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$tokens = SyncToken::where([
'account_id' => $user->account_id,
'user_id' => $user->id,
'name' => 'tasks',
])->orderBy('created_at')->get();
$this->assertGreaterThan(0, $tokens->count());
$token = $tokens->last();
$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">', false);
$response->assertSee('<d:response>'.
"<d:href>/dav/calendars/{$user->email}/tasks/</d:href>".
'<d:propstat>'.
'<d:prop>'.
"<cs:getctag>http://sabre.io/ns/sync/{$token->id}</cs:getctag>".
"<d:sync-token>http://sabre.io/ns/sync/{$token->id}</d:sync-token>".
"<s:sync-token>http://sabre.io/ns/sync/{$token->id}</s:sync-token>".
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>', false);
}
public function test_caldav_tasks_sync_collection_with_token()
{
Carbon::setTestNow(Carbon::create(2019, 1, 1, 9, 0, 0));
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$task = factory(Task::class)->create([
'account_id' => $user->account_id,
'contact_id' => $contact->id,
'created_at' => now(),
'updated_at' => now(),
]);
Carbon::setTestNow(Carbon::create(2019, 1, 1, 8, 0, 0));
$token = factory(SyncToken::class)->create([
'account_id' => $user->account_id,
'user_id' => $user->id,
'name' => 'tasks',
'timestamp' => now(),
]);
$response = $this->call('REPORT', "/dav/calendars/{$user->email}/tasks/", [], [], [],
[
'content-type' => 'application/xml; charset=utf-8',
],
"<sync-collection xmlns='DAV:'>
<sync-token>http://sabre.io/ns/sync/{$token->id}</sync-token>
<sync-level>1</sync-level>
<prop>
<getetag />
</prop>
</sync-collection>"
);
$response->assertStatus(207);
$token = SyncToken::where([
'account_id' => $user->account_id,
'user_id' => $user->id,
'name' => 'tasks',
])
->orderBy('created_at')
->get()
->last();
$response->assertSee("<d:multistatus xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\" xmlns:card=\"urn:ietf:params:xml:ns:carddav\" xmlns:cal=\"urn:ietf:params:xml:ns:caldav\" xmlns:cs=\"http://calendarserver.org/ns/\">
<d:response>
<d:href>/dav/calendars/{$user->email}/tasks/{$task->uuid}.ics</d:href>
<d:propstat>
<d:prop>
<d:getetag>&quot;{$this->getEtag($task)}&quot;</d:getetag>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
<d:sync-token>http://sabre.io/ns/sync/{$token->id}</d:sync-token>
</d:multistatus>", false);
}
public function test_caldav_tasks_sync_collection_init()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$task = factory(Task::class)->create([
'account_id' => $user->account_id,
'contact_id' => $contact->id,
'created_at' => now(),
'updated_at' => now(),
]);
$response = $this->call('REPORT', "/dav/calendars/{$user->email}/tasks/", [], [], [],
[
'content-type' => 'application/xml; charset=utf-8',
],
"<sync-collection xmlns='DAV:'>
<sync-token />
<sync-level>1</sync-level>
<prop>
<getetag />
</prop>
</sync-collection>"
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$tokens = SyncToken::where([
'account_id' => $user->account_id,
'user_id' => $user->id,
'name' => 'tasks',
])->orderBy('created_at')->get();
$this->assertGreaterThan(0, $tokens->count());
$token = $tokens->last();
$response->assertSee("<d:multistatus xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\" xmlns:card=\"urn:ietf:params:xml:ns:carddav\" xmlns:cal=\"urn:ietf:params:xml:ns:caldav\" xmlns:cs=\"http://calendarserver.org/ns/\">
<d:response>
<d:href>/dav/calendars/{$user->email}/tasks/{$task->uuid}.ics</d:href>
<d:propstat>
<d:prop>
<d:getetag>&quot;{$this->getEtag($task)}&quot;</d:getetag>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
<d:sync-token>http://sabre.io/ns/sync/{$token->id}</d:sync-token>
</d:multistatus>", false);
}
}

View File

@@ -0,0 +1,451 @@
<?php
namespace Tests\Api\DAV;
use Carbon\Carbon;
use Tests\ApiTestCase;
use App\Models\User\SyncToken;
use App\Models\Contact\Contact;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class CardDAVTest extends ApiTestCase
{
use DatabaseTransactions, CardEtag;
/**
* @group dav
*/
public function test_carddav_propfind_addressbooks()
{
$user = $this->signin();
$response = $this->call('PROPFIND', '/dav/addressbooks');
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee('<d:response><d:href>/dav/addressbooks/</d:href>', false);
$response->assertSee("<d:response><d:href>/dav/addressbooks/{$user->email}/</d:href>", false);
}
/**
* @group dav
*/
public function test_carddav_propfind_addressbooks_user()
{
$user = $this->signin();
$response = $this->call('PROPFIND', "/dav/addressbooks/{$user->email}");
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee("<d:response><d:href>/dav/addressbooks/{$user->email}/</d:href>", false);
$response->assertSee("<d:response><d:href>/dav/addressbooks/{$user->email}/contacts/</d:href>", false);
}
/**
* @group dav
*/
public function test_carddav_propfind_contacts()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$response = $this->call('PROPFIND', "/dav/addressbooks/{$user->email}/contacts");
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee("<d:response><d:href>/dav/addressbooks/{$user->email}/contacts/</d:href>", false);
$contactId = urlencode($contact->uuid);
$response->assertSee("<d:response><d:href>/dav/addressbooks/{$user->email}/contacts/{$contactId}.vcf</d:href>", false);
}
public function test_carddav_propfind_contacts_with_props()
{
$user = $this->signin();
$response = $this->call('PROPFIND', "/dav/addressbooks/{$user->email}/contacts/", [], [], [],
[
'HTTP_DEPTH' => 0,
],
'<d:propfind xmlns:d="DAV:">
<d:prop>
<d:displayname />
</d:prop>
</d:propfind>'
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">'.
'<d:response>'.
"<d:href>/dav/addressbooks/{$user->email}/contacts/</d:href>".
'<d:propstat>'.
'<d:prop>'.
'<d:displayname>Contacts</d:displayname>'.
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>'.
'</d:multistatus', false);
}
/**
* @group dav
*/
public function test_carddav_propfind_one_contact()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$response = $this->call('PROPFIND', "/dav/addressbooks/{$user->email}/contacts/{$contact->uuid}.vcf");
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee("<d:response><d:href>/dav/addressbooks/{$user->email}/contacts/{$contact->uuid}.vcf</d:href>", false);
}
/**
* @group dav
*/
public function test_carddav_propfind_one_contact_without_extension()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$response = $this->call('PROPFIND', "/dav/addressbooks/{$user->email}/contacts/{$contact->uuid}");
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee("<d:response><d:href>/dav/addressbooks/{$user->email}/contacts/{$contact->uuid}</d:href>", false);
}
public function test_carddav_getctag()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$response = $this->call('PROPFIND', "/dav/addressbooks/{$user->email}/", [], [], [],
[
'HTTP_DEPTH' => '1',
'content-type' => 'application/xml; charset=utf-8',
],
"<propfind xmlns='DAV:' xmlns:cs='http://calendarserver.org/ns/'>
<prop>
<cs:getctag />
<sync-token />
</prop>
</propfind>"
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$tokens = SyncToken::where([
'account_id' => $user->account_id,
'user_id' => $user->id,
'name' => 'contacts',
])->orderBy('created_at')->get();
$this->assertGreaterThan(0, $tokens->count());
$token = $tokens->last();
$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">', false);
$response->assertSee('<d:response>'.
"<d:href>/dav/addressbooks/{$user->email}/contacts/</d:href>".
'<d:propstat>'.
'<d:prop>'.
"<cs:getctag>http://sabre.io/ns/sync/{$token->id}</cs:getctag>".
"<d:sync-token>http://sabre.io/ns/sync/{$token->id}</d:sync-token>".
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>', false);
}
public function test_carddav_get_me_card()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$user->me_contact_id = $contact->id;
$user->save();
$response = $this->call('PROPFIND', "/dav/addressbooks/{$user->email}", [], [], [],
[
'HTTP_DEPTH' => '1',
'content-type' => 'application/xml; charset=utf-8',
],
"<propfind xmlns='DAV:' xmlns:cs='http://calendarserver.org/ns/'>
<prop>
<cs:me-card />
</prop>
</propfind>"
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee('<d:response>'.
"<d:href>/dav/addressbooks/{$user->email}/contacts/</d:href>".
'<d:propstat>'.
'<d:prop>'.
"<cs:me-card>/dav/addressbooks/{$user->email}/contacts/{$contact->uuid}.vcf</cs:me-card>".
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>', false);
}
public function test_carddav_set_me_card()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$response = $this->call('PROPPATCH', "/dav/addressbooks/{$user->email}/contacts", [], [], [],
[
'content-type' => 'application/xml; charset=utf-8',
],
"<propertyupdate xmlns='DAV:' xmlns:cs='http://calendarserver.org/ns/'>
<set>
<prop>
<cs:me-card>
<href>/dav/addressbooks/{$user->email}/contacts/{$contact->uuid}.vcf</href>
</cs:me-card>
</prop>
</set>
</propertyupdate>"
);
$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">', false);
$response->assertSee('<d:response>'.
"<d:href>/dav/addressbooks/{$user->email}/contacts</d:href>".
'<d:propstat>'.
'<d:prop>'.
'<cs:me-card/>'.
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>', false);
$this->assertDatabaseHas('users', [
'id' => $user->id,
'me_contact_id' => $contact->id,
]);
}
public function test_carddav_getctag_contacts()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$response = $this->call('PROPFIND', "/dav/addressbooks/{$user->email}/contacts/", [], [], [],
[
'HTTP_DEPTH' => '0',
'content-type' => 'application/xml; charset=utf-8',
],
"<propfind xmlns='DAV:' xmlns:cs='http://calendarserver.org/ns/'>
<prop>
<cs:getctag />
<sync-token />
</prop>
</propfind>"
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$tokens = SyncToken::where([
'account_id' => $user->account_id,
'user_id' => $user->id,
'name' => 'contacts',
])->orderBy('created_at')->get();
$this->assertGreaterThan(0, $tokens->count());
$token = $tokens->last();
$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">', false);
$response->assertSee('<d:response>'.
"<d:href>/dav/addressbooks/{$user->email}/contacts/</d:href>".
'<d:propstat>'.
'<d:prop>'.
"<cs:getctag>http://sabre.io/ns/sync/{$token->id}</cs:getctag>".
"<d:sync-token>http://sabre.io/ns/sync/{$token->id}</d:sync-token>".
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>', false);
}
public function test_carddav_sync_collection_with_token()
{
Carbon::setTestNow(Carbon::create(2019, 1, 1, 9, 0, 0));
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
Carbon::setTestNow(Carbon::create(2018, 1, 1, 8, 0, 0));
$token = factory(SyncToken::class)->create([
'account_id' => $user->account_id,
'user_id' => $user->id,
'name' => 'contacts',
'timestamp' => now(),
]);
$response = $this->call('REPORT', "/dav/addressbooks/{$user->email}/contacts/", [], [], [],
[
'content-type' => 'application/xml; charset=utf-8',
],
"<sync-collection xmlns='DAV:'>
<sync-token>http://sabre.io/ns/sync/{$token->id}</sync-token>
<sync-level>1</sync-level>
<prop>
<getetag />
</prop>
</sync-collection>"
);
$response->assertStatus(207);
$token = SyncToken::where([
'account_id' => $user->account_id,
'user_id' => $user->id,
'name' => 'contacts',
])
->orderBy('created_at')
->get()
->last();
$response->assertSee("<d:multistatus xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\" xmlns:card=\"urn:ietf:params:xml:ns:carddav\" xmlns:cal=\"urn:ietf:params:xml:ns:caldav\" xmlns:cs=\"http://calendarserver.org/ns/\">
<d:response>
<d:href>/dav/addressbooks/{$user->email}/contacts/{$contact->uuid}.vcf</d:href>
<d:propstat>
<d:prop>
<d:getetag>&quot;{$this->getEtag($contact)}&quot;</d:getetag>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
<d:sync-token>http://sabre.io/ns/sync/{$token->id}</d:sync-token>
</d:multistatus>", false);
}
public function test_carddav_sync_collection_init()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$response = $this->call('REPORT', "/dav/addressbooks/{$user->email}/contacts/", [], [], [],
[
'content-type' => 'application/xml; charset=utf-8',
],
"<sync-collection xmlns='DAV:'>
<sync-token />
<sync-level>1</sync-level>
<prop>
<getetag />
</prop>
</sync-collection>"
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$tokens = SyncToken::where([
'account_id' => $user->account_id,
'user_id' => $user->id,
'name' => 'contacts',
])->orderBy('created_at')->get();
$this->assertGreaterThan(0, $tokens->count());
$token = $tokens->last();
$response->assertSee("<d:multistatus xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\" xmlns:card=\"urn:ietf:params:xml:ns:carddav\" xmlns:cal=\"urn:ietf:params:xml:ns:caldav\" xmlns:cs=\"http://calendarserver.org/ns/\">
<d:response>
<d:href>/dav/addressbooks/{$user->email}/contacts/{$contact->uuid}.vcf</d:href>
<d:propstat>
<d:prop>
<d:getetag>&quot;{$this->getEtag($contact)}&quot;</d:getetag>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
<d:sync-token>http://sabre.io/ns/sync/{$token->id}</d:sync-token>
</d:multistatus>", false);
}
public function test_carddav_sync_collection_deleted_contact()
{
Carbon::setTestNow(Carbon::create(2019, 1, 1, 9, 0, 0));
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
'deleted_at' => Carbon::create(2019, 3, 1, 9, 0, 0),
]);
Carbon::setTestNow(Carbon::create(2019, 2, 1, 9, 0, 0));
$token = factory(SyncToken::class)->create([
'account_id' => $user->account_id,
'user_id' => $user->id,
'name' => 'contacts',
'timestamp' => now(),
]);
Carbon::setTestNow(Carbon::create(2019, 4, 1, 9, 0, 0));
$response = $this->call('REPORT', "/dav/addressbooks/{$user->email}/contacts/", [], [], [],
[
'content-type' => 'application/xml; charset=utf-8',
],
"<sync-collection xmlns='DAV:'>
<sync-token>http://sabre.io/ns/sync/{$token->id}</sync-token>
<sync-level>1</sync-level>
<prop>
<getetag />
</prop>
</sync-collection>"
);
$response->assertStatus(207);
$token = SyncToken::where([
'account_id' => $user->account_id,
'user_id' => $user->id,
'name' => 'contacts',
])
->orderBy('created_at')
->get()
->last();
$response->assertSee("<d:multistatus xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\" xmlns:card=\"urn:ietf:params:xml:ns:carddav\" xmlns:cal=\"urn:ietf:params:xml:ns:caldav\" xmlns:cs=\"http://calendarserver.org/ns/\">
<d:response>
<d:href>/dav/addressbooks/{$user->email}/contacts/{$contact->uuid}.vcf</d:href>
<d:status>HTTP/1.1 404 Not Found</d:status>
</d:response>
<d:sync-token>http://sabre.io/ns/sync/{$token->id}</d:sync-token>
</d:multistatus>", false);
}
}

176
tests/Api/DAV/CardEtag.php Normal file
View File

@@ -0,0 +1,176 @@
<?php
namespace Tests\Api\DAV;
use App\Models\Contact\Task;
use App\Models\Contact\Contact;
use App\Models\Instance\SpecialDate;
use App\Models\Contact\ContactFieldType;
trait CardEtag
{
protected function getEtag($obj, bool $quotes = false)
{
$data = '';
if ($obj instanceof Contact) {
$data = $this->getCard($obj, true);
} elseif ($obj instanceof SpecialDate) {
$data = $this->getCal($obj, true);
} elseif ($obj instanceof Task) {
$data = $this->getVTodo($obj, true);
}
$etag = sha1($data);
if ($quotes) {
$etag = '"'.$etag.'"';
}
return $etag;
}
protected function getCard(Contact $contact, bool $realFormat = false): string
{
$contact = $contact->refresh();
$url = route('people.show', $contact);
$sabreversion = \Sabre\VObject\Version::VERSION;
$timestamp = $contact->updated_at->format('Ymd\THis\Z');
$data = "BEGIN:VCARD
VERSION:4.0
PRODID:-//Sabre//Sabre VObject {$sabreversion}//EN
UID:{$contact->uuid}
SOURCE:{$url}
FN:{$contact->name}
N:{$contact->last_name};{$contact->first_name};{$contact->middle_name};;
";
if ($contact->gender) {
$data .= "GENDER:{$contact->gender->type}";
$data .= "\n";
}
$picture = $contact->getAvatarURL();
if (! empty($picture)) {
$data .= "PHOTO;VALUE=URI:{$picture}\n";
}
foreach ($contact->addresses as $address) {
$data .= 'ADR:;;';
$data .= $address->place->street.';';
$data .= $address->place->city.';';
$data .= $address->place->province.';';
$data .= $address->place->postal_code.';';
$data .= $address->place->country;
$data .= "\n";
}
foreach ($contact->contactFields as $contactField) {
$type = '';
if ($contactField->labels->count() > 0) {
$type = ';TYPE='.$contactField->labels->map(function ($label) {
return $label->label_i18n ?: $label->label;
})->join(',');
}
switch ($contactField->contactFieldType->type) {
case ContactFieldType::PHONE:
$data .= "TEL$type:{$contactField->data}\n";
break;
case ContactFieldType::EMAIL:
$data .= "EMAIL$type:{$contactField->data}\n";
break;
default:
break;
}
}
$data .= "REV:{$timestamp}\n";
$tags = $contact->getTagsAsString();
if (! empty($tags)) {
$data .= "CATEGORIES:{$tags}\n";
}
$data .= "END:VCARD\n";
if ($realFormat) {
$data = mb_ereg_replace("\n", "\r\n", $data);
}
return $data;
}
protected function getCal(SpecialDate $specialDate, bool $realFormat = false): string
{
$contact = $specialDate->contact;
$url = route('people.show', $contact);
$description = "See {$contact->name}s profile: {$url}";
$description1 = mb_substr($description, 0, 61);
$description2 = mb_substr($description, 61);
$sabreversion = \Sabre\VObject\Version::VERSION;
$timestamp = $specialDate->created_at->format('Ymd\THis\Z');
$start = $specialDate->date->format('Ymd');
$end = $specialDate->date->addDays(1)->format('Ymd');
$data = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Sabre//Sabre VObject {$sabreversion}//EN
CALSCALE:GREGORIAN
BEGIN:VTIMEZONE
TZID:UTC
END:VTIMEZONE
BEGIN:VEVENT
UID:{$specialDate->uuid}
DTSTART;VALUE=DATE:{$start}
DTEND;VALUE=DATE:{$end}
RRULE:FREQ=YEARLY
DTSTAMP:{$timestamp}
CREATED:{$timestamp}
SUMMARY:Birthday of {$contact->name}
ATTACH:{$url}
DESCRIPTION:{$description1}
{$description2}
END:VEVENT
END:VCALENDAR
";
if ($realFormat) {
$data = mb_ereg_replace("\n", "\r\n", $data);
}
return $data;
}
protected function getVTodo(Task $task, bool $realFormat = false): string
{
$sabreversion = \Sabre\VObject\Version::VERSION;
$timestamp = $task->created_at->format('Ymd\THis\Z');
$contact = $task->contact;
$data = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Sabre//Sabre VObject {$sabreversion}//EN
CALSCALE:GREGORIAN
BEGIN:VTIMEZONE
TZID:UTC
END:VTIMEZONE
BEGIN:VTODO
UID:{$task->uuid}
SUMMARY:{$task->title}
DTSTAMP:{$timestamp}
CREATED:{$timestamp}
DESCRIPTION:{$task->description}
";
if ($contact) {
$url = route('people.show', $contact);
$data .= "ATTACH:{$url}
";
}
$data .= 'END:VTODO
END:VCALENDAR
';
if ($realFormat) {
$data = mb_ereg_replace("\n", "\r\n", $data);
}
return $data;
}
}

View File

@@ -0,0 +1,218 @@
<?php
namespace Tests\Api\DAV;
use Tests\ApiTestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class DAVServerTest extends ApiTestCase
{
use DatabaseTransactions;
/**
* @group dav
*/
public function test_dav_propfind_base()
{
$user = $this->signin();
$response = $this->call('PROPFIND', '/dav');
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee('<d:response><d:href>/dav/</d:href>', false);
$response->assertSee('<d:response><d:href>/dav/principals/</d:href>', false);
$response->assertSee('<d:response><d:href>/dav/addressbooks/</d:href>', false);
$response->assertSee('<d:response><d:href>/dav/calendars/</d:href>', false);
}
/**
* @group dav
*/
public function test_dav_propfind_principals()
{
$user = $this->signin();
$response = $this->call('PROPFIND', '/dav/principals');
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee('<d:response><d:href>/dav/principals/</d:href>', false);
$response->assertSee("<d:response><d:href>/dav/principals/{$user->email}/</d:href>", false);
}
/**
* @group dav
*/
public function test_dav_propfind_principals_user()
{
$user = $this->signin();
$response = $this->call('PROPFIND', "/dav/principals/{$user->email}");
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee("<d:response><d:href>/dav/principals/{$user->email}/</d:href>", false);
}
/**
* @group dav
*/
public function test_dav_ensure_browser_plugin_not_enabled()
{
$user = $this->signin();
$response = $this->call('GET', '/dav');
$response->assertStatus(302);
$response->assertHeader('X-Sabre-Version');
$response->assertHeader('Location', route('settings.dav'));
}
/**
* @group dav
*/
public function test_carddav_propfind_groupmemberset()
{
$user = $this->signin();
$response = $this->call('PROPFIND', "/dav/principals/{$user->email}/", [], [], [],
[
'content-type' => 'application/xml; charset=utf-8',
],
'<propfind xmlns="DAV:"
xmlns:CAL="urn:ietf:params:xml:ns:caldav"
xmlns:CARD="urn:ietf:params:xml:ns:carddav">
<prop>
<CARD:addressbook-home-set />
<group-member-set />
</prop>
</propfind>'
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">'.
'<d:response>'.
"<d:href>/dav/principals/{$user->email}/</d:href>".
'<d:propstat>'.
'<d:prop>'.
'<card:addressbook-home-set>'.
"<d:href>/dav/addressbooks/{$user->email}/</d:href>".
'</card:addressbook-home-set>'.
'<d:group-member-set>'.
"<d:href>/dav/principals/{$user->email}/</d:href>".
'</d:group-member-set>'.
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>'.
'</d:multistatus>', false);
}
/**
* @group dav
*/
public function test_carddav_report_propertysearch()
{
$user = $this->signin();
$response = $this->call('REPORT', '/dav/principals/', [], [], [],
[
'HTTP_DEPTH' => '0',
'content-type' => 'application/xml; charset=utf-8',
],
"<principal-property-search xmlns=\"DAV:\">
<property-search>
<match>{$user->name}</match>
<prop>
<displayname/>
</prop>
</property-search>
<prop>
<displayname/>
</prop>
</principal-property-search>"
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">'.
'<d:response>'.
"<d:href>/dav/principals/{$user->email}/</d:href>".
'<d:propstat>'.
'<d:prop>'.
"<d:displayname>{$user->name}</d:displayname>".
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>'.
'</d:multistatus>', false);
}
/**
* @group dav
*/
public function test_caldav_propfind()
{
$user = $this->signin();
$response = $this->call('PROPFIND', '/dav/calendars');
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee('<d:response><d:href>/dav/calendars/</d:href>', false);
$response->assertSee("<d:response><d:href>/dav/calendars/{$user->email}/</d:href>", false);
}
/**
* @group dav
*/
public function test_caldav_propfind_calendars_user()
{
$user = $this->signin();
$response = $this->call('PROPFIND', "/dav/calendars/{$user->email}");
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee("<d:response><d:href>/dav/calendars/{$user->email}/</d:href>", false);
$response->assertSee("<d:response><d:href>/dav/calendars/{$user->email}/birthdays/</d:href>", false);
$response->assertSee("<d:response><d:href>/dav/calendars/{$user->email}/tasks/</d:href>", false);
}
/**
* @group dav
*/
public function test_dav_limit_users_unauthorized()
{
$user = $this->signin();
config(['laravelsabre.users' => 'unauthorized']);
$response = $this->call('PROPFIND', '/dav');
$response->assertStatus(403);
}
/**
* @group dav
*/
public function test_dav_limit_users_authorized()
{
$user = $this->signin();
config(['laravelsabre.users' => $user->email]);
$response = $this->call('PROPFIND', '/dav');
$response->assertStatus(207);
}
}

View File

@@ -0,0 +1,494 @@
<?php
namespace Tests\Api\DAV;
use Tests\ApiTestCase;
use Illuminate\Support\Str;
use App\Models\Account\Photo;
use App\Models\Contact\Contact;
use Illuminate\Http\UploadedFile;
use Sabre\VObject\PHPUnitAssertions;
use Intervention\Image\Facades\Image;
use Illuminate\Support\Facades\Storage;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class VCardContactTest extends ApiTestCase
{
use DatabaseTransactions, CardEtag, PHPUnitAssertions;
/**
* @group dav
*/
public function test_carddav_get_one_contact()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$response = $this->get("/dav/addressbooks/{$user->email}/contacts/{$contact->uuid}.vcf", [
'HTTP_ACCEPT' => 'text/vcard; version=4.0',
]);
$response->assertStatus(200);
$response->assertHeader('X-Sabre-Version');
$this->assertVObjectEqualsVObject($this->getCard($contact, true), $response->getContent());
}
/**
* @group dav
*/
public function test_carddav_put_one_contact()
{
$user = $this->signin();
$response = $this->call('PUT', "/dav/addressbooks/{$user->email}/contacts/single_vcard_stub.vcf", [], [], [],
['content-type' => 'application/xml; charset=utf-8'],
"BEGIN:VCARD\nVERSION:4.0\nFN:John Doe\nN:Doe;John;;;\nEND:VCARD"
);
$response->assertStatus(201);
$response->assertHeader('X-Sabre-Version');
$response->assertHeaderMissing('ETag');
$this->assertDatabaseHas('contacts', [
'account_id' => $user->account_id,
'first_name' => 'John',
'last_name' => 'Doe',
]);
}
/**
* @group dav
*/
public function test_carddav_put_one_contact_with_photo()
{
Storage::fake();
$user = $this->signin();
$image = Image::canvas(1, 1, '#fff')->encode('data-url');
$response = $this->call('PUT', "/dav/addressbooks/{$user->email}/contacts/single_vcard_stub.vcf", [], [], [],
['content-type' => 'application/xml; charset=utf-8'],
"BEGIN:VCARD\nVERSION:4.0\nFN:John Doe\nN:Doe;John;;;\nPHOTO:$image\nEND:VCARD"
);
$response->assertStatus(201);
$response->assertHeader('X-Sabre-Version');
$response->assertHeaderMissing('ETag');
$this->assertDatabaseHas('contacts', [
'account_id' => $user->account_id,
'first_name' => 'John',
'last_name' => 'Doe',
]);
$this->assertDatabaseHas('photos', [
'account_id' => $user->account_id,
]);
$photo = Photo::where(['account_id' => $user->account_id])->first();
Storage::disk('public')->assertExists($photo->new_filename);
}
/**
* @group dav
*/
public function test_carddav_put_one_contact_with_photo_already_set()
{
$user = $this->signin();
$photo = factory(Photo::class)->create([
'account_id' => $user->account_id,
]);
UploadedFile::fake()->image('file.jpg')->storeAs('', 'file.jpg');
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
'avatar_source' => 'photo',
'avatar_photo_id' => $photo->id,
'uuid' => Str::uuid()->toString(),
]);
$image = Image::canvas(1, 1, '#fff')->encode('data-url');
$response = $this->call('PUT', "/dav/addressbooks/{$user->email}/contacts/{$contact->uuid}.vcf", [], [], [],
['content-type' => 'application/xml; charset=utf-8'],
"BEGIN:VCARD\nVERSION:4.0\nFN:John Doe\nN:Doe;John;;;\nPHOTO:$image\nEND:VCARD"
);
$response->assertStatus(204);
$response->assertHeader('X-Sabre-Version');
$response->assertHeaderMissing('ETag');
$this->assertDatabaseHas('contacts', [
'account_id' => $user->account_id,
'first_name' => 'John',
'last_name' => 'Doe',
'avatar_photo_id' => $photo->id,
]);
}
/**
* @group dav
*/
public function test_carddav_put_one_contact_with_photo_and_attributes()
{
Storage::fake();
$user = $this->signin();
$image = base64_encode(Image::canvas(1, 1, '#fff')->encode('jpg'));
$response = $this->call('PUT', "/dav/addressbooks/{$user->email}/contacts/single_vcard_stub.vcf", [], [], [],
['content-type' => 'application/xml; charset=utf-8'],
"BEGIN:VCARD\nVERSION:3.0\nFN:John Doe\nN:Doe;John;;;\nPHOTO;ENCODING=B;TYPE=JPEG:$image\nEND:VCARD"
);
$response->assertStatus(201);
$response->assertHeader('X-Sabre-Version');
$response->assertHeaderMissing('ETag');
$this->assertDatabaseHas('contacts', [
'account_id' => $user->account_id,
'first_name' => 'John',
'last_name' => 'Doe',
]);
$this->assertDatabaseHas('photos', [
'account_id' => $user->account_id,
]);
$photo = Photo::where(['account_id' => $user->account_id])->first();
Storage::disk('public')->assertExists($photo->new_filename);
}
/**
* @group dav
*/
public function test_carddav_update_existing_contact()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$response = $this->call('PUT', "/dav/addressbooks/{$user->email}/contacts/{$contact->uuid}.vcf", [], [], [],
['content-type' => 'application/xml; charset=utf-8'],
"BEGIN:VCARD\nVERSION:4.0\nFN:John Doex\nN:Doex;John;;;\nEND:VCARD"
);
$response->assertStatus(204);
$response->assertHeader('X-Sabre-Version');
$response->assertHeaderMissing('ETag');
$this->assertDatabaseHas('contacts', [
'account_id' => $user->account_id,
'first_name' => 'John',
'last_name' => 'Doex',
]);
}
/**
* @group dav
*/
public function test_carddav_update_existing_contact_if_modified()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$filename = urlencode($contact->uuid.'.vcf');
$response = $this->call('PUT', "/dav/addressbooks/{$user->email}/contacts/{$filename}", [], [], [],
[
'HTTP_If-Modified-Since' => $contact->updated_at->addDays(-1)->toRfc7231String(),
'content-type' => 'application/xml; charset=utf-8',
],
"BEGIN:VCARD\nVERSION:4.0\nFN:John Doex\nN:Doex;John;;;\nEND:VCARD"
);
$response->assertStatus(204);
$response->assertHeader('X-Sabre-Version');
$response->assertHeaderMissing('ETag');
$this->assertDatabaseHas('contacts', [
'account_id' => $user->account_id,
'first_name' => 'John',
'last_name' => 'Doex',
]);
}
/**
* @group dav
*/
public function test_carddav_update_existing_contact_if_modified_not_modified()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$filename = urlencode($contact->uuid.'.vcf');
$response = $this->call('PUT', "/dav/addressbooks/{$user->email}/contacts/{$filename}", [], [], [],
[
'HTTP_If-Modified-Since' => $contact->updated_at->addDays(1)->toRfc7231String(),
'content-type' => 'application/xml; charset=utf-8',
],
"BEGIN:VCARD\nVERSION:4.0\nFN:John Doex\nN:Doex;John;;;\nEND:VCARD"
);
// Not modified
$response->assertStatus(304);
$response->assertHeader('X-Sabre-Version');
// see http://tools.ietf.org/html/rfc2616#section-10.3.5
$response->assertHeaderMissing('Last-Modified');
$response->assertHeaderMissing('ETag');
}
/**
* @group dav
*/
public function test_carddav_update_existing_contact_if_unmodified()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$filename = urlencode($contact->uuid.'.vcf');
$response = $this->call('PUT', "/dav/addressbooks/{$user->email}/contacts/{$filename}", [], [], [],
[
'HTTP_If-Unmodified-Since' => $contact->updated_at->addDays(1)->toRfc7231String(),
'content-type' => 'application/xml; charset=utf-8',
],
"BEGIN:VCARD\nVERSION:4.0\nFN:John Doex\nN:Doex;John;;;\nEND:VCARD"
);
$response->assertStatus(204);
$response->assertHeader('X-Sabre-Version');
$response->assertHeaderMissing('ETag');
$this->assertDatabaseHas('contacts', [
'account_id' => $user->account_id,
'first_name' => 'John',
'last_name' => 'Doex',
]);
}
/**
* @group dav
*/
public function test_carddav_update_existing_contact_if_unmodified_error()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$filename = urlencode($contact->uuid.'.vcf');
$response = $this->call('PUT', "/dav/addressbooks/{$user->email}/contacts/{$filename}", [], [], [],
[
'HTTP_If-Unmodified-Since' => $contact->updated_at->addDays(-1)->toRfc7231String(),
'content-type' => 'application/xml; charset=utf-8',
],
"BEGIN:VCARD\nVERSION:4.0\nFN:John Doex\nN:Doex;John;;;\nEND:VCARD"
);
// PRECONDITION FAILED
$response->assertStatus(412);
$response->assertHeader('X-Sabre-Version');
$sabreversion = \Sabre\DAV\Version::VERSION;
$response->assertSee("<d:error xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\">
<s:sabredav-version>{$sabreversion}</s:sabredav-version>
<s:exception>Sabre\DAV\Exception\PreconditionFailed</s:exception>
<s:message>An If-Unmodified-Since header was specified, but the entity has been changed since the specified date.</s:message>", false);
}
/**
* @group dav
*/
public function test_carddav_update_existing_contact_no_modify()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$filename = urlencode($contact->uuid.'.vcf');
$response = $this->get("/dav/addressbooks/{$user->email}/contacts/{$filename}");
$data = $response->getContent();
$response = $this->call('PUT', "/dav/addressbooks/{$user->email}/contacts/{$filename}", [], [], [],
['content-type' => 'application/xml; charset=utf-8'],
$data
);
$response->assertStatus(204);
$response->assertHeader('X-Sabre-Version');
//$response->assertHeader('ETag'); // etag no more sent
}
public function test_carddav_contacts_report_version4()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$response = $this->call('REPORT', "/dav/addressbooks/{$user->email}/contacts/", [], [], [],
[
'HTTP_DEPTH' => '1',
'content-type' => 'application/xml; charset=utf-8',
],
'<card:addressbook-query xmlns:d="DAV:" xmlns:card="urn:ietf:params:xml:ns:carddav">
<d:prop>
<d:getetag />
<card:address-data content-type="text/vcard" version="4.0" />
</d:prop>
</card:addressbook-query>'
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$vcard = mb_ereg_replace("\n", "&#13;\n", $this->getCard($contact));
$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">'.
'<d:response>'.
"<d:href>/dav/addressbooks/{$user->email}/contacts/{$contact->uuid}.vcf</d:href>".
'<d:propstat>'.
'<d:prop>'.
"<d:getetag>&quot;{$this->getEtag($contact)}&quot;</d:getetag>".
"<card:address-data>{$vcard}</card:address-data>".
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>'.
'</d:multistatus>', false);
}
public function test_carddav_contacts_report_version3()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$response = $this->call('REPORT', "/dav/addressbooks/{$user->email}/contacts/", [], [], [],
[
'HTTP_DEPTH' => '1',
'content-type' => 'application/xml; charset=utf-8',
],
'<card:addressbook-query xmlns:d="DAV:" xmlns:card="urn:ietf:params:xml:ns:carddav">
<d:prop>
<d:getetag />
<card:address-data content-type="text/vcard" version="3.0" />
</d:prop>
</card:addressbook-query>'
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$vcard = mb_ereg_replace('VERSION:4.0', 'VERSION:3.0', $this->getCard($contact));
$vcard = mb_ereg_replace("\n", "&#13;\n", $vcard);
$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">'.
'<d:response>'.
"<d:href>/dav/addressbooks/{$user->email}/contacts/{$contact->uuid}.vcf</d:href>".
'<d:propstat>'.
'<d:prop>'.
"<d:getetag>&quot;{$this->getEtag($contact)}&quot;</d:getetag>".
"<card:address-data>{$vcard}</card:address-data>".
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>'.
'</d:multistatus>', false);
}
public function test_carddav_contacts_report_multiget()
{
$user = $this->signin();
$contact1 = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$contact2 = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$response = $this->call('REPORT', "/dav/addressbooks/{$user->email}/contacts/", [], [], [],
[
'HTTP_DEPTH' => '1',
],
"<card:addressbook-multiget xmlns:d=\"DAV:\" xmlns:card=\"urn:ietf:params:xml:ns:carddav\">
<d:prop>
<d:getetag />
<card:address-data content-type=\"text/vcard\" version=\"4.0\" />
</d:prop>
<d:href>/dav/addressbooks/{$user->email}/contacts/{$contact1->uuid}.vcf</d:href>
<d:href>/dav/addressbooks/{$user->email}/contacts/{$contact2->uuid}.vcf</d:href>
</card:addressbook-multiget>"
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$vcard1 = mb_ereg_replace("\n", "&#13;\n", $this->getCard($contact1));
$vcard2 = mb_ereg_replace("\n", "&#13;\n", $this->getCard($contact2));
$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">'.
'<d:response>'.
"<d:href>/dav/addressbooks/{$user->email}/contacts/{$contact1->uuid}.vcf</d:href>".
'<d:propstat>'.
'<d:prop>'.
"<d:getetag>&quot;{$this->getEtag($contact1)}&quot;</d:getetag>".
"<card:address-data>{$vcard1}</card:address-data>".
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>', false);
$response->assertSee(
'<d:response>'.
"<d:href>/dav/addressbooks/{$user->email}/contacts/{$contact2->uuid}.vcf</d:href>".
'<d:propstat>'.
'<d:prop>'.
"<d:getetag>&quot;{$this->getEtag($contact2)}&quot;</d:getetag>".
"<card:address-data>{$vcard2}</card:address-data>".
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>'.
'</d:multistatus>', false);
}
/**
* @group dav
* @test
*/
public function carddav_delete_one_contact()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$response = $this->call('DELETE', "/dav/addressbooks/{$user->email}/contacts/{$contact->uuid}.vcf");
$response->assertStatus(204);
$response->assertHeader('X-Sabre-Version');
$response->assertHeaderMissing('ETag');
$this->assertDatabaseMissing('contacts', [
'account_id' => $user->account_id,
'id' => $contact->id,
'deleted_at' => null,
]);
}
}

View File

@@ -0,0 +1,138 @@
<?php
namespace Tests\Api\DAV;
use Tests\ApiTestCase;
use Illuminate\Support\Str;
use App\Models\Contact\Contact;
use Sabre\VObject\PHPUnitAssertions;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class VEventBirthdayTest extends ApiTestCase
{
use DatabaseTransactions, CardEtag, PHPUnitAssertions;
/**
* @group dav
*/
public function test_caldav_get_one_birthday()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$specialDate = $contact->setSpecialDate('birthdate', 1983, 03, 04);
$specialDate->uuid = Str::uuid();
$specialDate->save();
$response = $this->get("/dav/calendars/{$user->email}/birthdays/{$specialDate->uuid}.ics");
$response->assertStatus(200);
$response->assertHeader('X-Sabre-Version');
$this->assertVObjectEqualsVObject($this->getCal($specialDate, true), $response->getContent() ?: $response->streamedContent());
}
public function test_caldav_birthdays_report()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$specialDate = $contact->setSpecialDate('birthdate', 1983, 03, 04);
$specialDate->uuid = Str::uuid();
$specialDate->save();
$response = $this->call('REPORT', "/dav/calendars/{$user->email}/birthdays/", [], [], [],
[
'HTTP_DEPTH' => '1',
'content-type' => 'application/xml; charset=utf-8',
],
'<cal:calendar-query xmlns:d="DAV:" xmlns:cal="urn:ietf:params:xml:ns:caldav">
<d:prop>
<d:getetag />
<cal:calendar-data content-type="text/calendar" version="2.0" />
</d:prop>
<cal:filter>
<cal:comp-filter name="VCALENDAR" />
</cal:filter>
</cal:calendar-query>'
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">'.
'<d:response>'.
"<d:href>/dav/calendars/{$user->email}/birthdays/{$specialDate->uuid}.ics</d:href>".
'<d:propstat>'.
'<d:prop>'.
"<d:getetag>&quot;{$this->getEtag($specialDate)}&quot;</d:getetag>".
"<cal:calendar-data>{$this->getCal($specialDate)}</cal:calendar-data>".
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>'.
'</d:multistatus>', false);
}
public function test_caldav_birthdays_report_multiget()
{
$user = $this->signin();
$contact1 = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$specialDate1 = $contact1->setSpecialDate('birthdate', 1983, 03, 04);
$specialDate1->uuid = Str::uuid();
$specialDate1->save();
$contact2 = factory(Contact::class)->create([
'account_id' => $user->account_id,
'firstname' => 'Jane',
]);
$specialDate2 = $contact2->setSpecialDate('birthdate', 1980, 05, 01);
$specialDate2->uuid = Str::uuid();
$specialDate2->save();
$response = $this->call('REPORT', "/dav/calendars/{$user->email}/birthdays/", [], [], [],
[
'HTTP_DEPTH' => '1',
],
"<cal:calendar-multiget xmlns:d=\"DAV:\" xmlns:cal=\"urn:ietf:params:xml:ns:caldav\">
<d:prop>
<d:getetag />
<cal:calendar-data content-type=\"text/calendar\" version=\"2.0\" />
</d:prop>
<d:href>/dav/calendars/{$user->email}/birthdays/{$specialDate1->uuid}.ics</d:href>
<d:href>/dav/calendars/{$user->email}/birthdays/{$specialDate2->uuid}.ics</d:href>
</cal:calendar-multiget>"
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">'.
'<d:response>'.
"<d:href>/dav/calendars/{$user->email}/birthdays/{$specialDate1->uuid}.ics</d:href>".
'<d:propstat>'.
'<d:prop>'.
"<d:getetag>&quot;{$this->getEtag($specialDate1)}&quot;</d:getetag>".
"<cal:calendar-data>{$this->getCal($specialDate1)}</cal:calendar-data>".
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>', false);
$response->assertSee(
'<d:response>'.
"<d:href>/dav/calendars/{$user->email}/birthdays/{$specialDate2->uuid}.ics</d:href>".
'<d:propstat>'.
'<d:prop>'.
"<d:getetag>&quot;{$this->getEtag($specialDate2)}&quot;</d:getetag>".
"<cal:calendar-data>{$this->getCal($specialDate2)}</cal:calendar-data>".
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>'.
'</d:multistatus>', false);
}
}

View File

@@ -0,0 +1,244 @@
<?php
namespace Tests\Api\DAV;
use Carbon\Carbon;
use Tests\ApiTestCase;
use Illuminate\Support\Str;
use App\Models\Contact\Task;
use App\Models\Contact\Contact;
use Sabre\VObject\PHPUnitAssertions;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class VTodoTaskTest extends ApiTestCase
{
use DatabaseTransactions, CardEtag, PHPUnitAssertions;
/**
* @group dav
*/
public function test_caldav_get_one_task()
{
$user = $this->signin();
$task = factory(Task::class)->create([
'account_id' => $user->account_id,
'contact_id' => null,
'created_at' => now(),
'updated_at' => now(),
]);
$response = $this->get("/dav/calendars/{$user->email}/tasks/{$task->uuid}.ics");
$response->assertStatus(200);
$response->assertHeader('X-Sabre-Version');
$this->assertVObjectEqualsVObject($this->getVTodo($task, true), $response->getContent() ?: $response->streamedContent());
}
/**
* @group dav
*/
public function test_caldav_put_one_task()
{
$user = $this->signin();
$uuid = Str::uuid();
$response = $this->call('PUT', "/dav/calendars/{$user->email}/tasks/{$uuid->toString()}.ics", [], [], [],
['content-type' => 'application/xml; charset=utf-8'],
"BEGIN:VCALENDAR
BEGIN:VTODO
UID:{$uuid->toString()}
SUMMARY:title
DESCRIPTION:description
END:VTODO
END:VCALENDAR
"
);
$response->assertStatus(201);
$response->assertHeader('X-Sabre-Version');
$response->assertHeaderMissing('ETag');
$this->assertDatabaseHas('tasks', [
'account_id' => $user->account_id,
'contact_id' => null,
'uuid' => $uuid,
'title' => 'title',
'description' => 'description',
]);
}
/**
* @group dav
*/
public function test_caldav_update_existing_task()
{
$user = $this->signin();
$task = factory(Task::class)->create([
'account_id' => $user->account_id,
'contact_id' => null,
]);
$response = $this->call('PUT', "/dav/calendars/{$user->email}/tasks/{$task->uuid}.ics", [], [], [],
['content-type' => 'application/xml; charset=utf-8'],
"BEGIN:VCALENDAR
BEGIN:VTODO
UID:{$task->uuid}
SUMMARY:new title
DESCRIPTION:new description
END:VTODO
END:VCALENDAR
"
);
$response->assertStatus(204);
$response->assertHeader('X-Sabre-Version');
$response->assertHeaderMissing('ETag');
$this->assertDatabaseHas('tasks', [
'account_id' => $user->account_id,
'uuid' => $task->uuid,
'title' => 'new title',
'description' => 'new description',
]);
}
/**
* @group dav
*/
public function test_caldav_update_task_complete()
{
$user = $this->signin();
$task = factory(Task::class)->create([
'account_id' => $user->account_id,
'contact_id' => null,
]);
$response = $this->call('PUT', "/dav/calendars/{$user->email}/tasks/{$task->uuid}.ics", [], [], [],
['content-type' => 'application/xml; charset=utf-8'],
"BEGIN:VCALENDAR
BEGIN:VTODO
UID:{$task->uuid}
SUMMARY:{$task->title}
DESCRIPTION:{$task->description}
STATUS:COMPLETED
COMPLETED:20190121T182800Z
END:VTODO
END:VCALENDAR
"
);
$response->assertStatus(204);
$response->assertHeader('X-Sabre-Version');
$response->assertHeaderMissing('ETag');
$this->assertDatabaseHas('tasks', [
'account_id' => $user->account_id,
'uuid' => $task->uuid,
'completed' => true,
'completed_at' => Carbon::create(2019, 01, 21, 18, 28, 00),
]);
}
public function test_caldav_tasks_report()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$task = factory(Task::class)->create([
'account_id' => $user->account_id,
'created_at' => now(),
]);
$response = $this->call('REPORT', "/dav/calendars/{$user->email}/tasks/", [], [], [],
[
'HTTP_DEPTH' => '1',
'content-type' => 'application/xml; charset=utf-8',
],
'<cal:calendar-query xmlns:d="DAV:" xmlns:cal="urn:ietf:params:xml:ns:caldav">
<d:prop>
<d:getetag />
<cal:calendar-data content-type="text/calendar" version="2.0" />
</d:prop>
<cal:filter>
<cal:comp-filter name="VCALENDAR" />
</cal:filter>
</cal:calendar-query>'
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$peopleurl = route('people.show', $contact);
$sabreversion = \Sabre\VObject\Version::VERSION;
$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">'.
'<d:response>'.
"<d:href>/dav/calendars/{$user->email}/tasks/{$task->uuid}.ics</d:href>".
'<d:propstat>'.
'<d:prop>'.
"<d:getetag>&quot;{$this->getEtag($task)}&quot;</d:getetag>".
"<cal:calendar-data>{$this->getVTodo($task)}</cal:calendar-data>".
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>'.
'</d:multistatus>', false);
}
public function test_caldav_tasks_report_multiget()
{
$user = $this->signin();
$task1 = factory(Task::class)->create([
'account_id' => $user->account_id,
'created_at' => now(),
]);
$task2 = factory(Task::class)->create([
'account_id' => $user->account_id,
'created_at' => now(),
]);
$response = $this->call('REPORT', "/dav/calendars/{$user->email}/tasks/", [], [], [],
[
'HTTP_DEPTH' => '1',
],
"<cal:calendar-multiget xmlns:d=\"DAV:\" xmlns:cal=\"urn:ietf:params:xml:ns:caldav\">
<d:prop>
<d:getetag />
<cal:calendar-data content-type=\"text/calendar\" version=\"2.0\" />
</d:prop>
<d:href>/dav/calendars/{$user->email}/tasks/{$task1->uuid}.ics</d:href>
<d:href>/dav/calendars/{$user->email}/tasks/{$task2->uuid}.ics</d:href>
</cal:calendar-multiget>"
);
$response->assertStatus(207);
$response->assertHeader('X-Sabre-Version');
$response->assertSee('<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">'.
'<d:response>'.
"<d:href>/dav/calendars/{$user->email}/tasks/{$task1->uuid}.ics</d:href>".
'<d:propstat>'.
'<d:prop>'.
"<d:getetag>&quot;{$this->getEtag($task1)}&quot;</d:getetag>".
"<cal:calendar-data>{$this->getVTodo($task1)}</cal:calendar-data>".
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>', false);
$response->assertSee(
'<d:response>'.
"<d:href>/dav/calendars/{$user->email}/tasks/{$task2->uuid}.ics</d:href>".
'<d:propstat>'.
'<d:prop>'.
"<d:getetag>&quot;{$this->getEtag($task2)}&quot;</d:getetag>".
"<cal:calendar-data>{$this->getVTodo($task2)}</cal:calendar-data>".
'</d:prop>'.
'<d:status>HTTP/1.1 200 OK</d:status>'.
'</d:propstat>'.
'</d:response>'.
'</d:multistatus>', false);
}
}