1<?php
2
3namespace Sabre\CardDAV;
4
5use Sabre\DAV\PropFind;
6use Sabre\HTTP;
7
8class SogoStripContentTypeTest extends \Sabre\DAVServerTest {
9
10    protected $setupCardDAV = true;
11    protected $carddavAddressBooks = [
12        [
13            'id'           => 1,
14            'uri'          => 'book1',
15            'principaluri' => 'principals/user1',
16        ],
17    ];
18    protected $carddavCards = [
19        1 => [
20            'card1.vcf' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD",
21        ],
22    ];
23
24    function testDontStrip() {
25
26        $result = $this->server->getProperties('addressbooks/user1/book1/card1.vcf', ['{DAV:}getcontenttype']);
27        $this->assertEquals([
28            '{DAV:}getcontenttype' => 'text/vcard; charset=utf-8'
29        ], $result);
30
31    }
32    function testStrip() {
33
34        $this->server->httpRequest = HTTP\Sapi::createFromServerArray([
35            'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 Lightning/1.2.1',
36        ]);
37        $result = $this->server->getProperties('addressbooks/user1/book1/card1.vcf', ['{DAV:}getcontenttype']);
38        $this->assertEquals([
39            '{DAV:}getcontenttype' => 'text/x-vcard'
40        ], $result);
41
42    }
43    function testDontTouchOtherMimeTypes() {
44
45        $this->server->httpRequest = new HTTP\Request('GET', '/addressbooks/user1/book1/card1.vcf', [
46            'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 Lightning/1.2.1',
47        ]);
48
49        $propFind = new PropFind('hello', ['{DAV:}getcontenttype']);
50        $propFind->set('{DAV:}getcontenttype', 'text/plain');
51        $this->carddavPlugin->propFindLate($propFind, new \Sabre\DAV\SimpleCollection('foo'));
52        $this->assertEquals('text/plain', $propFind->get('{DAV:}getcontenttype'));
53
54    }
55
56}
57