|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) 2013 Thomas Tanghus ([email protected]) |
|
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
5
|
|
|
* later. |
|
6
|
|
|
* See the COPYING-README file. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
use Test\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class Test_VObjects |
|
13
|
|
|
* @group DB |
|
14
|
|
|
*/ |
|
15
|
|
|
class Test_VObjects extends TestCase { |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
public static function setUpBeforeClass() { |
|
18
|
|
|
parent::setUpBeforeClass(); |
|
19
|
|
|
\Sabre\VObject\Component\VCard::$propertyMap['CATEGORIES'] = 'OCA\Contacts\VObject\GroupProperty'; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
View Code Duplication |
public function testCrappyVCard() { |
|
|
|
|
|
|
23
|
|
|
$cardData = file_get_contents(__DIR__ . '/../data/test3.vcf'); |
|
24
|
|
|
$obj = \Sabre\VObject\Reader::read( |
|
25
|
|
|
$cardData, |
|
26
|
|
|
\Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES |
|
27
|
|
|
); |
|
28
|
|
|
$obj->validate($obj::REPAIR); |
|
29
|
|
|
|
|
30
|
|
|
$this->assertEquals('2.1', (string)$obj->VERSION); |
|
31
|
|
|
$this->assertEquals('Adèle Fermée', (string)$obj->FN); |
|
32
|
|
|
$this->assertEquals('Fermée;Adèle;;;', (string)$obj->N); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
View Code Duplication |
public function testEscapedParameters() { |
|
|
|
|
|
|
36
|
|
|
$cardData = file_get_contents(__DIR__ . '/../data/test6.vcf'); |
|
37
|
|
|
$obj = \Sabre\VObject\Reader::read( |
|
38
|
|
|
$cardData, |
|
39
|
|
|
\Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES |
|
40
|
|
|
); |
|
41
|
|
|
$obj->validate($obj::REPAIR); |
|
42
|
|
|
|
|
43
|
|
|
$this->assertEquals('3.0', (string)$obj->VERSION); |
|
44
|
|
|
$this->assertEquals('Parameters;Escaped;;;', (string)$obj->N); |
|
45
|
|
|
$this->assertEquals('TEL;TYPE=PREF\,WORK\,VOICE:123456789' . "\r\n", $obj->TEL->serialize()); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testGroupProperty() { |
|
49
|
|
|
$arr = array( |
|
50
|
|
|
'Home', |
|
51
|
|
|
'work', |
|
52
|
|
|
'Friends, Family', |
|
53
|
|
|
); |
|
54
|
|
|
|
|
55
|
|
|
$vcard = new \OCA\Contacts\VObject\VCard(); |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
$property = $vcard->createProperty('CATEGORIES'); |
|
|
|
|
|
|
58
|
|
|
$property->setParts($arr); |
|
59
|
|
|
|
|
60
|
|
|
// Test parsing and serializing |
|
61
|
|
|
$this->assertEquals('Home,work,Friends\, Family', $property->getValue()); |
|
62
|
|
|
$this->assertEquals('CATEGORIES:Home,work,Friends\, Family' . "\r\n", $property->serialize()); |
|
63
|
|
|
$this->assertEquals(3, count($property->getParts())); |
|
64
|
|
|
|
|
65
|
|
|
// Test add |
|
66
|
|
|
$property->addGroup('Coworkers'); |
|
67
|
|
|
$this->assertTrue($property->hasGroup('coworkers')); |
|
68
|
|
|
$this->assertEquals(4, count($property->getParts())); |
|
69
|
|
|
$this->assertEquals('Home,work,Friends\, Family,Coworkers', $property->getValue()); |
|
70
|
|
|
|
|
71
|
|
|
// Test remove |
|
72
|
|
|
$this->assertTrue($property->hasGroup('Friends, fAmIlY')); |
|
73
|
|
|
$property->removeGroup('Friends, fAmIlY'); |
|
74
|
|
|
$this->assertEquals(3, count($property->getParts())); |
|
75
|
|
|
$parts = $property->getParts(); |
|
76
|
|
|
$this->assertEquals('Coworkers', $parts[2]); |
|
77
|
|
|
|
|
78
|
|
|
// Test rename |
|
79
|
|
|
$property->renameGroup('work', 'Work'); |
|
80
|
|
|
$parts = $property->getParts(); |
|
81
|
|
|
$this->assertEquals('Work', $parts[1]); |
|
82
|
|
|
//$this->assertEquals(true, false); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
This check marks class names that have not been written in CamelCase.
In CamelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database connector becomes
DatabaseConnector.