addResponse('https://test', Http::response(), null, 'OPTIONS')
->addResponse('https://test', Http::response(null, 200, ['Dav' => 'test']), null, 'OPTIONS')
->addResponse('https://test', Http::response(null, 200, ['Dav' => ' test ']), null, 'OPTIONS')
->fake();
$client = $tester->client();
$result = $client->options();
$this->assertEquals([], $result);
$result = $client->options();
$this->assertEquals(['test'], $result);
$result = $client->options();
$this->assertEquals(['test'], $result);
$tester->assert();
}
/** @test */
public function it_get_serviceurl()
{
$tester = (new DavTester())
->serviceUrl()
->fake();
$client = $tester->client();
$result = $client->getServiceUrl();
$tester->assert();
$this->assertEquals('https://test/dav/', $result);
}
/** @test */
public function it_get_non_standard_serviceurl()
{
$tester = (new DavTester())
->addResponse('https://test/.well-known/carddav', Http::response(), null, 'GET')
->addResponse('https://test/.well-known/carddav', Http::response(), null, 'GET')
->nonStandardServiceUrl()
->fake();
$client = $tester->client();
$result = $client->getServiceUrl();
$tester->assert();
$this->assertEquals('https://test/dav/', $result);
}
/** @test */
public function it_get_non_standard_serviceurl2()
{
$tester = (new DavTester())
->addResponse('https://test/.well-known/carddav', Http::response(null, 404), null, 'GET')
->addResponse('https://test/.well-known/carddav', Http::response(null, 404), null, 'GET')
->nonStandardServiceUrl()
->fake();
$client = $tester->client();
$result = $client->getServiceUrl();
$tester->assert();
$this->assertEquals('https://test/dav/', $result);
}
/** @test */
public function it_fail_non_standard()
{
$tester = (new DavTester())
->addResponse('https://test/.well-known/carddav', Http::response(null, 500), null, 'GET')
->fake();
$client = $tester->client();
$this->expectException(RequestException::class);
$client->getServiceUrl();
}
/** @test */
public function it_get_base_uri()
{
$tester = (new DavTester())
->fake();
$client = $tester->client();
$result = $client->path();
$this->assertEquals('https://test', $result);
$result = $client->path('xxx');
$this->assertEquals('https://test/xxx', $result);
}
/** @test */
public function it_set_base_uri()
{
$tester = (new DavTester())
->fake();
$client = $tester->client();
$result = $client->setBaseUri('https://new')
->path();
$this->assertEquals('https://new', $result);
}
/** @test */
public function it_call_propfind()
{
$tester = (new DavTester())
->addResponse('https://test', Http::response(DavTester::multistatusHeader().
''.
'href'.
''.
''.
'value'.
''.
'HTTP/1.1 200 OK'.
''.
''.
''), ''."\n".
''.
''.
''.
''.
"\n", 'PROPFIND')
->fake();
$client = $tester->client();
$result = $client->propFind(['{DAV:}test']);
$tester->assert();
$this->assertEquals([
'{DAV:}test' => 'value',
], $result);
}
/** @test */
public function it_get_property()
{
$tester = (new DavTester())
->addResponse('https://test/test', Http::response(DavTester::multistatusHeader().
''.
'href'.
''.
''.
'value'.
''.
'HTTP/1.1 200 OK'.
''.
''.
''), ''."\n".
''.
''.
''.
''.
"\n", 'PROPFIND')
->fake();
$client = $tester->client();
$result = $client->getProperty('{DAV:}test', 'https://test/test');
$tester->assert();
$this->assertEquals('value', $result);
}
/** @test */
public function it_get_supported_report()
{
$tester = (new DavTester('https://test/dav'))
->addResponse('https://test/dav', Http::response(DavTester::multistatusHeader().
''.
'/dav'.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
''.
'HTTP/1.1 200 OK'.
''.
''.
''), ''."\n".
''.
''.
''.
''.
"\n", 'PROPFIND')
->fake();
$client = $tester->client();
$result = $client->getSupportedReportSet();
$tester->assert();
$this->assertEquals(['{DAV:}test1', '{DAV:}test2'], $result);
}
/** @test */
public function it_sync_collection()
{
$tester = (new DavTester())
->addResponse('https://test', Http::response(DavTester::multistatusHeader().
''.
'href'.
''.
''.
'"00001-abcd1"'.
'value'.
''.
'HTTP/1.1 200 OK'.
''.
''.
'"00001-abcd1"'.
''), ''."\n".
''.
''.
'1'.
''.
''.
''.
"\n", 'REPORT')
->fake();
$client = $tester->client();
$result = $client->syncCollection(['{DAV:}test'], '');
$tester->assert();
$this->assertEquals([
'href' => [
'properties' => [
200 => [
'{DAV:}getetag' => '"00001-abcd1"',
'{DAV:}test' => 'value',
],
],
'status' => '200',
],
'synctoken' => '"00001-abcd1"',
], $result);
}
/** @test */
public function it_sync_collection_with_synctoken()
{
$tester = (new DavTester())
->addResponse('https://test', Http::response(DavTester::multistatusHeader().
''.
'href'.
''.
''.
'"00001-abcd1"'.
'value'.
''.
'HTTP/1.1 200 OK'.
''.
''.
'"00001-abcd1"'.
''), ''."\n".
''.
'"00000-abcd0"'.
'1'.
''.
''.
''.
"\n", 'REPORT')
->fake();
$client = $tester->client();
$result = $client->syncCollection(['{DAV:}test'], '"00000-abcd0"');
$tester->assert();
$this->assertEquals([
'href' => [
'properties' => [
200 => [
'{DAV:}getetag' => '"00001-abcd1"',
'{DAV:}test' => 'value',
],
],
'status' => '200',
],
'synctoken' => '"00001-abcd1"',
], $result);
}
/** @test */
public function it_run_addressbook_multiget_report()
{
$tester = (new DavTester())
->addResponse('https://test', Http::response(DavTester::multistatusHeader().
''.
'href'.
''.
''.
'"00001-abcd1"'.
'value'.
''.
'HTTP/1.1 200 OK'.
''.
''.
''), ''."\n".
''.
''.
''.
''.
'https://test/contacts/1'.
"\n", 'REPORT')
->fake();
$client = $tester->client();
$result = $client->addressbookMultiget(['{DAV:}test'], ['https://test/contacts/1']);
$this->assertEquals([
'href' => [
'properties' => [
200 => [
'{DAV:}getetag' => '"00001-abcd1"',
'{DAV:}test' => 'value',
],
],
'status' => '200',
],
], $result);
$tester->assert();
}
/** @test */
public function it_run_addressbook_query_report()
{
$tester = (new DavTester())
->addResponse('https://test', Http::response(DavTester::multistatusHeader().
''.
'href'.
''.
''.
'"00001-abcd1"'.
'value'.
''.
'HTTP/1.1 200 OK'.
''.
''.
''), ''."\n".
''.
''.
''.
''.
"\n", 'REPORT')
->fake();
$client = $tester->client();
$result = $client->addressbookQuery(['{DAV:}test']);
$tester->assert();
$this->assertEquals([
'href' => [
'properties' => [
200 => [
'{DAV:}getetag' => '"00001-abcd1"',
'{DAV:}test' => 'value',
],
],
'status' => '200',
],
], $result);
}
/** @test */
public function it_run_proppatch()
{
$tester = (new DavTester())
->addResponse('https://test', Http::response(DavTester::multistatusHeader().
''.
'href'.
''.
''.
'value'.
''.
'HTTP/1.1 200 OK'.
''.
''.
'', 207), ''."\n".
''."\n".
' '."\n".
' '."\n".
' value'."\n".
' '."\n".
' '."\n".
"\n", 'PROPPATCH')
->fake();
$client = $tester->client();
$result = $client->propPatch(['{DAV:}test' => 'value']);
$tester->assert();
$this->assertTrue($result);
}
/** @test */
public function it_run_proppatch_error()
{
$tester = (new DavTester())
->addResponse('https://test', Http::response(DavTester::multistatusHeader().
''.
'href'.
''.
''.
'x'.
''.
'HTTP/1.1 405 OK'.
''.
''.
''.
'x'.
''.
'HTTP/1.1 500 OK'.
''.
''.
'', 207), ''."\n".
''."\n".
' '."\n".
' '."\n".
' value'."\n".
' value'."\n".
' '."\n".
' '."\n".
"\n", 'PROPPATCH')
->fake();
$client = $tester->client();
$this->expectException(DavClientException::class);
$this->expectExceptionMessage('PROPPATCH failed. The following properties errored: {DAV:}test (405), {DAV:}excerpt (500)');
$client->propPatch([
'{DAV:}test' => 'value',
'{DAV:}excerpt' => 'value',
]);
}
}