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