summaryrefslogtreecommitdiffstats
path: root/Dockerfile
Commit message (Expand)AuthorAgeFilesLines
* Use shadowing script for docker (#17846)zeripath2021-12-011-2/+1
* chmod executables when copying to the docker (#17423)zeripath2021-10-251-0/+2
* build with go1.17 (#16707)techknowlogick2021-08-171-1/+1
* revert to use alpine 3.13 (#16451)techknowlogick2021-07-161-2/+2
* Alpine 3.14 released (#16170)techknowlogick2021-07-071-2/+2
* Remove random password in Dockerfiles (#15362)Martin Michaelis2021-04-291-1/+1
* go1.16 (#14783)techknowlogick2021-02-281-1/+1
* Add environment-to-ini to docker image (#14762)Kyle D2021-02-231-0/+4
* upgrade to alpine 3.13 (#14343)techknowlogick2021-01-201-2/+2
* Revert "Dockerfile: Support socat use cases (#13208)" (#13369)Antoine GIRARD2020-10-311-1/+0
* Dockerfile: Support socat use cases (#13208)Begley Brothers (Development)2020-10-211-0/+1
* Update Dockerfile (#12922)Antoine GIRARD2020-09-271-2/+1
* go1.15 (#12475)techknowlogick2020-08-131-1/+1
* Fix missing CGO_EXTRA_FLAGS build arg for docker (#11782)Cirno the Strongest2020-06-061-0/+1
* Alpine 3.12 (#11720)techknowlogick2020-06-031-2/+2
* Add gnupg to Dockerfile (#11365)Cirno the Strongest2020-05-101-1/+2
* go 1.14 (#10467)techknowlogick2020-03-201-1/+1
* Frontend build improvements, fix Fomantic build (#10576)silverwind2020-03-031-1/+1
* alpine 3.11 (#9440)techknowlogick2019-12-261-2/+2
* Fix latest docker image haven't include static files. (#9252)Lunny Xiao2019-12-051-1/+1
* Add Node.js build dep, remove built js/css files (#9114)silverwind2019-12-051-1/+1
* use go 1.13 (#8088)techknowlogick2019-09-121-1/+1
* build: use GOPROXY and disable download on some steps (#7745)Antoine GIRARD2019-08-051-0/+3
* Alpine 3.10 (#7256)techknowlogick2019-06-201-2/+2
* [docker] drop the docker Makefile from the image (#6507)Jakob Ackermann2019-05-051-1/+1
* Use golang 1.12 to build in dockerfile (#6285)techknowlogick2019-03-081-1/+1
* Upgrade alpine to 3.9 (#5909)techknowlogick2019-02-051-2/+2
* Upgrade alpine to 3.8 (#5423)techknowlogick2018-11-281-2/+2
* Update golang version in Dockerfile (#5246)Stanislav2018-11-011-1/+1
* Update build tags for sqlite_unlock_notify (#5144)Mura Li2018-10-231-1/+1
* Fix docker build (#4358)techknowlogick2018-07-041-1/+1
* Add missing path in the Docker app.ini template (#2181)Tao Wang2018-07-031-0/+1
* Docker multi-stage (#2927)Antoine GIRARD2018-03-121-9/+29
* Update alpine to 3.7 (#3121)Antoine GIRARD2017-12-101-1/+1
* Docker multi-arch base (#1985)Antoine GIRARD2017-11-161-1/+0
* Add environment variable support for Docker image (#2201)Tao Wang2017-10-311-0/+1
* Add maintainer label for docker file (#2658)Bo-Yi Wu2017-10-051-1/+2
* Dockerfile: Updated alpine image to 3.6. (#2486)Jon Davies2017-09-131-1/+1
* Use /dev/urandom to create random password (#2298)Pontus Leitzler2017-08-131-1/+1
* Revert "Reduce number of layer" (#2086)Lunny Xiao2017-06-301-5/+5
* Reduce number of layer (#2078)Dryusdan2017-06-301-5/+5
* Realy don't cache apk indexDaniel Wendler (@cassandra)2017-05-091-1/+1
* Upgrade alpine to v3.5 in Dockerfile (#1633)Peter Dave Hello2017-05-051-1/+1
* Refactor DockerfilePeter Dave Hello2017-04-291-6/+3
* Fixing multiple docker issues (#386)Thomas Boerger2016-12-151-4/+2
* Copy gitea binary to docker from correct path (#325)Thomas Boerger2016-12-011-1/+1
* Added -S flag to addgroup command within DockerfilesThomas Boerger2016-11-281-1/+1
* Replaced edge with 3.4 for the alpine base imageThomas Boerger2016-11-281-1/+1
* Replaced shadow with addgroup and adduserThomas Boerger2016-11-281-8/+5
* Use su-exec instead of gosu, much smallerThomas Boerger2016-11-281-3/+3
8045/stable28 Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/CardDAV/ConverterTest.php
blob: 9ab0631e93ac93645fcfffd570c5b15071849ce7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?php
/**
 * @copyright Copyright (c) 2016, ownCloud, Inc.
 *
 * @author Joas Schilling <coding@schilljs.com>
 * @author Roeland Jago Douma <roeland@famdouma.nl>
 * @author Thomas Müller <thomas.mueller@tmit.eu>
 *
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

namespace OCA\DAV\Tests\unit\CardDAV;

use OC\Accounts\AccountManager;
use OCA\DAV\CardDAV\Converter;
use OCP\IDBConnection;
use OCP\IImage;
use OCP\IUser;
use PHPUnit_Framework_MockObject_MockObject;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Test\TestCase;

class ConverterTest extends  TestCase {

	/** @var  AccountManager | PHPUnit_Framework_MockObject_MockObject */
	private $accountManager;

	/** @var  EventDispatcher | PHPUnit_Framework_MockObject_MockObject */
	private $eventDispatcher;

	/** @var  IDBConnection | PHPUnit_Framework_MockObject_MockObject */
	private $databaseConnection;

	public function setUp() {
		parent::setUp();
		$this->databaseConnection = $this->getMockBuilder(IDBConnection::class)->getMock();
		$this->eventDispatcher = $this->getMockBuilder(EventDispatcher::class)
			->disableOriginalConstructor()->getMock();
		$this->accountManager = $this->getMockBuilder(AccountManager::class)
			->disableOriginalConstructor()->getMock();
	}

	public function getAccountManager(IUser $user) {
		$accountManager = $this->getMockBuilder(AccountManager::class)
			->disableOriginalConstructor()->getMock();
		$accountManager->expects($this->any())->method('getUser')->willReturn(
			[
				AccountManager::PROPERTY_DISPLAYNAME =>
					[
						'value' => $user->getDisplayName(),
						'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
					],
				AccountManager::PROPERTY_ADDRESS =>
					[
						'value' => '',
						'scope' => AccountManager::VISIBILITY_PRIVATE,
					],
				AccountManager::PROPERTY_WEBSITE =>
					[
						'value' => '',
						'scope' => AccountManager::VISIBILITY_PRIVATE,
					],
				AccountManager::PROPERTY_EMAIL =>
					[
						'value' => $user->getEMailAddress(),
						'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
					],
				AccountManager::PROPERTY_AVATAR =>
					[
						'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY
					],
				AccountManager::PROPERTY_PHONE =>
					[
						'value' => '',
						'scope' => AccountManager::VISIBILITY_PRIVATE,
					],
				AccountManager::PROPERTY_TWITTER =>
					[
						'value' => '',
						'scope' => AccountManager::VISIBILITY_PRIVATE,
					],
			]
		);

		return $accountManager;
	}

	/**
	 * @dataProvider providesNewUsers
	 */
	public function testCreation($expectedVCard, $displayName = null, $eMailAddress = null, $cloudId = null) {
		$user = $this->getUserMock($displayName, $eMailAddress, $cloudId);
		$accountManager = $this->getAccountManager($user);

		$converter = new Converter($accountManager);
		$vCard = $converter->createCardFromUser($user);
		if ($expectedVCard !== null) {
			$this->assertInstanceOf('Sabre\VObject\Component\VCard', $vCard);
			$cardData = $vCard->jsonSerialize();
			$this->compareData($expectedVCard, $cardData);

		} else {
			$this->assertSame($expectedVCard, $vCard);
		}

	}

	protected function compareData($expected, $data) {
		foreach ($expected as $key => $value) {
			$found = false;
			foreach ($data[1] as $d) {
				if($d[0] === $key && $d[3] === $value) {
					$found = true;
					break;
				}
			}
			if (!$found) $this->assertTrue(false, 'Expected data: ' . $key . ' not found.');
		}
	}

	public function providesNewUsers() {
		return [
			[
				null
			],
			[
				null,
				null,
				'foo@bar.net'
			],
			[
				[
					'cloud' => 'foo@cloud.net',
					'email' => 'foo@bar.net',
					'photo' => 'MTIzNDU2Nzg5',
				],
				null,
				'foo@bar.net',
				'foo@cloud.net'
			],
			[
				[
					'cloud' => 'foo@cloud.net',
					'email' => 'foo@bar.net',
					'fn' => 'Dr. Foo Bar',
					'photo' => 'MTIzNDU2Nzg5',
				],
				"Dr. Foo Bar",
				"foo@bar.net",
				'foo@cloud.net'
			],
			[
				[
					'cloud' => 'foo@cloud.net',
					'fn' => 'Dr. Foo Bar',
					'photo' => 'MTIzNDU2Nzg5',
				],
				"Dr. Foo Bar",
				null,
				"foo@cloud.net"
			],
			[
				[
					'cloud' => 'foo@cloud.net',
					'fn' => 'Dr. Foo Bar',
					'photo' => 'MTIzNDU2Nzg5',
				],
				'Dr. Foo Bar',
				'',
				'foo@cloud.net'
			],
		];
	}

	/**
	 * @dataProvider providesNames
	 * @param $expected
	 * @param $fullName
	 */
	public function testNameSplitter($expected, $fullName) {

		$converter = new Converter($this->accountManager);
		$r = $converter->splitFullName($fullName);
		$r = implode(';', $r);
		$this->assertEquals($expected, $r);
	}

	public function providesNames() {
		return [
				['Sauron;;;;', 'Sauron'],
				['Baggins;Bilbo;;;', 'Bilbo Baggins'],
				['Tolkien;John;Ronald Reuel;;', 'John Ronald Reuel Tolkien'],
		];
	}

	/**
	 * @param $displayName
	 * @param $eMailAddress
	 * @param $cloudId
	 * @return IUser | PHPUnit_Framework_MockObject_MockObject
	 */
	protected function getUserMock($displayName, $eMailAddress, $cloudId) {
		$image0 = $this->getMockBuilder(IImage::class)->disableOriginalConstructor()->getMock();
		$image0->method('mimeType')->willReturn('image/jpeg');
		$image0->method('data')->willReturn('123456789');
		$user = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
		$user->method('getUID')->willReturn('12345');
		$user->method('getDisplayName')->willReturn($displayName);
		$user->method('getEMailAddress')->willReturn($eMailAddress);
		$user->method('getCloudId')->willReturn($cloudId);
		$user->method('getAvatarImage')->willReturn($image0);
		return $user;
	}
}