@@ -17,20 +17,21 @@ interface IDatasource {
1717use OCA \Tables \Db \Column ;
1818use OCA \Tables \Db \Row2 ;
1919use OCA \Tables \Service \ColumnService ;
20+ use OCA \Tables \Service \RelationService ;
2021use OCA \Tables \Service \RowService ;
2122use OCA \Tables \Service \TableService ;
2223use OCA \Tables \Service \ViewService ;
2324use OCP \IL10N ;
2425use PHPUnit \Framework \MockObject \MockObject ;
2526use PHPUnit \Framework \TestCase ;
26- use Psr \Log \LoggerInterface ;
2727
2828final class AnalyticsDatasourceTest extends TestCase {
2929 private IL10N |MockObject $ l10n ;
3030 private TableService |MockObject $ tableService ;
3131 private ViewService |MockObject $ viewService ;
3232 private ColumnService |MockObject $ columnService ;
3333 private RowService |MockObject $ rowService ;
34+ private RelationService |MockObject $ relationService ;
3435 private AnalyticsDatasource $ datasource ;
3536
3637 protected function setUp (): void {
@@ -42,14 +43,15 @@ protected function setUp(): void {
4243 $ this ->viewService = $ this ->createMock (ViewService::class);
4344 $ this ->columnService = $ this ->createMock (ColumnService::class);
4445 $ this ->rowService = $ this ->createMock (RowService::class);
46+ $ this ->relationService = $ this ->createMock (RelationService::class);
4547
4648 $ this ->datasource = new AnalyticsDatasource (
4749 $ this ->l10n ,
48- $ this ->createMock (LoggerInterface::class),
4950 $ this ->tableService ,
5051 $ this ->viewService ,
5152 $ this ->columnService ,
5253 $ this ->rowService ,
54+ $ this ->relationService ,
5355 'user1 ' ,
5456 );
5557 }
@@ -148,6 +150,44 @@ public function testReadDataFormatsDisplayValuesForAnalytics(): void {
148150 ], $ result ['data ' ]);
149151 }
150152
153+ public function testReadDataFormatsRelationValuesForAnalytics (): void {
154+ $ this ->columnService
155+ ->expects ($ this ->once ())
156+ ->method ('findAllByTable ' )
157+ ->with (123 , 'user1 ' )
158+ ->willReturn ([
159+ $ this ->createColumn (1 , 'Name ' , 'text ' ),
160+ $ this ->createColumn (2 , 'Customer ' , 'relation ' ),
161+ ]);
162+
163+ $ this ->relationService
164+ ->expects ($ this ->once ())
165+ ->method ('getRelationData ' )
166+ ->willReturn ([
167+ 42 => ['id ' => 42 , 'label ' => 'Acme Corp ' ],
168+ 43 => ['id ' => 43 , 'label ' => 'Globex ' ],
169+ ]);
170+
171+ $ row = new Row2 ();
172+ $ row ->setData ([
173+ ['columnId ' => 1 , 'value ' => 'Order 1 ' ],
174+ ['columnId ' => 2 , 'value ' => 42 ],
175+ ]);
176+
177+ $ this ->rowService
178+ ->expects ($ this ->once ())
179+ ->method ('findAllByTable ' )
180+ ->with (123 , 'user1 ' , null , null )
181+ ->willReturn ([$ row ]);
182+
183+ $ result = $ this ->datasource ->readData ([
184+ 'tableId ' => '123 ' ,
185+ 'user_id ' => 'user1 ' ,
186+ ]);
187+
188+ self ::assertSame ([['Order 1 ' , 'Acme Corp ' , 1 ]], $ result ['data ' ]);
189+ }
190+
151191 public function testReadDataFormatsDefaultValuesForAnalytics (): void {
152192 $ numberColumn = $ this ->createColumn (1 , 'Amount ' , 'number ' );
153193 $ numberColumn ->setNumberDefault (10 );
0 commit comments