Test_VObjects::testCrappyVCard()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 12
Ratio 100 %
Metric Value
dl 12
loc 12
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
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 {
0 ignored issues
show
Coding Style introduced by
The class Test_VObjects is not named in CamelCase.

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.

Loading history...
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() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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();
0 ignored issues
show
Bug introduced by
The call to VCard::__construct() misses a required argument $name.

This check looks for function calls that miss required arguments.

Loading history...
56
57
		$property = $vcard->createProperty('CATEGORIES');
0 ignored issues
show
Bug introduced by
The method createProperty() does not exist on OCA\Contacts\VObject\VCard. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
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