MCPcopy Create free account
hub / github.com/Rello/analytics / DatasourceControllerTest

Class DatasourceControllerTest

tests/Controller/DatasourceControllerTest.php:8–727  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6use PHPUnit\Framework\TestCase;
7
8class DatasourceControllerTest extends TestCase {
9 /**
10 * Verifies datasource providers expose their report templates via indexFiltered().
11 */
12 public function testIndexFilteredIncludesReportTemplatesForDatasourceProviders(): void {
13 $github = $this->createMock(\OCA\Analytics\Datasource\Github::class);
14 $github->expects($this->once())
15 ->method('getName')
16 ->willReturn('GitHub');
17 $github->expects($this->once())
18 ->method('getTemplate')
19 ->willReturn([]);
20 $github->expects($this->once())
21 ->method('getReportTemplates')
22 ->willReturn([
23 'github_demo_downloads' => [
24 'name' => 'Demo: Analytics Downloads',
25 'report' => ['name' => 'Demo: Analytics Downloads'],
26 ],
27 ]);
28
29 $controller = $this->createController(null, $github);
30 $result = $controller->indexFiltered(DatasourceController::DATASET_TYPE_GIT);
31
32 $this->assertArrayHasKey('reportTemplates', $result);
33 $this->assertArrayHasKey(DatasourceController::DATASET_TYPE_GIT, $result['reportTemplates']);
34 $this->assertArrayHasKey('github_demo_downloads', $result['reportTemplates'][DatasourceController::DATASET_TYPE_GIT]);
35 }
36
37 public function testOwnReturnsInternalDatasourcesWithoutDispatchingRegisteredDatasourceEvent(): void {
38 $dispatcher = $this->createMock(\OCP\EventDispatcher\IEventDispatcher::class);
39 $dispatcher->expects($this->never())
40 ->method('dispatchTyped');
41
42 $localCsv = $this->createMock(\OCA\Analytics\Datasource\LocalCsv::class);
43 $localCsv->expects($this->once())
44 ->method('getName')
45 ->willReturn('Local CSV');
46 $localCsv->expects($this->once())
47 ->method('getTemplate')
48 ->willReturn([]);
49
50 $controller = $this->createController($localCsv, null, $dispatcher);
51 $result = $controller->own();
52
53 $this->assertArrayHasKey(DatasourceController::DATASET_TYPE_LOCAL_CSV, $result['datasources']);
54 $this->assertSame('Local CSV', $result['datasources'][DatasourceController::DATASET_TYPE_LOCAL_CSV]);
55 }
56
57 /**
58 * Verifies hidden drilldown indices are processed in numeric order and removed from headers.
59 */
60 public function testAggregateDataRemovesColumnsUsingNumericSorting() {
61 $controller = $this->createController();
62
63 $header = [];
64 $row1 = [];
65 $row2 = [];

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected