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->assertEquals($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_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(" {$sabreversion} Sabre\DAV\Exception\PreconditionFailed An If-Unmodified-Since header was specified, but the entity has been changed since the specified date."); } /** * @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'); } 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', ], ' ' ); $response->assertStatus(207); $response->assertHeader('X-Sabre-Version'); $peopleurl = route('people.show', $contact); $sabreversion = \Sabre\VObject\Version::VERSION; $response->assertSee(''. ''. "/dav/addressbooks/{$user->email}/contacts/{$contact->uuid}.vcf". ''. ''. ""{$this->getEtag($contact)}"". "BEGIN:VCARD \n". "VERSION:4.0 \n". "PRODID:-//Sabre//Sabre VObject {$sabreversion}//EN \n". "UID:{$contact->uuid} \n". "SOURCE:{$peopleurl} \n". "FN:John Doe \n". "N:Doe;John;;; \n". "GENDER:O; \n". "END:VCARD \n". ''. ''. 'HTTP/1.1 200 OK'. ''. ''. ''); } 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', ], ' ' ); $response->assertStatus(207); $response->assertHeader('X-Sabre-Version'); $peopleurl = route('people.show', $contact); $sabreversion = \Sabre\VObject\Version::VERSION; $response->assertSee(''. ''. "/dav/addressbooks/{$user->email}/contacts/{$contact->uuid}.vcf". ''. ''. ""{$this->getEtag($contact)}"". "BEGIN:VCARD \n". "VERSION:3.0 \n". "PRODID:-//Sabre//Sabre VObject {$sabreversion}//EN \n". "UID:{$contact->uuid} \n". "SOURCE:{$peopleurl} \n". "FN:John Doe \n". "N:Doe;John;;; \n". "GENDER:O; \n". "END:VCARD \n". ''. ''. 'HTTP/1.1 200 OK'. ''. ''. ''); } 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', ], " /dav/addressbooks/{$user->email}/contacts/{$contact1->uuid}.vcf /dav/addressbooks/{$user->email}/contacts/{$contact2->uuid}.vcf " ); $response->assertStatus(207); $response->assertHeader('X-Sabre-Version'); $people1url = route('people.show', $contact1); $people2url = route('people.show', $contact2); $sabreversion = \Sabre\VObject\Version::VERSION; $response->assertSee(''. ''. "/dav/addressbooks/{$user->email}/contacts/{$contact1->uuid}.vcf". ''. ''. ""{$this->getEtag($contact1)}"". "BEGIN:VCARD \n". "VERSION:4.0 \n". "PRODID:-//Sabre//Sabre VObject {$sabreversion}//EN \n". "UID:{$contact1->uuid} \n". "SOURCE:{$people1url} \n". "FN:John Doe \n". "N:Doe;John;;; \n". "GENDER:O; \n". "END:VCARD \n". ''. ''. 'HTTP/1.1 200 OK'. ''. ''); $response->assertSee( ''. "/dav/addressbooks/{$user->email}/contacts/{$contact2->uuid}.vcf". ''. ''. ""{$this->getEtag($contact2)}"". "BEGIN:VCARD \n". "VERSION:4.0 \n". "PRODID:-//Sabre//Sabre VObject {$sabreversion}//EN \n". "UID:{$contact2->uuid} \n". "SOURCE:{$people2url} \n". "FN:John Doe \n". "N:Doe;John;;; \n". "GENDER:O; \n". "END:VCARD \n". ''. ''. 'HTTP/1.1 200 OK'. ''. ''. ''); } }