From c47a600aca038614f6eb235533f912c0cc74328b Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 15 Aug 2024 11:59:58 +1200 Subject: [PATCH] MNT Move config from silverstripe/admin so that unit-tests pass --- tests/Middleware/CSRFMiddlewareTest.php | 20 ++++++++++++++++++++ tests/Schema/TestSchemaBuilder.php | 5 ++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/Middleware/CSRFMiddlewareTest.php b/tests/Middleware/CSRFMiddlewareTest.php index b0349d7c..61487bbc 100644 --- a/tests/Middleware/CSRFMiddlewareTest.php +++ b/tests/Middleware/CSRFMiddlewareTest.php @@ -8,6 +8,26 @@ class CSRFMiddlewareTest extends BaseMiddlewareProcessTest { + private bool $securityTokenWasEnabled = false; + + protected function setUp(): void + { + parent::setUp(); + // CSRF token check is normally disabled for unit-tests + $this->securityTokenWasEnabled = SecurityToken::is_enabled(); + if (!$this->securityTokenWasEnabled) { + SecurityToken::enable(); + } + } + + protected function tearDown(): void + { + parent::tearDown(); + if (!$this->securityTokenWasEnabled) { + SecurityToken::disable(); + } + } + public function testItDoesntDoAnythingIfNotAMutation() { $this->assertEquals('resolved', $this->simulateMiddlewareProcess( diff --git a/tests/Schema/TestSchemaBuilder.php b/tests/Schema/TestSchemaBuilder.php index 05047971..33d8eff3 100644 --- a/tests/Schema/TestSchemaBuilder.php +++ b/tests/Schema/TestSchemaBuilder.php @@ -13,6 +13,7 @@ use SilverStripe\GraphQL\Schema\Logger; use SilverStripe\GraphQL\Schema\Schema; use SilverStripe\GraphQL\Schema\SchemaBuilder; +use SilverStripe\GraphQL\Schema\Services\SchemaTranscribeHandler; class TestSchemaBuilder extends SchemaBuilder { @@ -101,7 +102,9 @@ private function bootstrapSchema(string $key) 'properties' => [ 'handlers' => [ 'graphqlTranscribe' => [ - 'off' => ['graphqlSchemaBuild'] + 'off' => ['graphqlSchemaBuild'], + 'on' => ['graphqlSchemaBuild'], + 'handler' => '%$' . SchemaTranscribeHandler::class, ], ], ],