1010 * @author Morris Jobke <hey@morrisjobke.de>
1111 * @author Roeland Jago Douma <roeland@famdouma.nl>
1212 * @author Thomas Müller <thomas.mueller@tmit.eu>
13+ * @author Matthias Heinisch <nextcloud@matthiasheinisch.de>
1314 *
1415 * @license AGPL-3.0
1516 *
3536use OCP \IURLGenerator ;
3637use Sabre \VObject \Component \VCard ;
3738use Sabre \VObject \Property \Text ;
39+ //use Sabre\VObject\Property\;
3840use Test \TestCase ;
3941
4042class AddressBookImplTest extends TestCase {
@@ -199,7 +201,7 @@ public function testUpdate() {
199201 ->willReturn (['carddata ' => 'data ' ]);
200202 $ addressBookImpl ->expects ($ this ->once ())->method ('readCard ' )
201203 ->with ('data ' )->willReturn ($ this ->vCard );
202- $ this ->vCard ->expects ($ this ->exactly (count ($ properties )))
204+ $ this ->vCard ->expects ($ this ->exactly (count ($ properties )- 1 ))
203205 ->method ('createProperty ' );
204206 $ this ->backend ->expects ($ this ->never ())->method ('createCard ' );
205207 $ this ->backend ->expects ($ this ->once ())->method ('updateCard ' );
@@ -209,6 +211,41 @@ public function testUpdate() {
209211 $ this ->assertTrue ($ addressBookImpl ->createOrUpdate ($ properties ));
210212 }
211213
214+ public function testUpdateWithTypes () {
215+ $ uid = 'uid ' ;
216+ $ uri = 'bla.vcf ' ;
217+ $ properties = ['URI ' => $ uri , 'UID ' => $ uid , 'FN ' => 'John Doe ' , 'ADR ' => [['type ' => 'HOME ' , 'value ' => ';;street;city;;;country ' ]]];
218+ $ vCard = new vCard ;
219+ $ textProperty = $ vCard ->createProperty ('KEY ' ,'value ' );
220+
221+ /** @var \PHPUnit\Framework\MockObject\MockObject | AddressBookImpl $addressBookImpl */
222+ $ addressBookImpl = $ this ->getMockBuilder (AddressBookImpl::class)
223+ ->setConstructorArgs (
224+ [
225+ $ this ->addressBook ,
226+ $ this ->addressBookInfo ,
227+ $ this ->backend ,
228+ $ this ->urlGenerator ,
229+ ]
230+ )
231+ ->setMethods (['vCard2Array ' , 'createUid ' , 'createEmptyVCard ' , 'readCard ' ])
232+ ->getMock ();
233+
234+ $ this ->backend ->expects ($ this ->once ())->method ('getCard ' )
235+ ->with ($ this ->addressBookInfo ['id ' ], $ uri )
236+ ->willReturn (['carddata ' => 'data ' ]);
237+ $ addressBookImpl ->expects ($ this ->once ())->method ('readCard ' )
238+ ->with ('data ' )->willReturn ($ this ->vCard );
239+ $ this ->vCard ->method ('createProperty ' )->willReturn ($ textProperty );
240+ $ this ->vCard ->expects ($ this ->exactly (count ($ properties )-1 ))
241+ ->method ('createProperty ' );
242+ $ this ->vCard ->expects ($ this ->once ())->method ('remove ' )
243+ ->with ('ADR ' );
244+ $ this ->vCard ->expects ($ this ->once ())->method ('add ' );
245+
246+ $ addressBookImpl ->createOrUpdate ($ properties );
247+ }
248+
212249 /**
213250 * @dataProvider dataTestGetPermissions
214251 *
0 commit comments