Skip to content

Commit 59d087d

Browse files
committed
Add unit test for updateApiConfig hook
1 parent 808d883 commit 59d087d

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ fetch(
364364
.then(responseJson => console.log(responseJson));
365365
```
366366

367-
When working with non-public API endpoints you may wish to disable the csrf token check so that you can quickly test `GET` queries in your browsers location bar. You can do this by calling `SecurityToken::disable()` in `app/_config.php`, though if you do this be very careful this isn't then disabled in production too. To be safe, wrap this in a check to an environment variable which you then define if your personal .env file, for example:
367+
When working with non-public API endpoints you may wish to disable the csrf token check so that you can quickly test `GET` queries in your browsers location bar. You can do this by calling `SecurityToken::disable()` in `app/_config.php`, though if you do this be very careful this isn't then disabled in production too. To be safe, wrap this in a check to an environment variable of your choosing that you set in your local .env file, for example:
368368

369369
```php
370370
use SilverStripe\Core\Environment;
@@ -433,4 +433,4 @@ Notes:
433433
| `onBeforeAction(DataObject $obj, string $action)` | Called during `ACTION` requests before running the action |
434434
| `onAfterAction(DataObject $obj, string $action)` | Called during `ACTION` requests after running the action |
435435
| `onBeforeSendResponse(HTTPResponse $response)` | Called during all requests before sending HTTP response |
436-
| `updateApiConfig(array &$apiConfig)` | Called during all requests before any processing. Allows late updates to `private static array $api_config`, though modifying the `RestApiEndpoint::PATH` key has no effect at this stage |
436+
| `updateApiConfig(array &$apiConfig)` | Called during all requests before any processing. Allows late updates to `private static array $api_config`. Note that modifying the `RestApiEndpoint::PATH` key will have no effect at this stage |

tests/Controllers/RestApiEndpointTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,6 +2299,7 @@ public function testExtensionHooks(): void
22992299
$this->assertTrue(TestApiEndpoint::$hooksCalled['onDeleteAfterDelete']);
23002300
// BeforeSendResponse
23012301
$this->assertTrue(TestApiEndpoint::$hooksCalled['onBeforeSendResponse']);
2302+
$this->assertTrue(TestApiEndpoint::$hooksCalled['updateApiConfig']);
23022303
}
23032304

23042305
private function login(int $authLevel)

tests/Controllers/RestApiEndpointTest/TestApiEndpoint.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class TestApiEndpoint extends RestApiEndpoint implements PermissionProvider, Tes
121121
'onBeforeAction' => false,
122122
'onAfterAction' => false,
123123
'onBeforeSendResponse' => false,
124+
'updateApiConfig' => false,
124125
];
125126

126127
public function providePermissions()
@@ -191,4 +192,9 @@ protected function onBeforeSendResponse(HTTPResponse $response): void
191192
{
192193
self::$hooksCalled['onBeforeSendResponse'] = true;
193194
}
195+
196+
protected function updateApiConfig(array $apiConfig): void
197+
{
198+
self::$hooksCalled['updateApiConfig'] = true;
199+
}
194200
}

0 commit comments

Comments
 (0)