3
require_once __DIR__ . '/KolabTestBase.php';
6
* @author Jason M. Felice <jason.m.felice@gmail.com>
8
* @subpackage UnitTests
10
class Turba_ToDo_KolabTest extends Turba_KolabTestBase {
17
public function setUp()
19
$this->markTestIncomplete('Convert to use Horde_Test.');
20
$this->prepareTurba();
22
$this->_kolab = new Kolab();
25
function testBug5476()
27
/* Open our addressbook */
28
$this->_kolab->open('INBOX/Contacts', 1);
32
'given-name' => 'test',
33
'last-name' => 'test',
34
'full-name' => 'test test',
38
$this->_kolab->_storage->save($object);
42
'given-name' => 'test2',
43
'last-name' => 'test2',
44
'full-name' => 'test2 test2',
48
$this->_kolab->_storage->save($object);
50
// Check that the driver can be created
51
$turba = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create('wrobel@example.org');
52
//$this->assertNoError($turba);
54
$result = $turba->search(array(), array('last-name'));
55
$this->assertNoError($result);
56
$this->assertEquals(2, count($result));
58
$turba = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create('INBOX%2Ftest2');
59
$result = $turba->search(array(), array('last-name'));
61
$this->assertEquals(0, count($result));
66
/* Open our addressbook */
67
$this->_kolab->open('INBOX/Contacts', 1);
71
'given-name' => 'photo',
72
'last-name' => 'photo',
73
'full-name' => 'photo photo',
75
'phototype' => 'image/jpeg',
79
$turba = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create('wrobel@example.org');
80
//$this->assertNoError($turba);
82
$this->assertNoError($turba->_add($object));
84
$list = Kolab_List::singleton();
85
$share = &$list->getByShare('INBOX/Contacts', 'contact');
86
$data = &$share->getData();
87
$object = $data->getObject('1');
88
$this->assertTrue(isset($object['_attachments'][$object['picture']]));
89
$attachment = $data->getAttachment($object['_attachments'][$object['picture']]['key']);
90
$this->assertEquals("abcd\n", $attachment);
93
function testAttachments()
95
/* Open our addressbook */
96
$this->_kolab->open('INBOX/Contacts', 1);
100
'given-name' => 'atc',
101
'last-name' => 'atc',
102
'full-name' => 'atc atc',
106
$turba = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create('wrobel@example.org');
107
//$this->assertNoError($turba);
109
$this->assertNoError($turba->_add($object));
111
$contact = $turba->getObject('a');
112
$this->assertNoError($contact);
114
$list = Kolab_List::singleton();
115
$share = &$list->getByShare('INBOX/Contacts', 'contact');
116
$data = &$share->getData();
118
$atc1 = Horde_Util::getTempFile();
119
$fh = fopen($atc1, 'w');
123
$info = array('tmp_name' => $atc1,
124
'name' => 'test.txt');
125
$this->assertNoError($contact->addFile($info));
127
$objects = $data->getObjects();
128
$this->assertEquals(1, count($objects));
129
$object = $data->getObject('a');
130
$this->assertTrue(isset($object['_attachments']));
131
$this->assertEquals(1, count($object['_attachments']));
132
$this->assertEquals(1, count($object['link-attachment']));
133
$this->assertContains('test.txt', $object['link-attachment']);
134
$attachment = $data->getAttachment($object['_attachments']['test.txt']['key']);
135
$this->assertEquals("test\n", $attachment);
137
$atc1 = Horde_Util::getTempFile();
138
$fh = fopen($atc1, 'w');
142
$info = array('tmp_name' => $atc1,
143
'name' => 'test.txt');
144
$this->assertNoError($contact->addFile($info));
146
$objects = $data->getObjects();
147
$this->assertEquals(1, count($objects));
148
$object = $data->getObject('a');
149
$this->assertTrue(isset($object['_attachments']));
150
$this->assertEquals(2, count($object['_attachments']));
151
$this->assertEquals(2, count($object['link-attachment']));
152
$this->assertContains('test[1].txt', $object['link-attachment']);
153
$attachment = $data->getAttachment($object['_attachments']['test[1].txt']['key']);
154
$this->assertEquals("hhhh\n", $attachment);
156
$atc1 = Horde_Util::getTempFile();
157
$fh = fopen($atc1, 'w');
158
fwrite($fh, 'dummy');
161
$info = array('tmp_name' => $atc1,
162
'name' => 'dummy.txt');
163
$this->assertNoError($contact->addFile($info));
165
$objects = $data->getObjects();
166
$this->assertEquals(1, count($objects));
167
$object = $data->getObject('a');
168
$this->assertTrue(isset($object['_attachments']));
169
$this->assertEquals(3, count($object['_attachments']));
170
$this->assertEquals(3, count($object['link-attachment']));
171
$this->assertContains('dummy.txt', $object['link-attachment']);
172
$attachment = $data->getAttachment($object['_attachments']['dummy.txt']['key']);
173
$this->assertEquals("dummy\n", $attachment);
175
$this->assertError($contact->deleteFile('doesnotexist.txt'), "Unable to delete VFS file.");
177
$this->assertNoError($contact->deleteFile('test[1].txt'));
179
$objects = $data->getObjects();
180
$this->assertEquals(1, count($objects));
181
$object = $data->getObject('a');
182
$this->assertTrue(!isset($object['_attachments']['test[1].txt']));
183
$this->assertEquals(2, count($object['_attachments']));
184
$this->assertEquals(2, count($object['link-attachment']));
185
$this->assertNotContains('test[1].txt', $object['link-attachment']);
187
$files = $contact->listFiles();
188
$this->assertNoError($files);
190
$this->assertContains('test.txt', array_keys($files));
191
$this->assertContains('dummy.txt', array_keys($files));
193
$this->assertNoError($contact->deleteFiles());
195
$objects = $data->getObjects();
196
$this->assertEquals(1, count($objects));
197
$object = $data->getObject('a');
198
$this->assertTrue(!isset($object['_attachments']['test.txt']));
199
$this->assertTrue(!isset($object['_attachments']));
200
$this->assertTrue(!isset($object['link-attachment']));