2424namespace OCA \Deck \Service \Importer \Systems ;
2525
2626use OCA \Deck \Service \Importer \BoardImportService ;
27- use OCP \IL10N ;
28- use OCP \IURLGenerator ;
2927use OCP \IUser ;
3028use OCP \IUserManager ;
3129use OCP \Server ;
3634 */
3735class DeckJsonServiceTest extends \Test \TestCase {
3836 private DeckJsonService $ service ;
39- /** @var IURLGenerator|MockObject */
40- private $ urlGenerator ;
4137 /** @var IUserManager|MockObject */
4238 private $ userManager ;
43- /** @var IL10N */
44- private $ l10n ;
4539 public function setUp (): void {
4640 $ this ->userManager = $ this ->createMock (IUserManager::class);
47- $ this ->urlGenerator = $ this ->createMock (IURLGenerator::class);
48- $ this ->l10n = $ this ->createMock (IL10N ::class);
4941 $ this ->service = new DeckJsonService (
5042 $ this ->userManager ,
51- $ this ->urlGenerator ,
52- $ this ->l10n
5343 );
5444 }
5545
@@ -61,6 +51,59 @@ public function testGetBoardWithNoName() {
6151 }
6252
6353 public function testGetBoardWithSuccess () {
54+ $ importService = $ this ->setUpImportService ();
55+
56+ $ boards = $ this ->service ->getBoards ();
57+ $ importService ->setData ($ boards [0 ]);
58+ $ actual = $ this ->service ->getBoard ();
59+ $ this ->assertEquals ('My test board ' , $ actual ->getTitle ());
60+ $ this ->assertEquals ('admin ' , $ actual ->getOwner ());
61+ $ this ->assertEquals ('e0ed31 ' , $ actual ->getColor ());
62+ }
63+
64+ public function testGetCards () {
65+ $ importService = $ this ->setUpImportService ();
66+
67+ $ boards = $ this ->service ->getBoards ();
68+ $ importService ->setData ($ boards [0 ]);
69+
70+ $ importService ->getBoard ()->setId (1 );
71+
72+ $ this ->service ->getLabels ();
73+
74+ $ stacks = $ this ->service ->getStacks ();
75+ $ stackId = 1 ;
76+ foreach ($ stacks as $ code => $ stack ) {
77+ $ stack ->setId ($ stackId ++);
78+ $ this ->service ->updateStack ($ code , $ stack );
79+ }
80+
81+ $ cards = $ this ->service ->getCards ();
82+
83+ $ this ->assertCount (6 , $ cards );
84+
85+ // Card 114 (title "1") has a done value set in the fixture
86+ $ card114 = $ cards [114 ];
87+ $ this ->assertEquals ('1 ' , $ card114 ->getTitle ());
88+ $ this ->assertInstanceOf (\DateTime::class, $ card114 ->getDone ());
89+ $ this ->assertEquals ('2023-07-18T10:00:00+00:00 ' , $ card114 ->getDone ()->format (\DateTime::ATOM ));
90+ $ this ->assertEquals ('2050-07-24T22:00:00+00:00 ' , $ card114 ->getDuedate ()->format (\DateTime::ATOM ));
91+ $ this ->assertFalse ($ card114 ->getArchived ());
92+ $ this ->assertEquals ('admin ' , $ card114 ->getOwner ());
93+
94+ // Card 115 (title "2") has no done value in the fixture
95+ $ card115 = $ cards [115 ];
96+ $ this ->assertEquals ('2 ' , $ card115 ->getTitle ());
97+ $ this ->assertNull ($ card115 ->getDone ());
98+
99+ // Card 119 (title "6") — from stack B, no done value
100+ $ card119 = $ cards [119 ];
101+ $ this ->assertEquals ('6 ' , $ card119 ->getTitle ());
102+ $ this ->assertNull ($ card119 ->getDone ());
103+ $ this ->assertEquals ('# Test description ' . "\n\n" . 'Hello world ' , $ card119 ->getDescription ());
104+ }
105+
106+ private function setUpImportService (): BoardImportService {
64107 $ importService = Server::get (BoardImportService::class);
65108
66109 $ data = json_decode (file_get_contents (__DIR__ . '/../../../../data/deck.json ' ));
@@ -77,11 +120,6 @@ public function testGetBoardWithSuccess() {
77120
78121 $ this ->service ->setImportService ($ importService );
79122
80- $ boards = $ this ->service ->getBoards ();
81- $ importService ->setData ($ boards [0 ]);
82- $ actual = $ this ->service ->getBoard ();
83- $ this ->assertEquals ('My test board ' , $ actual ->getTitle ());
84- $ this ->assertEquals ('admin ' , $ actual ->getOwner ());
85- $ this ->assertEquals ('e0ed31 ' , $ actual ->getColor ());
123+ return $ importService ;
86124 }
87125}
0 commit comments