3737use OCA \Deck \Db \Stack ;
3838use OCA \Deck \Db \StackMapper ;
3939use OCA \Deck \Model \CardDetails ;
40+ use OCA \Deck \Model \OptionalNullableValue ;
4041use OCA \Deck \Notification \NotificationHelper ;
4142use OCA \Deck \StatusException ;
4243use OCA \Deck \Validators \CardServiceValidator ;
@@ -368,7 +369,7 @@ public function testUpdate() {
368369 ->method ('find ' )
369370 ->with (234 )
370371 ->willReturn ($ stack );
371- $ actual = $ this ->cardService ->update (123 , 'newtitle ' , 234 , 'text ' , 'admin ' , 'foo ' , 999 , '2017-01-01 00:00:00 ' , null , null , null , null , 'ffffff ' );
372+ $ actual = $ this ->cardService ->update (123 , 'newtitle ' , 234 , 'text ' , 'admin ' , 'foo ' , 999 , '2017-01-01 00:00:00 ' , null , null , null , null , new OptionalNullableValue ( 'ffffff ' ) );
372373 $ this ->assertEquals ('newtitle ' , $ actual ->getTitle ());
373374 $ this ->assertEquals (234 , $ actual ->getStackId ());
374375 $ this ->assertEquals ('text ' , $ actual ->getType ());
@@ -378,6 +379,104 @@ public function testUpdate() {
378379 $ this ->assertEquals ('ffffff ' , $ actual ->getColor ());
379380 }
380381
382+ public function testUpdateKeepsColorWhenOmitted () {
383+ $ card = Card::fromParams ([
384+ 'title ' => 'Card title ' ,
385+ 'archived ' => 'false ' ,
386+ 'stackId ' => 234 ,
387+ 'color ' => '00ff00 ' ,
388+ ]);
389+ $ card ->setColor ('ff0000 ' );
390+ $ stack = Stack::fromParams ([
391+ 'id ' => 234 ,
392+ 'boardId ' => 1337 ,
393+ ]);
394+ $ this ->cardMapper ->expects ($ this ->once ())->method ('find ' )->willReturn ($ card );
395+ $ this ->cardMapper ->expects ($ this ->once ())->method ('update ' )->willReturnCallback (function ($ c ) {
396+ $ c ->setId (1 );
397+ return $ c ;
398+ });
399+ $ this ->stackMapper ->expects ($ this ->once ())
400+ ->method ('find ' )
401+ ->with (234 )
402+ ->willReturn ($ stack );
403+ $ actual = $ this ->cardService ->update (123 , 'newtitle ' , 234 , 'text ' , 'admin ' , 'foo ' , 999 , '2017-01-01 00:00:00 ' , null , null , null , null , null );
404+ $ this ->assertSame ('ff0000 ' , $ actual ->getColor ());
405+ }
406+
407+ public function testUpdateClearsColorWhenNullProvided () {
408+ $ card = Card::fromParams ([
409+ 'title ' => 'Card title ' ,
410+ 'archived ' => 'false ' ,
411+ 'stackId ' => 234 ,
412+ 'color ' => '00ff00 ' ,
413+ ]);
414+ $ card ->setColor ('ff0000 ' );
415+ $ stack = Stack::fromParams ([
416+ 'id ' => 234 ,
417+ 'boardId ' => 1337 ,
418+ ]);
419+ $ this ->cardMapper ->expects ($ this ->once ())->method ('find ' )->willReturn ($ card );
420+ $ this ->cardMapper ->expects ($ this ->once ())->method ('update ' )->willReturnCallback (function ($ c ) {
421+ $ c ->setId (1 );
422+ return $ c ;
423+ });
424+ $ this ->stackMapper ->expects ($ this ->once ())
425+ ->method ('find ' )
426+ ->with (234 )
427+ ->willReturn ($ stack );
428+ $ actual = $ this ->cardService ->update (123 , 'newtitle ' , 234 , 'text ' , 'admin ' , 'foo ' , 999 , '2017-01-01 00:00:00 ' , null , null , null , null , new OptionalNullableValue (null ));
429+ $ this ->assertNull ($ actual ->getColor ());
430+ }
431+
432+ public function testUpdateClearsColorWhenEmptyStringProvided () {
433+ $ card = Card::fromParams ([
434+ 'title ' => 'Card title ' ,
435+ 'archived ' => 'false ' ,
436+ 'stackId ' => 234 ,
437+ 'color ' => '00ff00 ' ,
438+ ]);
439+ $ card ->setColor ('ff0000 ' );
440+ $ stack = Stack::fromParams ([
441+ 'id ' => 234 ,
442+ 'boardId ' => 1337 ,
443+ ]);
444+ $ this ->cardMapper ->expects ($ this ->once ())->method ('find ' )->willReturn ($ card );
445+ $ this ->cardMapper ->expects ($ this ->once ())->method ('update ' )->willReturnCallback (function ($ c ) {
446+ $ c ->setId (1 );
447+ return $ c ;
448+ });
449+ $ this ->stackMapper ->expects ($ this ->once ())
450+ ->method ('find ' )
451+ ->with (234 )
452+ ->willReturn ($ stack );
453+ $ actual = $ this ->cardService ->update (123 , 'newtitle ' , 234 , 'text ' , 'admin ' , 'foo ' , 999 , '2017-01-01 00:00:00 ' , null , null , null , null , new OptionalNullableValue ('' ));
454+ $ this ->assertNull ($ actual ->getColor ());
455+ }
456+
457+ public function testUpdateSetsColor () {
458+ $ card = Card::fromParams ([
459+ 'title ' => 'Card title ' ,
460+ 'archived ' => 'false ' ,
461+ 'stackId ' => 234 ,
462+ ]);
463+ $ stack = Stack::fromParams ([
464+ 'id ' => 234 ,
465+ 'boardId ' => 1337 ,
466+ ]);
467+ $ this ->cardMapper ->expects ($ this ->once ())->method ('find ' )->willReturn ($ card );
468+ $ this ->cardMapper ->expects ($ this ->once ())->method ('update ' )->willReturnCallback (function ($ c ) {
469+ $ c ->setId (1 );
470+ return $ c ;
471+ });
472+ $ this ->stackMapper ->expects ($ this ->once ())
473+ ->method ('find ' )
474+ ->with (234 )
475+ ->willReturn ($ stack );
476+ $ actual = $ this ->cardService ->update (123 , 'newtitle ' , 234 , 'text ' , 'admin ' , 'foo ' , 999 , '2017-01-01 00:00:00 ' , null , null , null , null , new OptionalNullableValue ('00ff00 ' ));
477+ $ this ->assertSame ('00ff00 ' , $ actual ->getColor ());
478+ }
479+
381480 public function testUpdateWithStartdate () {
382481 $ card = Card::fromParams ([
383482 'title ' => 'Card title ' ,
0 commit comments