xref: /plugin/davcal/vendor/sabre/dav/tests/Sabre/CardDAV/TestUtil.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\CardDAV;
4*a1a3b679SAndreas Boehler
5*a1a3b679SAndreas Boehleruse PDO;
6*a1a3b679SAndreas Boehler
7*a1a3b679SAndreas Boehlerclass TestUtil {
8*a1a3b679SAndreas Boehler
9*a1a3b679SAndreas Boehler    static function getBackend() {
10*a1a3b679SAndreas Boehler
11*a1a3b679SAndreas Boehler        $backend = new Backend\PDO(self::getSQLiteDB());
12*a1a3b679SAndreas Boehler        return $backend;
13*a1a3b679SAndreas Boehler
14*a1a3b679SAndreas Boehler    }
15*a1a3b679SAndreas Boehler
16*a1a3b679SAndreas Boehler    static function getSQLiteDB() {
17*a1a3b679SAndreas Boehler
18*a1a3b679SAndreas Boehler        if (file_exists(SABRE_TEMPDIR . '/testdb.sqlite'))
19*a1a3b679SAndreas Boehler            unlink(SABRE_TEMPDIR . '/testdb.sqlite');
20*a1a3b679SAndreas Boehler
21*a1a3b679SAndreas Boehler        $pdo = new PDO('sqlite:' . SABRE_TEMPDIR . '/testdb.sqlite');
22*a1a3b679SAndreas Boehler        $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
23*a1a3b679SAndreas Boehler
24*a1a3b679SAndreas Boehler        // Yup this is definitely not 'fool proof', but good enough for now.
25*a1a3b679SAndreas Boehler        $queries = explode(';', file_get_contents(__DIR__ . '/../../../examples/sql/sqlite.addressbooks.sql'));
26*a1a3b679SAndreas Boehler        foreach($queries as $query) {
27*a1a3b679SAndreas Boehler            $pdo->exec($query);
28*a1a3b679SAndreas Boehler        }
29*a1a3b679SAndreas Boehler        // Inserting events through a backend class.
30*a1a3b679SAndreas Boehler        $backend = new Backend\PDO($pdo);
31*a1a3b679SAndreas Boehler        $addressbookId = $backend->createAddressBook(
32*a1a3b679SAndreas Boehler            'principals/user1',
33*a1a3b679SAndreas Boehler            'UUID-123467',
34*a1a3b679SAndreas Boehler            array(
35*a1a3b679SAndreas Boehler                '{DAV:}displayname' => 'user1 addressbook',
36*a1a3b679SAndreas Boehler                '{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'AddressBook description',
37*a1a3b679SAndreas Boehler            )
38*a1a3b679SAndreas Boehler        );
39*a1a3b679SAndreas Boehler        $backend->createAddressBook(
40*a1a3b679SAndreas Boehler            'principals/user1',
41*a1a3b679SAndreas Boehler            'UUID-123468',
42*a1a3b679SAndreas Boehler            array(
43*a1a3b679SAndreas Boehler                '{DAV:}displayname' => 'user1 addressbook2',
44*a1a3b679SAndreas Boehler                '{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'AddressBook description',
45*a1a3b679SAndreas Boehler            )
46*a1a3b679SAndreas Boehler        );
47*a1a3b679SAndreas Boehler        $backend->createCard($addressbookId, 'UUID-2345', self::getTestCardData());
48*a1a3b679SAndreas Boehler        return $pdo;
49*a1a3b679SAndreas Boehler
50*a1a3b679SAndreas Boehler    }
51*a1a3b679SAndreas Boehler
52*a1a3b679SAndreas Boehler    static function getTestCardData($type = 1) {
53*a1a3b679SAndreas Boehler
54*a1a3b679SAndreas Boehler        $addressbookData = 'BEGIN:VCARD
55*a1a3b679SAndreas BoehlerVERSION:3.0
56*a1a3b679SAndreas BoehlerPRODID:-//Acme Inc.//RoadRunner 1.0//EN
57*a1a3b679SAndreas BoehlerFN:Wile E. Coyote
58*a1a3b679SAndreas BoehlerN:Coyote;Wile;Erroll;;
59*a1a3b679SAndreas BoehlerORG:Acme Inc.
60*a1a3b679SAndreas BoehlerUID:39A6B5ED-DD51-4AFE-A683-C35EE3749627
61*a1a3b679SAndreas BoehlerREV:2012-06-20T07:00:39+00:00
62*a1a3b679SAndreas BoehlerEND:VCARD';
63*a1a3b679SAndreas Boehler
64*a1a3b679SAndreas Boehler        return $addressbookData;
65*a1a3b679SAndreas Boehler
66*a1a3b679SAndreas Boehler    }
67*a1a3b679SAndreas Boehler
68*a1a3b679SAndreas Boehler}
69