From f6284079a63c85a0e120a4b6b8c2c358c30da284 Mon Sep 17 00:00:00 2001 From: Luis Date: Thu, 7 Sep 2023 13:47:57 +0200 Subject: [PATCH] Testing: Add compatibility to drupal 10 --- .../tests/src/Kernel/Breadcrumbs/BreadcrumbsTest.php | 2 +- .../tests/src/Kernel/Entity/BundleLessEntityTest.php | 2 +- .../tests/src/Kernel/Entity/EntityByIdTest.php | 2 +- .../tests/src/Kernel/Entity/EntityFieldValueTest.php | 2 +- .../src/Kernel/EntityMutation/EntityMutationTest.php | 5 ++++- .../tests/src/Kernel/EntityQuery/EntityQueryTest.php | 10 +++++----- .../tests/src/Kernel/GraphQLContentTestBase.php | 2 +- .../tests/src/Kernel/GraphQLCoreTestBase.php | 2 +- .../tests/src/Kernel/Images/ImageFieldTest.php | 8 ++++---- .../tests/src/Kernel/Languages/LanguageTest.php | 8 ++++---- .../graphql_core/tests/src/Kernel/Menu/MenuTest.php | 3 ++- .../tests/src/Kernel/Routing/ExternalRequestTest.php | 2 +- .../tests/src/Kernel/Routing/InternalRequestTest.php | 2 +- .../tests/src/Kernel/Routing/RouteTest.php | 4 ++-- tests/src/Kernel/Framework/LanguageContextTest.php | 2 +- tests/src/Kernel/Framework/PermissionsTest.php | 3 +-- tests/src/Kernel/Framework/ResultTest.php | 3 +-- tests/src/Kernel/Framework/SecureFieldTest.php | 4 ++-- tests/src/Kernel/GraphQLFileTestBase.php | 2 +- tests/src/Kernel/GraphQLTestBase.php | 5 ++--- tests/src/Unit/StringFormattingTest.php | 5 ++++- 21 files changed, 41 insertions(+), 37 deletions(-) diff --git a/modules/graphql_core/tests/src/Kernel/Breadcrumbs/BreadcrumbsTest.php b/modules/graphql_core/tests/src/Kernel/Breadcrumbs/BreadcrumbsTest.php index dae30649b..e4c8fbab7 100644 --- a/modules/graphql_core/tests/src/Kernel/Breadcrumbs/BreadcrumbsTest.php +++ b/modules/graphql_core/tests/src/Kernel/Breadcrumbs/BreadcrumbsTest.php @@ -25,7 +25,7 @@ class BreadcrumbsTest extends GraphQLCoreTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $breadcrumbManager = $this->prophesize('Drupal\Core\Breadcrumb\BreadcrumbManager'); diff --git a/modules/graphql_core/tests/src/Kernel/Entity/BundleLessEntityTest.php b/modules/graphql_core/tests/src/Kernel/Entity/BundleLessEntityTest.php index b29fa68e9..df0cd0686 100644 --- a/modules/graphql_core/tests/src/Kernel/Entity/BundleLessEntityTest.php +++ b/modules/graphql_core/tests/src/Kernel/Entity/BundleLessEntityTest.php @@ -18,7 +18,7 @@ class BundleLessEntityTest extends GraphQLContentTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); FieldStorageConfig::create([ 'field_name' => 'field_test', diff --git a/modules/graphql_core/tests/src/Kernel/Entity/EntityByIdTest.php b/modules/graphql_core/tests/src/Kernel/Entity/EntityByIdTest.php index ab0f6b58c..753753de3 100644 --- a/modules/graphql_core/tests/src/Kernel/Entity/EntityByIdTest.php +++ b/modules/graphql_core/tests/src/Kernel/Entity/EntityByIdTest.php @@ -28,7 +28,7 @@ class EntityByIdTest extends GraphQLContentTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $languageStorage */ diff --git a/modules/graphql_core/tests/src/Kernel/Entity/EntityFieldValueTest.php b/modules/graphql_core/tests/src/Kernel/Entity/EntityFieldValueTest.php index 490c6dadd..7456ac653 100644 --- a/modules/graphql_core/tests/src/Kernel/Entity/EntityFieldValueTest.php +++ b/modules/graphql_core/tests/src/Kernel/Entity/EntityFieldValueTest.php @@ -35,7 +35,7 @@ class EntityFieldValueTest extends GraphQLContentTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); } diff --git a/modules/graphql_core/tests/src/Kernel/EntityMutation/EntityMutationTest.php b/modules/graphql_core/tests/src/Kernel/EntityMutation/EntityMutationTest.php index e8ff2e631..9aed3f7b1 100644 --- a/modules/graphql_core/tests/src/Kernel/EntityMutation/EntityMutationTest.php +++ b/modules/graphql_core/tests/src/Kernel/EntityMutation/EntityMutationTest.php @@ -30,7 +30,7 @@ protected function userPermissions() { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->mockInputType('node_input', [ 'name' => 'NodeInput', @@ -41,6 +41,9 @@ protected function setUp() { ]); } + /** + * + */ protected function mockMutationFactory($definition, $result = NULL, $builder = NULL) { $mutation = $this->getMockBuilder([ 'createNode' => CreateEntityBase::class, diff --git a/modules/graphql_core/tests/src/Kernel/EntityQuery/EntityQueryTest.php b/modules/graphql_core/tests/src/Kernel/EntityQuery/EntityQueryTest.php index 0566204c1..09c4bfd70 100644 --- a/modules/graphql_core/tests/src/Kernel/EntityQuery/EntityQueryTest.php +++ b/modules/graphql_core/tests/src/Kernel/EntityQuery/EntityQueryTest.php @@ -15,7 +15,7 @@ class EntityQueryTest extends GraphQLContentTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->createContentType(['type' => 'a']); $this->createContentType(['type' => 'b']); @@ -50,7 +50,7 @@ public function testEntityQuery() { $c->save(); $d->save(); - // TODO: Check cache metadata. + // @todo Check cache metadata. $metadata = $this->defaultCacheMetaData(); $metadata->addCacheContexts(['user.node_grants:view']); $metadata->addCacheTags([ @@ -122,11 +122,11 @@ public function testFilterSecurity() { $metadata->addCacheTags(['graphql', 'user_list']); $this->assertResults('query { userQuery (filter: { conditions: [ { field: "pass", value: "foo" } ] }) { count } }', [], [ 'userQuery' => [ - // TODO: With proper access checking for filters this value should - // become "2" and the entity query field can be marked as secure + // @todo With proper access checking for filters this value should + // become "2" and the entity query field can be marked as secure // again. 'count' => 0, - ] + ], ], $metadata); } diff --git a/modules/graphql_core/tests/src/Kernel/GraphQLContentTestBase.php b/modules/graphql_core/tests/src/Kernel/GraphQLContentTestBase.php index d1df9a016..4efc66259 100644 --- a/modules/graphql_core/tests/src/Kernel/GraphQLContentTestBase.php +++ b/modules/graphql_core/tests/src/Kernel/GraphQLContentTestBase.php @@ -45,7 +45,7 @@ protected function userPermissions() { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->installConfig(['node', 'filter', 'text']); diff --git a/modules/graphql_core/tests/src/Kernel/GraphQLCoreTestBase.php b/modules/graphql_core/tests/src/Kernel/GraphQLCoreTestBase.php index 36a4c5023..c75bb0791 100644 --- a/modules/graphql_core/tests/src/Kernel/GraphQLCoreTestBase.php +++ b/modules/graphql_core/tests/src/Kernel/GraphQLCoreTestBase.php @@ -21,7 +21,7 @@ class GraphQLCoreTestBase extends GraphQLTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); // User entity schema is required for the currentUserContext field. $this->installEntitySchema('user'); diff --git a/modules/graphql_core/tests/src/Kernel/Images/ImageFieldTest.php b/modules/graphql_core/tests/src/Kernel/Images/ImageFieldTest.php index ab819036a..c58bd1c05 100644 --- a/modules/graphql_core/tests/src/Kernel/Images/ImageFieldTest.php +++ b/modules/graphql_core/tests/src/Kernel/Images/ImageFieldTest.php @@ -23,7 +23,7 @@ class ImageFieldTest extends GraphQLContentTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->installConfig('image'); $this->installSchema('file', 'file_usage'); @@ -44,7 +44,6 @@ public function testImageField() { $a->save(); - $style = ImageStyle::load('thumbnail'); $dimensions = [ @@ -58,7 +57,7 @@ public function testImageField() { $metadata->addCacheTags([ 'file:1', 'node:1', - // TODO: Check metatags. Is the config metatag required? + // @todo Check metatags. Is the config metatag required? 'config:image.style.thumbnail', ]); @@ -78,7 +77,8 @@ public function testImageField() { 'width' => $dimensions['width'], 'height' => $dimensions['height'], ], - ]], + ], + ], ], ], ], $metadata); diff --git a/modules/graphql_core/tests/src/Kernel/Languages/LanguageTest.php b/modules/graphql_core/tests/src/Kernel/Languages/LanguageTest.php index 917a45248..d2fe6688d 100644 --- a/modules/graphql_core/tests/src/Kernel/Languages/LanguageTest.php +++ b/modules/graphql_core/tests/src/Kernel/Languages/LanguageTest.php @@ -22,7 +22,7 @@ class LanguageTest extends GraphQLCoreTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->installConfig(['language']); @@ -51,8 +51,7 @@ protected function setUp() { */ public function testLanguageId() { $metadata = $this->defaultCacheMetaData(); - // TODO: Should this also contain the language config cache metadata? - + // @todo Should this also contain the language config cache metadata? $this->assertResults($this->getQueryFromFile('languages.gql'), [], [ 'languages' => [ 0 => [ @@ -104,7 +103,7 @@ public function testLanguageSwitchLinks() { 'config:language.entity.en', 'config:language.entity.es', 'config:language.entity.fr', - 'config:language.entity.pt-br' + 'config:language.entity.pt-br', ]); $this->assertResults($this->getQueryFromFile('language_switch_links.gql'), [], [ @@ -154,4 +153,5 @@ public function testLanguageSwitchLinks() { ], ], $metadata); } + } diff --git a/modules/graphql_core/tests/src/Kernel/Menu/MenuTest.php b/modules/graphql_core/tests/src/Kernel/Menu/MenuTest.php index 0b7fe837e..df80f9eff 100644 --- a/modules/graphql_core/tests/src/Kernel/Menu/MenuTest.php +++ b/modules/graphql_core/tests/src/Kernel/Menu/MenuTest.php @@ -26,7 +26,7 @@ class MenuTest extends GraphQLCoreTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->installEntitySchema('menu_link_content'); $this->installConfig('menu_link_content'); @@ -126,4 +126,5 @@ public function testMenuTree() { $metadata ); } + } diff --git a/modules/graphql_core/tests/src/Kernel/Routing/ExternalRequestTest.php b/modules/graphql_core/tests/src/Kernel/Routing/ExternalRequestTest.php index 538cc17f6..677e791aa 100644 --- a/modules/graphql_core/tests/src/Kernel/Routing/ExternalRequestTest.php +++ b/modules/graphql_core/tests/src/Kernel/Routing/ExternalRequestTest.php @@ -21,7 +21,7 @@ class ExternalRequestTest extends GraphQLCoreTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->installEntitySchema('user'); } diff --git a/modules/graphql_core/tests/src/Kernel/Routing/InternalRequestTest.php b/modules/graphql_core/tests/src/Kernel/Routing/InternalRequestTest.php index dd2a91fbe..06b9346b9 100644 --- a/modules/graphql_core/tests/src/Kernel/Routing/InternalRequestTest.php +++ b/modules/graphql_core/tests/src/Kernel/Routing/InternalRequestTest.php @@ -19,7 +19,7 @@ class InternalRequestTest extends GraphQLCoreTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->installEntitySchema('user'); } diff --git a/modules/graphql_core/tests/src/Kernel/Routing/RouteTest.php b/modules/graphql_core/tests/src/Kernel/Routing/RouteTest.php index e1133632d..f8d5cf126 100644 --- a/modules/graphql_core/tests/src/Kernel/Routing/RouteTest.php +++ b/modules/graphql_core/tests/src/Kernel/Routing/RouteTest.php @@ -3,8 +3,8 @@ namespace Drupal\Tests\graphql_core\Kernel\Routing; use Drupal\Core\GeneratedUrl; -use Drupal\path_alias\AliasManagerInterface; use Drupal\Core\Routing\UrlGeneratorInterface; +use Drupal\path_alias\AliasManagerInterface; use Drupal\Tests\graphql_core\Kernel\GraphQLCoreTestBase; use Prophecy\Argument; @@ -22,7 +22,7 @@ class RouteTest extends GraphQLCoreTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $aliasManager = $this->prophesize(AliasManagerInterface::class); diff --git a/tests/src/Kernel/Framework/LanguageContextTest.php b/tests/src/Kernel/Framework/LanguageContextTest.php index 90191a537..8e40a6107 100644 --- a/tests/src/Kernel/Framework/LanguageContextTest.php +++ b/tests/src/Kernel/Framework/LanguageContextTest.php @@ -23,7 +23,7 @@ class LanguageContextTest extends GraphQLTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->mockType('node', ['name' => 'Node']); diff --git a/tests/src/Kernel/Framework/PermissionsTest.php b/tests/src/Kernel/Framework/PermissionsTest.php index 01340a72b..603a8e29a 100644 --- a/tests/src/Kernel/Framework/PermissionsTest.php +++ b/tests/src/Kernel/Framework/PermissionsTest.php @@ -4,7 +4,6 @@ use Drupal\graphql\GraphQL\QueryProvider\QueryProviderInterface; use Drupal\Tests\graphql\Kernel\GraphQLTestBase; -use PhpParser\Node\Arg; use Prophecy\Argument; /** @@ -24,7 +23,7 @@ protected function userPermissions() { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->mockField('root', [ diff --git a/tests/src/Kernel/Framework/ResultTest.php b/tests/src/Kernel/Framework/ResultTest.php index ed5d9cb91..62bc8dee2 100644 --- a/tests/src/Kernel/Framework/ResultTest.php +++ b/tests/src/Kernel/Framework/ResultTest.php @@ -4,7 +4,6 @@ use Drupal\graphql\GraphQL\QueryProvider\QueryProviderInterface; use Drupal\Tests\graphql\Kernel\GraphQLTestBase; -use GraphQL\Server\OperationParams; use Prophecy\Argument; /** @@ -17,7 +16,7 @@ class ResultTest extends GraphQLTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->mockField('root', [ 'name' => 'root', diff --git a/tests/src/Kernel/Framework/SecureFieldTest.php b/tests/src/Kernel/Framework/SecureFieldTest.php index 48ca0f1f0..eb5484531 100644 --- a/tests/src/Kernel/Framework/SecureFieldTest.php +++ b/tests/src/Kernel/Framework/SecureFieldTest.php @@ -20,14 +20,14 @@ protected function userPermissions() { // Don't grant the user field security bypass for this test case. return [ 'execute graphql requests', - //'bypass graphql field security', + // 'bypass graphql field security', ]; } /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->mockField('secure', [ diff --git a/tests/src/Kernel/GraphQLFileTestBase.php b/tests/src/Kernel/GraphQLFileTestBase.php index 040ed344b..50602342c 100644 --- a/tests/src/Kernel/GraphQLFileTestBase.php +++ b/tests/src/Kernel/GraphQLFileTestBase.php @@ -28,7 +28,7 @@ abstract class GraphQLFileTestBase extends KernelTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->installConfig('system'); $this->installConfig('graphql'); diff --git a/tests/src/Kernel/GraphQLTestBase.php b/tests/src/Kernel/GraphQLTestBase.php index 306c9c4e2..6db649151 100644 --- a/tests/src/Kernel/GraphQLTestBase.php +++ b/tests/src/Kernel/GraphQLTestBase.php @@ -6,12 +6,11 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\KernelTests\KernelTestBase; use Drupal\language\Entity\ConfigurableLanguage; -use Drupal\Tests\graphql\Traits\ProphesizePermissionsTrait; use Drupal\Tests\graphql\Traits\EnableCliCacheTrait; use Drupal\Tests\graphql\Traits\HttpRequestTrait; use Drupal\Tests\graphql\Traits\IntrospectionTestTrait; -use Drupal\Tests\graphql\Traits\MockSchemaTrait; use Drupal\Tests\graphql\Traits\MockGraphQLPluginTrait; +use Drupal\Tests\graphql\Traits\ProphesizePermissionsTrait; use Drupal\Tests\graphql\Traits\QueryFileTrait; use Drupal\Tests\graphql\Traits\QueryResultAssertionTrait; @@ -96,7 +95,7 @@ public function register(ContainerBuilder $container) { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->injectTypeSystemPluginManagers($this->container); diff --git a/tests/src/Unit/StringFormattingTest.php b/tests/src/Unit/StringFormattingTest.php index 73ae56393..ecbab897e 100644 --- a/tests/src/Unit/StringFormattingTest.php +++ b/tests/src/Unit/StringFormattingTest.php @@ -40,12 +40,15 @@ public function testPropCaseFormatting($input, $expected) { $this->assertSame(lcfirst($expected), call_user_func_array([StringHelper::class, 'propCase'], $input)); } + /** + * + */ public function providerTestStringFormatting() { return [ [['simple-name'], 'SimpleName'], [['123-name-with*^&!@some-SPECIAL-chars'], '_123NameWithSomeSPECIALChars'], [['simple', 'name-of-string', 'components'], 'SimpleNameOfStringComponents'], - [['123', 'array', '%^!@&#*', 'of', 'STRING', '(*&', 'components', 'with', 'SPEcial', 'chars'], '_123ArrayOfSTRINGComponentsWithSPEcialChars'] + [['123', 'array', '%^!@&#*', 'of', 'STRING', '(*&', 'components', 'with', 'SPEcial', 'chars'], '_123ArrayOfSTRINGComponentsWithSPEcialChars'], ]; }