From e52f39a52560e932a050a420045afef79be533f7 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Tue, 12 Nov 2024 16:49:04 +1300 Subject: [PATCH] API Make LinkFieldController a subclass of FormSchemaController --- src/Controllers/LinkFieldController.php | 6 ++---- tests/php/Controllers/LinkFieldControllerTest.php | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Controllers/LinkFieldController.php b/src/Controllers/LinkFieldController.php index 0df9ad7b..545e0bc0 100644 --- a/src/Controllers/LinkFieldController.php +++ b/src/Controllers/LinkFieldController.php @@ -2,7 +2,7 @@ namespace SilverStripe\LinkField\Controllers; -use SilverStripe\Admin\LeftAndMain; +use SilverStripe\Admin\FormSchemaController; use SilverStripe\Control\HTTPResponse; use SilverStripe\Forms\DefaultFormFactory; use SilverStripe\Forms\Form; @@ -25,14 +25,12 @@ use SilverStripe\ORM\Queries\SQLUpdate; use SilverStripe\Versioned\Versioned; -class LinkFieldController extends LeftAndMain +class LinkFieldController extends FormSchemaController { public const FORM_NAME_TEMPLATE = 'LinkForm_%s'; private static string $url_segment = 'linkfield'; - private static $ignore_menuitem = true; - private static array $url_handlers = [ 'linkForm/$ItemID' => 'linkForm', 'GET data/$ItemID' => 'linkData', diff --git a/tests/php/Controllers/LinkFieldControllerTest.php b/tests/php/Controllers/LinkFieldControllerTest.php index 63cdf66d..0392826b 100644 --- a/tests/php/Controllers/LinkFieldControllerTest.php +++ b/tests/php/Controllers/LinkFieldControllerTest.php @@ -251,9 +251,9 @@ public function testLinkFormPost( $response = $this->post($url, $data, $headers); $this->assertSame($expectedCode, $response->getStatusCode()); if ($fail === 'csrf-token') { - // Will end up at an HTML page with "Silverstripe - Bad Request" - $this->assertSame('text/html; charset=utf-8', $response->getHeader('Content-type')); - $this->assertStringContainsString('Silverstripe - Bad Request', $response->getBody()); + // Gives suitable error message for XHR request + $this->assertStringStartsWith('text/plain', $response->getHeader('Content-type')); + $this->assertStringContainsString('There seems to have been a technical problem', $response->getBody()); return; } $this->assertSame($expectedCode, $response->getStatusCode());