@@ -286,4 +286,90 @@ public function rollBack(): void {
286286 $ newTable ->getSort ()
287287 );
288288 }
289+
290+ public function testImportRemapsViewCardSources (): void {
291+ $ user = $ this ->createMock (IUser::class);
292+ $ importSource = $ this ->createMock (IImportSource::class);
293+ $ output = new NullOutput ();
294+
295+ $ user ->method ('getUID ' )->willReturn ('user1 ' );
296+ $ importSource ->method ('getMigratorVersion ' )->willReturn (1 );
297+
298+ $ tableData = [
299+ 'id ' => 1 ,
300+ 'title ' => 'Test ' ,
301+ ];
302+ $ columns = [
303+ ['id ' => 10 , 'tableId ' => 1 ],
304+ ['id ' => 11 , 'tableId ' => 1 ],
305+ ];
306+ $ views = [
307+ [
308+ 'tableId ' => 1 ,
309+ 'title ' => 'Nested settings ' ,
310+ 'columnSettings ' => [['columnId ' => 10 , 'order ' => 0 ]],
311+ 'viewSettings ' => [
312+ 'cardBackgroundSource ' => 10 ,
313+ 'cardTitleSource ' => 11 ,
314+ ],
315+ ],
316+ [
317+ 'tableId ' => 1 ,
318+ 'title ' => 'Legacy settings ' ,
319+ 'columnSettings ' => [['columnId ' => 11 , 'order ' => 0 ]],
320+ 'cardBackgroundSource ' => 11 ,
321+ 'cardTitleSource ' => 10 ,
322+ ],
323+ ];
324+
325+ $ importSource ->method ('getFileContents ' )->willReturnCallback (static function (string $ file ) use ($ tableData , $ columns , $ views ): string {
326+ return match ($ file ) {
327+ 'tables.json ' => json_encode ([$ tableData ]),
328+ 'columns.json ' => json_encode ($ columns ),
329+ 'views.json ' => json_encode ($ views ),
330+ default => json_encode ([]),
331+ };
332+ });
333+
334+ $ newTable = new Table ();
335+ $ newTable ->setId (100 );
336+ $ this ->tableService ->method ('importTable ' )->willReturn ($ newTable );
337+ $ this ->columnService ->method ('importColumn ' )->willReturnOnConsecutiveCalls (20 , 21 );
338+ $ this ->rowService ->method ('importRow ' )->willReturn (1 );
339+
340+ $ this ->tableMapper ->method ('getDBConnection ' )->willReturn (new class {
341+ public function beginTransaction (): void {
342+ }
343+ public function commit (): void {
344+ }
345+ public function rollBack (): void {
346+ }
347+ });
348+
349+ $ importedViews = [];
350+ $ this ->viewService ->expects ($ this ->exactly (2 ))
351+ ->method ('importView ' )
352+ ->with (
353+ $ this ->identicalTo (100 ),
354+ $ this ->callback (static function (array $ view ) use (&$ importedViews ): bool {
355+ $ importedViews [] = $ view ;
356+ return true ;
357+ }),
358+ $ this ->identicalTo ('user1 ' ),
359+ );
360+
361+ $ this ->migrator ->import ($ user , $ importSource , $ output );
362+
363+ $ this ->assertSame (
364+ [
365+ 'cardBackgroundSource ' => 20 ,
366+ 'cardTitleSource ' => 21 ,
367+ ],
368+ $ importedViews [0 ]['viewSettings ' ]
369+ );
370+ $ this ->assertSame (20 , $ importedViews [0 ]['columnSettings ' ][0 ]['columnId ' ]);
371+ $ this ->assertSame (21 , $ importedViews [1 ]['cardBackgroundSource ' ]);
372+ $ this ->assertSame (20 , $ importedViews [1 ]['cardTitleSource ' ]);
373+ $ this ->assertSame (21 , $ importedViews [1 ]['columnSettings ' ][0 ]['columnId ' ]);
374+ }
289375}
0 commit comments