| 18 | use Psr\Log\LoggerInterface; |
| 19 | |
| 20 | class ApiDataControllerTest extends TestCase { |
| 21 | public function testDeletionFilterRejectsUnknownColumns(): void { |
| 22 | $controller = $this->createController( |
| 23 | $this->createMock(IRequest::class), |
| 24 | $this->createMock(DatasetService::class), |
| 25 | $this->createMock(StorageService::class), |
| 26 | $this->createMock(VariableService::class) |
| 27 | ); |
| 28 | $method = new \ReflectionMethod(ApiDataController::class, 'normalizeDeletionFilter'); |
| 29 | |
| 30 | $result = $method->invoke($controller, [ |
| 31 | 'not-a-dataset-column' => ['option' => 'LT', 'value' => '%last 5 days%'], |
| 32 | ], [ |
| 33 | 'dimension1' => 'Reading date', |
| 34 | 'dimension2' => 'Source', |
| 35 | ]); |
| 36 | |
| 37 | $this->assertNull($result); |
| 38 | } |
| 39 | |
| 40 | public function testDeleteDataV4ResolvesDateVariablesAndReturnsDeletionCount(): void { |
| 41 | $request = $this->getMockBuilder(IRequest::class) |
| 42 | ->addMethods(['getParams']) |
| 43 | ->getMock(); |
| 44 | $request->method('getParams')->willReturn([ |
| 45 | 'filter' => [ |
| 46 | 'Reading date' => ['option' => 'LT', 'value' => '%last 5 days%'], |
| 47 | ], |
| 48 | ]); |
| 49 | $datasetService = $this->createMock(DatasetService::class); |
| 50 | $datasetService->method('readOwn')->with(42)->willReturn([ |
| 51 | 'id' => 42, |
| 52 | 'storageMode' => 'legacy', |
| 53 | 'dimension1' => 'Reading date', |
| 54 | 'dimension2' => 'Source', |
| 55 | ]); |
| 56 | $datasetService->expects($this->once())->method('provider')->with(42); |
| 57 | $variableService = $this->createMock(VariableService::class); |
| 58 | $variableService->expects($this->once()) |
| 59 | ->method('replaceFilterVariables') |
| 60 | ->willReturn([ |
| 61 | 'filteroptions' => '{"filter":{"dimension1":{"option":"LT","value":"2026-09-10"}}}', |
| 62 | ]); |
| 63 | $storageService = $this->createMock(StorageService::class); |
| 64 | $storageService->expects($this->once()) |
| 65 | ->method('deleteWithFilter') |
| 66 | ->with(42, [ |
| 67 | 'filter' => [ |
| 68 | 'dimension1' => ['option' => 'LT', 'value' => '2026-09-10'], |
| 69 | ], |
| 70 | ]) |
| 71 | ->willReturn(7); |
| 72 | |
| 73 | $response = $this->createController($request, $datasetService, $storageService, $variableService) |
| 74 | ->deleteDataV4(42); |
| 75 | |
| 76 | $this->assertSame(200, $response->getStatus()); |
| 77 | $this->assertSame([ |
nothing calls this directly
no outgoing calls
no test coverage detected