From 129a55be746df500a962d50d30802f968fa316ee Mon Sep 17 00:00:00 2001 From: Daniel Metzner Date: Fri, 3 Jun 2022 22:48:20 +0200 Subject: [PATCH] Enhance generator v6 locally to prevent a lot of warnings --- .openapi-generator/FILES | 42 +++ Tests/Api/AuthenticationApiInterfaceTest.php | 178 ++++++++++ Tests/Api/MediaLibraryApiInterfaceTest.php | 156 +++++++++ Tests/Api/NotificationsApiInterfaceTest.php | 153 +++++++++ Tests/Api/ProjectsApiInterfaceTest.php | 325 ++++++++++++++++++ Tests/Api/SearchApiInterfaceTest.php | 108 ++++++ Tests/Api/UserApiInterfaceTest.php | 195 +++++++++++ Tests/Api/UtilityApiInterfaceTest.php | 125 +++++++ Tests/AppKernel.php | 27 ++ Tests/Controller/ControllerTest.php | 121 +++++++ Tests/Model/BaseUserTest.php | 126 +++++++ Tests/Model/BasicUserDataResponseTest.php | 140 ++++++++ Tests/Model/DryRunTest.php | 91 +++++ .../ExtendedUserDataResponseAllOfTest.php | 91 +++++ Tests/Model/ExtendedUserDataResponseTest.php | 147 ++++++++ Tests/Model/ExtensionResponseTest.php | 98 ++++++ Tests/Model/FeaturedProjectResponseTest.php | 133 +++++++ Tests/Model/JWTResponseTest.php | 98 ++++++ Tests/Model/LoginRequestTest.php | 98 ++++++ Tests/Model/MediaCategoryResponseTest.php | 105 ++++++ Tests/Model/MediaFileResponseTest.php | 154 +++++++++ Tests/Model/MediaPackageResponseTest.php | 112 ++++++ Tests/Model/NotificationContentTest.php | 147 ++++++++ Tests/Model/NotificationResponseTest.php | 112 ++++++ .../Model/NotificationsCountResponseTest.php | 119 +++++++ Tests/Model/OAuthLoginRequestTest.php | 98 ++++++ Tests/Model/ProjectReportRequestTest.php | 91 +++++ Tests/Model/ProjectResponseTest.php | 217 ++++++++++++ Tests/Model/ProjectsCategoryTest.php | 105 ++++++ Tests/Model/RefreshRequestTest.php | 91 +++++ Tests/Model/RegisterErrorResponseTest.php | 105 ++++++ Tests/Model/RegisterRequestTest.php | 133 +++++++ .../Model/ResetPasswordErrorResponseTest.php | 91 +++++ Tests/Model/ResetPasswordRequestTest.php | 91 +++++ Tests/Model/SearchResponseTest.php | 112 ++++++ Tests/Model/SurveyResponseTest.php | 91 +++++ Tests/Model/TagResponseTest.php | 98 ++++++ .../Model/UpdateProjectErrorResponseTest.php | 112 ++++++ .../UpdateProjectFailureResponseTest.php | 91 +++++ Tests/Model/UpdateProjectRequestTest.php | 119 +++++++ Tests/Model/UpdateUserErrorResponseTest.php | 119 +++++++ Tests/Model/UpdateUserRequestAllOfTest.php | 91 +++++ Tests/Model/UpdateUserRequestTest.php | 140 ++++++++ Tests/Model/UpgradeTokenRequestTest.php | 91 +++++ Tests/Model/UploadErrorResponseTest.php | 91 +++++ Tests/test_config.yml | 8 + 46 files changed, 5386 insertions(+) create mode 100644 Tests/Api/AuthenticationApiInterfaceTest.php create mode 100644 Tests/Api/MediaLibraryApiInterfaceTest.php create mode 100644 Tests/Api/NotificationsApiInterfaceTest.php create mode 100644 Tests/Api/ProjectsApiInterfaceTest.php create mode 100644 Tests/Api/SearchApiInterfaceTest.php create mode 100644 Tests/Api/UserApiInterfaceTest.php create mode 100644 Tests/Api/UtilityApiInterfaceTest.php create mode 100644 Tests/AppKernel.php create mode 100644 Tests/Controller/ControllerTest.php create mode 100644 Tests/Model/BaseUserTest.php create mode 100644 Tests/Model/BasicUserDataResponseTest.php create mode 100644 Tests/Model/DryRunTest.php create mode 100644 Tests/Model/ExtendedUserDataResponseAllOfTest.php create mode 100644 Tests/Model/ExtendedUserDataResponseTest.php create mode 100644 Tests/Model/ExtensionResponseTest.php create mode 100644 Tests/Model/FeaturedProjectResponseTest.php create mode 100644 Tests/Model/JWTResponseTest.php create mode 100644 Tests/Model/LoginRequestTest.php create mode 100644 Tests/Model/MediaCategoryResponseTest.php create mode 100644 Tests/Model/MediaFileResponseTest.php create mode 100644 Tests/Model/MediaPackageResponseTest.php create mode 100644 Tests/Model/NotificationContentTest.php create mode 100644 Tests/Model/NotificationResponseTest.php create mode 100644 Tests/Model/NotificationsCountResponseTest.php create mode 100644 Tests/Model/OAuthLoginRequestTest.php create mode 100644 Tests/Model/ProjectReportRequestTest.php create mode 100644 Tests/Model/ProjectResponseTest.php create mode 100644 Tests/Model/ProjectsCategoryTest.php create mode 100644 Tests/Model/RefreshRequestTest.php create mode 100644 Tests/Model/RegisterErrorResponseTest.php create mode 100644 Tests/Model/RegisterRequestTest.php create mode 100644 Tests/Model/ResetPasswordErrorResponseTest.php create mode 100644 Tests/Model/ResetPasswordRequestTest.php create mode 100644 Tests/Model/SearchResponseTest.php create mode 100644 Tests/Model/SurveyResponseTest.php create mode 100644 Tests/Model/TagResponseTest.php create mode 100644 Tests/Model/UpdateProjectErrorResponseTest.php create mode 100644 Tests/Model/UpdateProjectFailureResponseTest.php create mode 100644 Tests/Model/UpdateProjectRequestTest.php create mode 100644 Tests/Model/UpdateUserErrorResponseTest.php create mode 100644 Tests/Model/UpdateUserRequestAllOfTest.php create mode 100644 Tests/Model/UpdateUserRequestTest.php create mode 100644 Tests/Model/UpgradeTokenRequestTest.php create mode 100644 Tests/Model/UploadErrorResponseTest.php create mode 100644 Tests/test_config.yml diff --git a/.openapi-generator/FILES b/.openapi-generator/FILES index 587e3bc6..d14475a3 100644 --- a/.openapi-generator/FILES +++ b/.openapi-generator/FILES @@ -107,8 +107,50 @@ Service/StrictJsonDeserializationVisitorFactory.php Service/SymfonyValidator.php Service/TypeMismatchException.php Service/ValidatorInterface.php +Tests/Api/AuthenticationApiInterfaceTest.php +Tests/Api/MediaLibraryApiInterfaceTest.php +Tests/Api/NotificationsApiInterfaceTest.php +Tests/Api/ProjectsApiInterfaceTest.php +Tests/Api/SearchApiInterfaceTest.php +Tests/Api/UserApiInterfaceTest.php +Tests/Api/UtilityApiInterfaceTest.php Tests/AppKernel.php Tests/Controller/ControllerTest.php +Tests/Model/BaseUserTest.php +Tests/Model/BasicUserDataResponseTest.php +Tests/Model/DryRunTest.php +Tests/Model/ExtendedUserDataResponseAllOfTest.php +Tests/Model/ExtendedUserDataResponseTest.php +Tests/Model/ExtensionResponseTest.php +Tests/Model/FeaturedProjectResponseTest.php +Tests/Model/JWTResponseTest.php +Tests/Model/LoginRequestTest.php +Tests/Model/MediaCategoryResponseTest.php +Tests/Model/MediaFileResponseTest.php +Tests/Model/MediaPackageResponseTest.php +Tests/Model/NotificationContentTest.php +Tests/Model/NotificationResponseTest.php +Tests/Model/NotificationsCountResponseTest.php +Tests/Model/OAuthLoginRequestTest.php +Tests/Model/ProjectReportRequestTest.php +Tests/Model/ProjectResponseTest.php +Tests/Model/ProjectsCategoryTest.php +Tests/Model/RefreshRequestTest.php +Tests/Model/RegisterErrorResponseTest.php +Tests/Model/RegisterRequestTest.php +Tests/Model/ResetPasswordErrorResponseTest.php +Tests/Model/ResetPasswordRequestTest.php +Tests/Model/SearchResponseTest.php +Tests/Model/SurveyResponseTest.php +Tests/Model/TagResponseTest.php +Tests/Model/UpdateProjectErrorResponseTest.php +Tests/Model/UpdateProjectFailureResponseTest.php +Tests/Model/UpdateProjectRequestTest.php +Tests/Model/UpdateUserErrorResponseTest.php +Tests/Model/UpdateUserRequestAllOfTest.php +Tests/Model/UpdateUserRequestTest.php +Tests/Model/UpgradeTokenRequestTest.php +Tests/Model/UploadErrorResponseTest.php Tests/test_config.yml autoload.php git_push.sh diff --git a/Tests/Api/AuthenticationApiInterfaceTest.php b/Tests/Api/AuthenticationApiInterfaceTest.php new file mode 100644 index 00000000..ebd24466 --- /dev/null +++ b/Tests/Api/AuthenticationApiInterfaceTest.php @@ -0,0 +1,178 @@ +request('DELETE', $path); + } + + /** + * Test case for authenticationGet. + * + * Check token. + */ + public function testAuthenticationGet(): void + { + $client = self::$client; + + $path = '/authentication'; + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for authenticationOauthPost. + * + * OAuth Login. + */ + public function testAuthenticationOauthPost(): void + { + $client = self::$client; + + $path = '/authentication/oauth'; + + $crawler = $client->request('POST', $path, [], [], ['CONTENT_TYPE' => 'application/json']); + } + + /** + * Test case for authenticationPost. + * + * Login. + */ + public function testAuthenticationPost(): void + { + $client = self::$client; + + $path = '/authentication'; + + $crawler = $client->request('POST', $path, [], [], ['CONTENT_TYPE' => 'application/json']); + } + + /** + * Test case for authenticationRefreshPost. + * + * Refresh token. + */ + public function testAuthenticationRefreshPost(): void + { + $client = self::$client; + + $path = '/authentication/refresh'; + + $crawler = $client->request('POST', $path, [], [], ['CONTENT_TYPE' => 'application/json']); + } + + /** + * Test case for authenticationUpgradePost. + * + * Upgrade a deprecated token to JWT. + */ + public function testAuthenticationUpgradePost(): void + { + $client = self::$client; + + $path = '/authentication/upgrade'; + + $crawler = $client->request('POST', $path, [], [], ['CONTENT_TYPE' => 'application/json']); + } + + /** + * @return mixed + */ + protected function genTestData(string $regexp) + { + $grammar = new \Hoa\File\Read('hoa://Library/Regex/Grammar.pp'); + $compiler = \Hoa\Compiler\Llk\Llk::load($grammar); + $ast = $compiler->parse($regexp); + $generator = new \Hoa\Regex\Visitor\Isotropic(new \Hoa\Math\Sampler\Random()); + + return $generator->visit($ast); + } +} diff --git a/Tests/Api/MediaLibraryApiInterfaceTest.php b/Tests/Api/MediaLibraryApiInterfaceTest.php new file mode 100644 index 00000000..877b9665 --- /dev/null +++ b/Tests/Api/MediaLibraryApiInterfaceTest.php @@ -0,0 +1,156 @@ +genTestData('\d+'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for mediaFilesGet. + * + * Get *all* content of the media library.. + */ + public function testMediaFilesGet(): void + { + $client = self::$client; + + $path = '/media/files'; + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for mediaFilesSearchGet. + * + * Search for mediafiles associated with keywords. + */ + public function testMediaFilesSearchGet(): void + { + $client = self::$client; + + $path = '/media/files/search'; + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for mediaPackageNameGet. + * + * Get media-library asstes of a named package. + */ + public function testMediaPackageNameGet(): void + { + $client = self::$client; + + $path = '/media/package/{name}'; + $pattern = '{name}'; + $data = $this->genTestData('^[a-zA-Z0-9\\-_]+$'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('GET', $path); + } + + /** + * @return mixed + */ + protected function genTestData(string $regexp) + { + $grammar = new \Hoa\File\Read('hoa://Library/Regex/Grammar.pp'); + $compiler = \Hoa\Compiler\Llk\Llk::load($grammar); + $ast = $compiler->parse($regexp); + $generator = new \Hoa\Regex\Visitor\Isotropic(new \Hoa\Math\Sampler\Random()); + + return $generator->visit($ast); + } +} diff --git a/Tests/Api/NotificationsApiInterfaceTest.php b/Tests/Api/NotificationsApiInterfaceTest.php new file mode 100644 index 00000000..e840ab02 --- /dev/null +++ b/Tests/Api/NotificationsApiInterfaceTest.php @@ -0,0 +1,153 @@ +genTestData('\d+'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('PUT', $path); + } + + /** + * Test case for notificationsCountGet. + * + * Count the number of unseen notifications. + */ + public function testNotificationsCountGet(): void + { + $client = self::$client; + + $path = '/notifications/count'; + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for notificationsGet. + * + * Get user notifications -- StatusCode: 501 - Not yet implemented. + */ + public function testNotificationsGet(): void + { + $client = self::$client; + + $path = '/notifications'; + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for notificationsReadPut. + * + * Mark all notifications as read. + */ + public function testNotificationsReadPut(): void + { + $client = self::$client; + + $path = '/notifications/read'; + + $crawler = $client->request('PUT', $path); + } + + /** + * @return mixed + */ + protected function genTestData(string $regexp) + { + $grammar = new \Hoa\File\Read('hoa://Library/Regex/Grammar.pp'); + $compiler = \Hoa\Compiler\Llk\Llk::load($grammar); + $ast = $compiler->parse($regexp); + $generator = new \Hoa\Regex\Visitor\Isotropic(new \Hoa\Math\Sampler\Random()); + + return $generator->visit($ast); + } +} diff --git a/Tests/Api/ProjectsApiInterfaceTest.php b/Tests/Api/ProjectsApiInterfaceTest.php new file mode 100644 index 00000000..bcdbdc1b --- /dev/null +++ b/Tests/Api/ProjectsApiInterfaceTest.php @@ -0,0 +1,325 @@ +genTestData('^[a-zA-Z0-9\\-]+$'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for projectIdDelete. + * + * Delete a project. + */ + public function testProjectIdDelete(): void + { + $client = self::$client; + + $path = '/project/{id}'; + $pattern = '{id}'; + $data = $this->genTestData('^[a-zA-Z0-9\\-]+$'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('DELETE', $path); + } + + /** + * Test case for projectIdGet. + * + * Get the information of a project. + */ + public function testProjectIdGet(): void + { + $client = self::$client; + + $path = '/project/{id}'; + $pattern = '{id}'; + $data = $this->genTestData('^[a-zA-Z0-9\\-]+$'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for projectIdPut. + * + * Update details of a project. + */ + public function testProjectIdPut(): void + { + $client = self::$client; + + $path = '/project/{id}'; + $pattern = '{id}'; + $data = $this->genTestData('^[a-zA-Z0-9\\-]+$'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('PUT', $path, [], [], ['CONTENT_TYPE' => 'application/json']); + } + + /** + * Test case for projectIdRecommendationsGet. + * + * Get recommended projects related to the specific project. + */ + public function testProjectIdRecommendationsGet(): void + { + $client = self::$client; + + $path = '/project/{id}/recommendations'; + $pattern = '{id}'; + $data = $this->genTestData('^[a-zA-Z0-9\\-]+$'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for projectIdReportPost. + * + * Report a project -- StatusCode: 501 - Not yet implemented. + */ + public function testProjectIdReportPost(): void + { + $client = self::$client; + + $path = '/project/{id}/report'; + $pattern = '{id}'; + $data = $this->genTestData('^[a-zA-Z0-9\\-]+$'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('POST', $path, [], [], ['CONTENT_TYPE' => 'application/json']); + } + + /** + * Test case for projectsCategoriesGet. + * + * Get default number of projects per category (Most downloaded etc.). + */ + public function testProjectsCategoriesGet(): void + { + $client = self::$client; + + $path = '/projects/categories'; + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for projectsExtensionsGet. + * + * Get all possible project extensions. Extensions are automatically added to projects based on their bricks.. + */ + public function testProjectsExtensionsGet(): void + { + $client = self::$client; + + $path = '/projects/extensions'; + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for projectsFeaturedGet. + * + * Get the currently featured projects. + */ + public function testProjectsFeaturedGet(): void + { + $client = self::$client; + + $path = '/projects/featured'; + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for projectsGet. + * + * Get projects. + */ + public function testProjectsGet(): void + { + $client = self::$client; + + $path = '/projects'; + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for projectsPost. + * + * Upload a catrobat project. + */ + public function testProjectsPost(): void + { + $client = self::$client; + + $path = '/projects'; + + $crawler = $client->request('POST', $path); + } + + /** + * Test case for projectsSearchGet. + * + * Search for projects associated with a keywords. + */ + public function testProjectsSearchGet(): void + { + $client = self::$client; + + $path = '/projects/search'; + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for projectsTagsGet. + * + * Get all possible project tags. Some Tags will only be availabe during events.. + */ + public function testProjectsTagsGet(): void + { + $client = self::$client; + + $path = '/projects/tags'; + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for projectsUserGet. + * + * Get the projects of the logged in user. + */ + public function testProjectsUserGet(): void + { + $client = self::$client; + + $path = '/projects/user'; + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for projectsUserIdGet. + * + * Get the public projects of a given user. + */ + public function testProjectsUserIdGet(): void + { + $client = self::$client; + + $path = '/projects/user/{id}'; + $pattern = '{id}'; + $data = $this->genTestData('^[a-zA-Z0-9\\-]+$'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('GET', $path); + } + + /** + * @return mixed + */ + protected function genTestData(string $regexp) + { + $grammar = new \Hoa\File\Read('hoa://Library/Regex/Grammar.pp'); + $compiler = \Hoa\Compiler\Llk\Llk::load($grammar); + $ast = $compiler->parse($regexp); + $generator = new \Hoa\Regex\Visitor\Isotropic(new \Hoa\Math\Sampler\Random()); + + return $generator->visit($ast); + } +} diff --git a/Tests/Api/SearchApiInterfaceTest.php b/Tests/Api/SearchApiInterfaceTest.php new file mode 100644 index 00000000..cb0c24e2 --- /dev/null +++ b/Tests/Api/SearchApiInterfaceTest.php @@ -0,0 +1,108 @@ +request('GET', $path); + } + + /** + * @return mixed + */ + protected function genTestData(string $regexp) + { + $grammar = new \Hoa\File\Read('hoa://Library/Regex/Grammar.pp'); + $compiler = \Hoa\Compiler\Llk\Llk::load($grammar); + $ast = $compiler->parse($regexp); + $generator = new \Hoa\Regex\Visitor\Isotropic(new \Hoa\Math\Sampler\Random()); + + return $generator->visit($ast); + } +} diff --git a/Tests/Api/UserApiInterfaceTest.php b/Tests/Api/UserApiInterfaceTest.php new file mode 100644 index 00000000..a7569816 --- /dev/null +++ b/Tests/Api/UserApiInterfaceTest.php @@ -0,0 +1,195 @@ +request('DELETE', $path); + } + + /** + * Test case for userGet. + * + * Get your private user data. + */ + public function testUserGet(): void + { + $client = self::$client; + + $path = '/user'; + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for userIdGet. + * + * Get public user data. + */ + public function testUserIdGet(): void + { + $client = self::$client; + + $path = '/user/{id}'; + $pattern = '{id}'; + $data = $this->genTestData('^[a-zA-Z0-9\\-]+$'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('GET', $path); + } + + /** + * Test case for userPost. + * + * Register. + */ + public function testUserPost(): void + { + $client = self::$client; + + $path = '/user'; + + $crawler = $client->request('POST', $path, [], [], ['CONTENT_TYPE' => 'application/json']); + } + + /** + * Test case for userPut. + * + * Update User. + */ + public function testUserPut(): void + { + $client = self::$client; + + $path = '/user'; + + $crawler = $client->request('PUT', $path, [], [], ['CONTENT_TYPE' => 'application/json']); + } + + /** + * Test case for userResetPasswordPost. + * + * Request email to reset password. + */ + public function testUserResetPasswordPost(): void + { + $client = self::$client; + + $path = '/user/reset-password'; + + $crawler = $client->request('POST', $path, [], [], ['CONTENT_TYPE' => 'application/json']); + } + + /** + * Test case for usersSearchGet. + * + * Search for users. + */ + public function testUsersSearchGet(): void + { + $client = self::$client; + + $path = '/users/search'; + + $crawler = $client->request('GET', $path); + } + + /** + * @return mixed + */ + protected function genTestData(string $regexp) + { + $grammar = new \Hoa\File\Read('hoa://Library/Regex/Grammar.pp'); + $compiler = \Hoa\Compiler\Llk\Llk::load($grammar); + $ast = $compiler->parse($regexp); + $generator = new \Hoa\Regex\Visitor\Isotropic(new \Hoa\Math\Sampler\Random()); + + return $generator->visit($ast); + } +} diff --git a/Tests/Api/UtilityApiInterfaceTest.php b/Tests/Api/UtilityApiInterfaceTest.php new file mode 100644 index 00000000..02c8a8dc --- /dev/null +++ b/Tests/Api/UtilityApiInterfaceTest.php @@ -0,0 +1,125 @@ +request('GET', $path); + } + + /** + * Test case for surveyLangCodeGet. + * + * Get survey link for given language code.. + */ + public function testSurveyLangCodeGet(): void + { + $client = self::$client; + + $path = '/survey/{lang_code}'; + $pattern = '{lang_code}'; + $data = $this->genTestData('[a-z0-9]+'); + $path = str_replace($pattern, $data, $path); + + $crawler = $client->request('GET', $path); + } + + /** + * @return mixed + */ + protected function genTestData(string $regexp) + { + $grammar = new \Hoa\File\Read('hoa://Library/Regex/Grammar.pp'); + $compiler = \Hoa\Compiler\Llk\Llk::load($grammar); + $ast = $compiler->parse($regexp); + $generator = new \Hoa\Regex\Visitor\Isotropic(new \Hoa\Math\Sampler\Random()); + + return $generator->visit($ast); + } +} diff --git a/Tests/AppKernel.php b/Tests/AppKernel.php new file mode 100644 index 00000000..942b0951 --- /dev/null +++ b/Tests/AppKernel.php @@ -0,0 +1,27 @@ +load(__DIR__.'/test_config.yml'); + } +} diff --git a/Tests/Controller/ControllerTest.php b/Tests/Controller/ControllerTest.php new file mode 100644 index 00000000..1d0a316f --- /dev/null +++ b/Tests/Controller/ControllerTest.php @@ -0,0 +1,121 @@ +headers->set('CONTENT_TYPE', $contentType, true); // last one argument overrides header + $this->assertSame( + $expectedReturn, + Controller::isContentTypeAllowed($request, $consumes), + sprintf( + 'Failed assertion that "Content-Type: %s" %s by [%s] consumes array.', + $contentType, + ($expectedReturn) ? 'is allowed' : 'is forbidden', + implode(', ', $consumes) + ) + ); + } + + public function provideArgumentsForIsContentTypeAllowed(): array + { + return [ + 'usual JSON content type' => [ + 'application/json', + ['application/json'], + true, + ], + 'extended content type from PR #6078' => [ + 'application/json; charset=utf-8', + ['application/json'], + true, + ], + 'more than one content types' => [ + 'application/json', + ['application/xml', 'application/json; charset=utf-8'], + true, + ], + 'empty consumes array' => [ + 'application/json', + [], + true, + ], + 'empty consumes and content type' => [ + null, + [], + true, + ], + 'consumes everything' => [ + 'application/json', + ['*/*'], + true, + ], + 'fancy custom content type' => [ + 'foobar/foobaz', + ['application/xml', 'foobar/foobaz; charset=utf-8'], + true, + ], + 'empty content type' => [ + null, + ['application/xml', 'application/json; charset=utf-8'], + false, + ], + 'content type out of consumes' => [ + 'text/html', + ['application/xml', 'application/json; charset=utf-8'], + false, + ], + ]; + } +} diff --git a/Tests/Model/BaseUserTest.php b/Tests/Model/BaseUserTest.php new file mode 100644 index 00000000..69ff5332 --- /dev/null +++ b/Tests/Model/BaseUserTest.php @@ -0,0 +1,126 @@ +