From 632bac86619daf82f3104b00e244503c9acc4ff2 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Wed, 8 Oct 2014 14:47:47 +0200 Subject: [PATCH] Added "use ..." statements This version ditches backwards compatibility with PHP earlier than 5.6. --- src/Controllers/AbstractController.php | 3 +- src/Controllers/AuthController.php | 27 ++-- src/Controllers/CommentController.php | 70 ++++++---- src/Controllers/FavoritesController.php | 18 ++- src/Controllers/GlobalParamController.php | 7 +- src/Controllers/HistoryController.php | 21 ++- src/Controllers/PostContentController.php | 15 ++- src/Controllers/PostController.php | 103 ++++++++------- src/Controllers/ScoreController.php | 28 ++-- src/Controllers/TagController.php | 21 ++- src/Controllers/UserAvatarController.php | 22 ++-- src/Controllers/UserController.php | 59 +++++---- .../ViewProxies/CommentViewProxy.php | 6 +- src/Controllers/ViewProxies/PostViewProxy.php | 26 ++-- src/Controllers/ViewProxies/UserViewProxy.php | 11 +- src/Dao/AbstractDao.php | 47 ++++--- src/Dao/CommentDao.php | 27 ++-- .../AbstractEntityConverter.php | 7 +- .../CommentEntityConverter.php | 8 +- .../FavoriteEntityConverter.php | 6 +- .../GlobalParamEntityConverter.php | 6 +- src/Dao/EntityConverters/IEntityConverter.php | 3 +- .../EntityConverters/PostEntityConverter.php | 14 +- .../EntityConverters/ScoreEntityConverter.php | 6 +- .../SnapshotEntityConverter.php | 6 +- .../EntityConverters/TagEntityConverter.php | 8 +- .../EntityConverters/TokenEntityConverter.php | 6 +- .../EntityConverters/UserEntityConverter.php | 6 +- src/Dao/FavoritesDao.php | 29 +++-- src/Dao/GlobalParamDao.php | 6 +- src/Dao/PostDao.php | 72 ++++++----- src/Dao/ScoreDao.php | 28 ++-- src/Dao/SnapshotDao.php | 19 ++- src/Dao/TagDao.php | 7 +- src/Dao/TokenDao.php | 6 +- src/Dao/TransactionManager.php | 3 +- src/Dao/UserDao.php | 24 ++-- src/DatabaseConnection.php | 3 +- src/Dispatcher.php | 24 ++-- src/Entities/Comment.php | 6 +- src/Entities/Favorite.php | 6 +- src/Entities/Post.php | 3 +- src/Entities/Score.php | 4 +- src/Entities/Snapshot.php | 3 +- src/FormData/LoginFormData.php | 6 +- src/FormData/PostEditFormData.php | 9 +- src/FormData/RegistrationFormData.php | 6 +- src/FormData/UploadFormData.php | 9 +- src/FormData/UserEditFormData.php | 16 ++- src/Helpers/EnumHelper.php | 37 +++--- src/IValidatable.php | 3 +- src/Injector.php | 6 +- src/Route.php | 5 +- src/Router.php | 10 +- src/SearchServices/Filters/BasicFilter.php | 5 +- src/SearchServices/Filters/IFilter.php | 5 +- .../Parsers/AbstractSearchParser.php | 42 +++--- .../Parsers/PostSearchParser.php | 110 ++++++++-------- .../Parsers/SnapshotSearchParser.php | 33 +++-- .../Parsers/TagSearchParser.php | 35 ++--- .../Parsers/UserSearchParser.php | 27 ++-- src/SearchServices/Result.php | 3 +- src/Services/AuthService.php | 31 +++-- src/Services/CommentService.php | 32 +++-- src/Services/EmailService.php | 9 +- src/Services/FavoritesService.php | 23 ++-- src/Services/FileService.php | 4 +- src/Services/HistoryService.php | 63 +++++---- .../ImageManipulation/ImageManipulator.php | 6 +- src/Services/PasswordService.php | 3 +- src/Services/PostService.php | 121 ++++++++++-------- src/Services/PrivilegeService.php | 12 +- src/Services/ScoreService.php | 26 ++-- src/Services/TagService.php | 18 ++- .../FlashThumbnailGenerator.php | 9 +- .../ImageThumbnailGenerator.php | 6 +- .../SmartThumbnailGenerator.php | 9 +- .../VideoThumbnailGenerator.php | 9 +- src/Services/ThumbnailService.php | 14 +- src/Services/TokenService.php | 9 +- src/Services/UpgradeService.php | 14 +- src/Services/UserService.php | 98 ++++++++------ src/Upgrades/IUpgrade.php | 3 +- src/Upgrades/Upgrade01.php | 3 +- src/Upgrades/Upgrade02.php | 3 +- src/Upgrades/Upgrade03.php | 3 +- src/Upgrades/Upgrade04.php | 18 ++- src/Upgrades/Upgrade05.php | 3 +- src/Upgrades/Upgrade06.php | 3 +- src/Upgrades/Upgrade07.php | 3 +- src/Upgrades/Upgrade08.php | 3 +- src/Upgrades/Upgrade09.php | 9 +- src/Upgrades/Upgrade10.php | 3 +- src/Upgrades/Upgrade11.php | 3 +- src/Upgrades/Upgrade12.php | 6 +- src/Upgrades/Upgrade13.php | 3 +- src/Upgrades/Upgrade14.php | 3 +- src/Upgrades/Upgrade15.php | 3 +- src/Upgrades/Upgrade16.php | 3 +- src/Upgrades/Upgrade17.php | 3 +- src/Upgrades/Upgrade18.php | 3 +- src/Validator.php | 6 +- tests/AbstractDatabaseTestCase.php | 35 +++-- tests/AbstractTestCase.php | 6 +- tests/ConfigMock.php | 3 +- tests/ConfigTest.php | 6 +- tests/ControllerRepositoryTest.php | 6 +- tests/Dao/CommentDaoTest.php | 32 +++-- tests/Dao/FavoritesDaoTest.php | 18 ++- tests/Dao/GlobalParamDaoTest.php | 15 ++- tests/Dao/PostDaoTest.php | 26 ++-- tests/Dao/ScoreDaoTest.php | 34 +++-- tests/Dao/SnapshotDaoTest.php | 19 ++- tests/Dao/TagDaoTest.php | 15 ++- tests/Dao/TokenDaoTest.php | 19 +-- tests/Dao/TransactionManagerTest.php | 14 +- tests/Dao/UserDaoFilterTest.php | 42 +++--- tests/Dao/UserDaoTest.php | 19 ++- tests/DispatcherTest.php | 21 ++- tests/Helpers/InputReaderTest.php | 8 +- tests/Helpers/MimeHelperTest.php | 36 +++--- tests/Helpers/ProgramExecutorTest.php | 6 +- tests/PrivilegeTest.php | 12 +- tests/RouterTest.php | 29 +++-- tests/SearchServices/UserSearchParserTest.php | 5 +- tests/Services/AuthServiceTest.php | 53 ++++---- tests/Services/FavoritesServiceTest.php | 43 ++++--- tests/Services/FileServiceTest.php | 13 +- tests/Services/HistoryServiceTest.php | 46 ++++--- tests/Services/ImageManipulatorTest.php | 22 ++-- tests/Services/PasswordServiceTest.php | 6 +- tests/Services/PostServiceTest.php | 96 ++++++++------ tests/Services/PrivilegeServiceTest.php | 35 ++--- tests/Services/ScoreServiceTest.php | 37 ++++-- tests/Services/TagServiceTest.php | 27 ++-- tests/Services/ThumbnailGeneratorTest.php | 32 +++-- tests/Services/ThumbnailServiceTest.php | 19 ++- tests/Services/UserServiceTest.php | 88 +++++++------ tests/TransactionManagerMock.php | 3 +- tests/ValidatorTest.php | 3 +- 140 files changed, 1673 insertions(+), 1076 deletions(-) diff --git a/src/Controllers/AbstractController.php b/src/Controllers/AbstractController.php index 5ff1d378..feed4ab0 100644 --- a/src/Controllers/AbstractController.php +++ b/src/Controllers/AbstractController.php @@ -1,7 +1,8 @@ authService = $authService; $this->userService = $userService; @@ -29,7 +38,7 @@ final class AuthController extends AbstractController $this->tokenViewProxy = $tokenViewProxy; } - public function registerRoutes(\Szurubooru\Router $router) + public function registerRoutes(Router $router) { $router->post('/api/login', [$this, 'login']); $router->put('/api/login', [$this, 'login']); @@ -39,7 +48,7 @@ final class AuthController extends AbstractController { if (isset($this->inputReader->userNameOrEmail) and isset($this->inputReader->password)) { - $formData = new \Szurubooru\FormData\LoginFormData($this->inputReader); + $formData = new LoginFormData($this->inputReader); $this->authService->loginFromCredentials($formData); $user = $this->authService->getLoggedInUser(); diff --git a/src/Controllers/CommentController.php b/src/Controllers/CommentController.php index 95fd1a4a..00c08b87 100644 --- a/src/Controllers/CommentController.php +++ b/src/Controllers/CommentController.php @@ -1,5 +1,19 @@ privilegeService = $privilegeService; $this->authService = $authService; @@ -29,7 +43,7 @@ class CommentController extends AbstractController $this->inputReader = $inputReader; } - public function registerRoutes(\Szurubooru\Router $router) + public function registerRoutes(Router $router) { $router->get('/api/comments', [$this, 'getComments']); $router->get('/api/comments/:postNameOrId', [$this, 'getPostComments']); @@ -40,19 +54,19 @@ class CommentController extends AbstractController public function getComments() { - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::LIST_COMMENTS); + $this->privilegeService->assertPrivilege(Privilege::LIST_COMMENTS); - $filter = new \Szurubooru\SearchServices\Filters\PostFilter(); + $filter = new PostFilter(); $filter->setPageSize(10); $filter->setPageNumber($this->inputReader->page); $filter->setOrder([ - \Szurubooru\SearchServices\Filters\PostFilter::ORDER_LAST_COMMENT_TIME => - \Szurubooru\SearchServices\Filters\PostFilter::ORDER_DESC]); + PostFilter::ORDER_LAST_COMMENT_TIME => + PostFilter::ORDER_DESC]); - $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); - $requirement->setValue(new \Szurubooru\SearchServices\Requirements\RequirementRangedValue()); + $requirement = new Requirement(); + $requirement->setValue(new RequirementRangedValue()); $requirement->getValue()->setMinValue(1); - $requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_COMMENT_COUNT); + $requirement->setType(PostFilter::REQUIREMENT_COMMENT_COUNT); $filter->addRequirement($requirement); $result = $this->postService->getFiltered($filter); @@ -77,17 +91,17 @@ class CommentController extends AbstractController public function getPostComments($postNameOrId) { - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::LIST_COMMENTS); + $this->privilegeService->assertPrivilege(Privilege::LIST_COMMENTS); $post = $this->postService->getByNameOrId($postNameOrId); - $filter = new \Szurubooru\SearchServices\Filters\CommentFilter(); + $filter = new CommentFilter(); $filter->setOrder([ - \Szurubooru\SearchServices\Filters\CommentFilter::ORDER_ID => - \Szurubooru\SearchServices\Filters\CommentFilter::ORDER_ASC]); + CommentFilter::ORDER_ID => + CommentFilter::ORDER_ASC]); - $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); - $requirement->setValue(new \Szurubooru\SearchServices\Requirements\RequirementSingleValue($post->getId())); - $requirement->setType(\Szurubooru\SearchServices\Filters\CommentFilter::REQUIREMENT_POST_ID); + $requirement = new Requirement(); + $requirement->setValue(new RequirementSingleValue($post->getId())); + $requirement->setType(CommentFilter::REQUIREMENT_POST_ID); $filter->addRequirement($requirement); $result = $this->commentService->getFiltered($filter); @@ -97,7 +111,7 @@ class CommentController extends AbstractController public function addComment($postNameOrId) { - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::ADD_COMMENTS); + $this->privilegeService->assertPrivilege(Privilege::ADD_COMMENTS); $post = $this->postService->getByNameOrId($postNameOrId); $comment = $this->commentService->createComment($post, $this->inputReader->text); @@ -110,8 +124,8 @@ class CommentController extends AbstractController $this->privilegeService->assertPrivilege( ($comment->getUser() and $this->privilegeService->isLoggedIn($comment->getUser())) - ? \Szurubooru\Privilege::EDIT_OWN_COMMENTS - : \Szurubooru\Privilege::EDIT_ALL_COMMENTS); + ? Privilege::EDIT_OWN_COMMENTS + : Privilege::EDIT_ALL_COMMENTS); $comment = $this->commentService->updateComment($comment, $this->inputReader->text); return $this->commentViewProxy->fromEntity($comment, $this->getCommentsFetchConfig()); @@ -123,8 +137,8 @@ class CommentController extends AbstractController $this->privilegeService->assertPrivilege( $this->privilegeService->isLoggedIn($comment->getUser()) - ? \Szurubooru\Privilege::DELETE_OWN_COMMENTS - : \Szurubooru\Privilege::DELETE_ALL_COMMENTS); + ? Privilege::DELETE_OWN_COMMENTS + : Privilege::DELETE_ALL_COMMENTS); return $this->commentService->deleteComment($comment); } @@ -133,7 +147,7 @@ class CommentController extends AbstractController { return [ - \Szurubooru\Controllers\ViewProxies\CommentViewProxy::FETCH_OWN_SCORE => true, + CommentViewProxy::FETCH_OWN_SCORE => true, ]; } } diff --git a/src/Controllers/FavoritesController.php b/src/Controllers/FavoritesController.php index 9791e5af..2b6c9fc6 100644 --- a/src/Controllers/FavoritesController.php +++ b/src/Controllers/FavoritesController.php @@ -1,5 +1,11 @@ privilegeService = $privilegeService; $this->authService = $authService; @@ -23,7 +29,7 @@ class FavoritesController extends AbstractController $this->userViewProxy = $userViewProxy; } - public function registerRoutes(\Szurubooru\Router $router) + public function registerRoutes(Router $router) { $router->get('/api/posts/:postNameOrId/favorites', [$this, 'getFavoriteUsers']); $router->post('/api/posts/:postNameOrId/favorites', [$this, 'addFavorite']); diff --git a/src/Controllers/GlobalParamController.php b/src/Controllers/GlobalParamController.php index 5338ede0..9b644fbb 100644 --- a/src/Controllers/GlobalParamController.php +++ b/src/Controllers/GlobalParamController.php @@ -1,17 +1,18 @@ globalParamDao = $globalParamDao; } - public function registerRoutes(\Szurubooru\Router $router) + public function registerRoutes(Router $router) { $router->get('/api/globals', [$this, 'getGlobals']); } diff --git a/src/Controllers/HistoryController.php b/src/Controllers/HistoryController.php index 726b4163..2291f8c0 100644 --- a/src/Controllers/HistoryController.php +++ b/src/Controllers/HistoryController.php @@ -1,5 +1,12 @@ historyService = $historyService; $this->privilegeService = $privilegeService; @@ -23,14 +30,14 @@ final class HistoryController extends AbstractController $this->snapshotViewProxy = $snapshotViewProxy; } - public function registerRoutes(\Szurubooru\Router $router) + public function registerRoutes(Router $router) { $router->get('/api/history', [$this, 'getFiltered']); } public function getFiltered() { - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::VIEW_HISTORY); + $this->privilegeService->assertPrivilege(Privilege::VIEW_HISTORY); $filter = $this->snapshotSearchParser->createFilterFromInputReader($this->inputReader); $filter->setPageSize(50); diff --git a/src/Controllers/PostContentController.php b/src/Controllers/PostContentController.php index 86fdaf4d..d4a523d4 100644 --- a/src/Controllers/PostContentController.php +++ b/src/Controllers/PostContentController.php @@ -1,5 +1,10 @@ postService = $postService; $this->fileService = $fileService; @@ -20,7 +25,7 @@ final class PostContentController extends AbstractController $this->thumbnailService = $thumbnailService; } - public function registerRoutes(\Szurubooru\Router $router) + public function registerRoutes(Router $router) { $router->get('/api/posts/:postName/content', [$this, 'getPostContent']); $router->get('/api/posts/:postName/thumbnail/:size', [$this, 'getPostThumbnail']); diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 77060985..fd20ea9c 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -1,5 +1,22 @@ config = $config; $this->authService = $authService; @@ -32,7 +49,7 @@ final class PostController extends AbstractController $this->snapshotViewProxy = $snapshotViewProxy; } - public function registerRoutes(\Szurubooru\Router $router) + public function registerRoutes(Router $router) { $router->post('/api/posts', [$this, 'createPost']); $router->get('/api/posts', [$this, 'getFiltered']); @@ -47,7 +64,7 @@ final class PostController extends AbstractController public function getByNameOrId($postNameOrId) { if ($postNameOrId !== 'featured') - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::VIEW_POSTS); + $this->privilegeService->assertPrivilege(Privilege::VIEW_POSTS); $post = $this->getByNameOrIdWithoutProxy($postNameOrId); return $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig()); @@ -55,14 +72,14 @@ final class PostController extends AbstractController public function getHistory($postNameOrId) { - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::VIEW_HISTORY); + $this->privilegeService->assertPrivilege(Privilege::VIEW_HISTORY); $post = $this->getByNameOrIdWithoutProxy($postNameOrId); return ['data' => $this->snapshotViewProxy->fromArray($this->postService->getHistory($post))]; } public function getFiltered() { - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::LIST_POSTS); + $this->privilegeService->assertPrivilege(Privilege::LIST_POSTS); $filter = $this->postSearchParser->createFilterFromInputReader($this->inputReader); $filter->setPageSize($this->config->posts->postsPerPage); @@ -78,13 +95,13 @@ final class PostController extends AbstractController public function createPost() { - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::UPLOAD_POSTS); - $formData = new \Szurubooru\FormData\UploadFormData($this->inputReader); + $this->privilegeService->assertPrivilege(Privilege::UPLOAD_POSTS); + $formData = new UploadFormData($this->inputReader); - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::UPLOAD_POSTS); + $this->privilegeService->assertPrivilege(Privilege::UPLOAD_POSTS); if ($formData->anonymous) - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::UPLOAD_POSTS_ANONYMOUSLY); + $this->privilegeService->assertPrivilege(Privilege::UPLOAD_POSTS_ANONYMOUSLY); $post = $this->postService->createPost($formData); return $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig()); @@ -93,22 +110,22 @@ final class PostController extends AbstractController public function updatePost($postNameOrId) { $post = $this->postService->getByNameOrId($postNameOrId); - $formData = new \Szurubooru\FormData\PostEditFormData($this->inputReader); + $formData = new PostEditFormData($this->inputReader); if ($formData->content !== null) - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::CHANGE_POST_CONTENT); + $this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_CONTENT); if ($formData->thumbnail !== null) - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::CHANGE_POST_THUMBNAIL); + $this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_THUMBNAIL); if ($formData->safety !== null) - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::CHANGE_POST_SAFETY); + $this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_SAFETY); if ($formData->source !== null) - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::CHANGE_POST_SOURCE); + $this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_SOURCE); if ($formData->tags !== null) - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::CHANGE_POST_TAGS); + $this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_TAGS); $this->postService->updatePost($post, $formData); $post = $this->postService->getByNameOrId($postNameOrId); @@ -139,12 +156,12 @@ final class PostController extends AbstractController { return [ - \Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_RELATIONS => true, - \Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_TAGS => true, - \Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_USER => true, - \Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_HISTORY => true, - \Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_OWN_SCORE => true, - \Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_FAVORITES => true, + PostViewProxy::FETCH_RELATIONS => true, + PostViewProxy::FETCH_TAGS => true, + PostViewProxy::FETCH_USER => true, + PostViewProxy::FETCH_HISTORY => true, + PostViewProxy::FETCH_OWN_SCORE => true, + PostViewProxy::FETCH_FAVORITES => true, ]; } @@ -152,7 +169,7 @@ final class PostController extends AbstractController { return [ - \Szurubooru\Controllers\ViewProxies\PostViewProxy::FETCH_TAGS => true, + PostViewProxy::FETCH_TAGS => true, ]; } @@ -163,33 +180,33 @@ final class PostController extends AbstractController if (!$userSettings) return; - if (!empty($userSettings->listPosts) and !count($filter->getRequirementsByType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_SAFETY))) + if (!empty($userSettings->listPosts) and !count($filter->getRequirementsByType(PostFilter::REQUIREMENT_SAFETY))) { $values = []; - if (!\Szurubooru\Helpers\TypeHelper::toBool($userSettings->listPosts->safe)) - $values[] = \Szurubooru\Entities\Post::POST_SAFETY_SAFE; - if (!\Szurubooru\Helpers\TypeHelper::toBool($userSettings->listPosts->sketchy)) - $values[] = \Szurubooru\Entities\Post::POST_SAFETY_SKETCHY; - if (!\Szurubooru\Helpers\TypeHelper::toBool($userSettings->listPosts->unsafe)) - $values[] = \Szurubooru\Entities\Post::POST_SAFETY_UNSAFE; + if (!TypeHelper::toBool($userSettings->listPosts->safe)) + $values[] = Post::POST_SAFETY_SAFE; + if (!TypeHelper::toBool($userSettings->listPosts->sketchy)) + $values[] = Post::POST_SAFETY_SKETCHY; + if (!TypeHelper::toBool($userSettings->listPosts->unsafe)) + $values[] = Post::POST_SAFETY_UNSAFE; if (count($values)) { - $requirementValue = new \Szurubooru\SearchServices\Requirements\RequirementCompositeValue(); + $requirementValue = new RequirementCompositeValue(); $requirementValue->setValues($values); - $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); - $requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_SAFETY); + $requirement = new Requirement(); + $requirement->setType(PostFilter::REQUIREMENT_SAFETY); $requirement->setValue($requirementValue); $requirement->setNegated(true); $filter->addRequirement($requirement); } } - if (!empty($userSettings->hideDownvoted) and !count($filter->getRequirementsByType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_USER_SCORE))) + if (!empty($userSettings->hideDownvoted) and !count($filter->getRequirementsByType(PostFilter::REQUIREMENT_USER_SCORE))) { - $requirementValue = new \Szurubooru\SearchServices\Requirements\RequirementCompositeValue(); + $requirementValue = new RequirementCompositeValue(); $requirementValue->setValues([$currentUser->getName(), -1]); - $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); - $requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_USER_SCORE); + $requirement = new Requirement(); + $requirement->setType(PostFilter::REQUIREMENT_USER_SCORE); $requirement->setValue($requirementValue); $requirement->setNegated(true); $filter->addRequirement($requirement); diff --git a/src/Controllers/ScoreController.php b/src/Controllers/ScoreController.php index ca6afc87..6173c496 100644 --- a/src/Controllers/ScoreController.php +++ b/src/Controllers/ScoreController.php @@ -1,7 +1,15 @@ privilegeService = $privilegeService; $this->authService = $authService; @@ -26,7 +34,7 @@ class ScoreController extends AbstractController $this->inputReader = $inputReader; } - public function registerRoutes(\Szurubooru\Router $router) + public function registerRoutes(Router $router) { $router->get('/api/posts/:postNameOrId/score', [$this, 'getPostScore']); $router->post('/api/posts/:postNameOrId/score', [$this, 'setPostScore']); @@ -58,7 +66,7 @@ class ScoreController extends AbstractController return $this->setScore($comment); } - private function setScore(\Szurubooru\Entities\Entity $entity) + private function setScore(Entity $entity) { $this->privilegeService->assertLoggedIn(); $score = intval($this->inputReader->score); @@ -67,7 +75,7 @@ class ScoreController extends AbstractController return ['score' => $result->getScore()]; } - private function getScore(\Szurubooru\Entities\Entity $entity) + private function getScore(Entity $entity) { $this->privilegeService->assertLoggedIn(); $user = $this->authService->getLoggedInUser(); diff --git a/src/Controllers/TagController.php b/src/Controllers/TagController.php index 0ab5a4f9..bb3b30d2 100644 --- a/src/Controllers/TagController.php +++ b/src/Controllers/TagController.php @@ -1,5 +1,12 @@ privilegeService = $privilegeService; $this->tagService = $tagService; @@ -23,14 +30,14 @@ final class TagController extends AbstractController $this->inputReader = $inputReader; } - public function registerRoutes(\Szurubooru\Router $router) + public function registerRoutes(Router $router) { $router->get('/api/tags', [$this, 'getTags']); } public function getTags() { - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::LIST_TAGS); + $this->privilegeService->assertPrivilege(Privilege::LIST_TAGS); $filter = $this->tagSearchParser->createFilterFromInputReader($this->inputReader); $filter->setPageSize(50); diff --git a/src/Controllers/UserAvatarController.php b/src/Controllers/UserAvatarController.php index 2eb1aca6..d3ecfd5c 100644 --- a/src/Controllers/UserAvatarController.php +++ b/src/Controllers/UserAvatarController.php @@ -1,5 +1,11 @@ userService = $userService; $this->fileService = $fileService; @@ -20,7 +26,7 @@ final class UserAvatarController extends AbstractController $this->thumbnailService = $thumbnailService; } - public function registerRoutes(\Szurubooru\Router $router) + public function registerRoutes(Router $router) { $router->get('/api/users/:userName/avatar/:size', [$this, 'getAvatarByName']); } @@ -38,17 +44,17 @@ final class UserAvatarController extends AbstractController switch ($user->getAvatarStyle()) { - case \Szurubooru\Entities\User::AVATAR_STYLE_GRAVATAR: + case User::AVATAR_STYLE_GRAVATAR: $hash = md5(strtolower(trim($user->getEmail() ? $user->getEmail() : $user->getId() . $user->getName()))); $url = 'https://www.gravatar.com/avatar/' . $hash . '?d=retro&s=' . $size; $this->serveFromUrl($url); break; - case \Szurubooru\Entities\User::AVATAR_STYLE_BLANK: + case User::AVATAR_STYLE_BLANK: $this->serveBlankFile($size); break; - case \Szurubooru\Entities\User::AVATAR_STYLE_MANUAL: + case User::AVATAR_STYLE_MANUAL: $this->serveFromFile($user->getCustomAvatarSourceContentPath(), $size); break; diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index 610b3b99..63204d38 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -1,5 +1,16 @@ config = $config; $this->privilegeService = $privilegeService; @@ -29,7 +40,7 @@ final class UserController extends AbstractController $this->userViewProxy = $userViewProxy; } - public function registerRoutes(\Szurubooru\Router $router) + public function registerRoutes(Router $router) { $router->post('/api/users', [$this, 'createUser']); $router->get('/api/users', [$this, 'getFiltered']); @@ -44,14 +55,14 @@ final class UserController extends AbstractController public function getByNameOrEmail($userNameOrEmail) { - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::VIEW_USERS); + $this->privilegeService->assertPrivilege(Privilege::VIEW_USERS); $user = $this->userService->getByNameOrEmail($userNameOrEmail); return $this->userViewProxy->fromEntity($user); } public function getFiltered() { - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::LIST_USERS); + $this->privilegeService->assertPrivilege(Privilege::LIST_USERS); $filter = $this->userSearchParser->createFilterFromInputReader($this->inputReader); $filter->setPageSize($this->config->users->usersPerPage); @@ -65,8 +76,8 @@ final class UserController extends AbstractController public function createUser() { - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::REGISTER); - $formData = new \Szurubooru\FormData\RegistrationFormData($this->inputReader); + $this->privilegeService->assertPrivilege(Privilege::REGISTER); + $formData = new RegistrationFormData($this->inputReader); $user = $this->userService->createUser($formData); return $this->userViewProxy->fromEntity($user); } @@ -74,43 +85,43 @@ final class UserController extends AbstractController public function updateUser($userNameOrEmail) { $user = $this->userService->getByNameOrEmail($userNameOrEmail); - $formData = new \Szurubooru\FormData\UserEditFormData($this->inputReader); + $formData = new UserEditFormData($this->inputReader); if ($formData->avatarStyle !== null || $formData->avatarContent !== null) { $this->privilegeService->assertPrivilege( $this->privilegeService->isLoggedIn($userNameOrEmail) - ? \Szurubooru\Privilege::CHANGE_OWN_AVATAR_STYLE - : \Szurubooru\Privilege::CHANGE_ALL_AVATAR_STYLES); + ? Privilege::CHANGE_OWN_AVATAR_STYLE + : Privilege::CHANGE_ALL_AVATAR_STYLES); } if ($formData->userName !== null) { $this->privilegeService->assertPrivilege( $this->privilegeService->isLoggedIn($userNameOrEmail) - ? \Szurubooru\Privilege::CHANGE_OWN_NAME - : \Szurubooru\Privilege::CHANGE_ALL_NAMES); + ? Privilege::CHANGE_OWN_NAME + : Privilege::CHANGE_ALL_NAMES); } if ($formData->password !== null) { $this->privilegeService->assertPrivilege( $this->privilegeService->isLoggedIn($userNameOrEmail) - ? \Szurubooru\Privilege::CHANGE_OWN_PASSWORD - : \Szurubooru\Privilege::CHANGE_ALL_PASSWORDS); + ? Privilege::CHANGE_OWN_PASSWORD + : Privilege::CHANGE_ALL_PASSWORDS); } if ($formData->email !== null) { $this->privilegeService->assertPrivilege( $this->privilegeService->isLoggedIn($userNameOrEmail) - ? \Szurubooru\Privilege::CHANGE_OWN_EMAIL_ADDRESS - : \Szurubooru\Privilege::CHANGE_ALL_EMAIL_ADDRESSES); + ? Privilege::CHANGE_OWN_EMAIL_ADDRESS + : Privilege::CHANGE_ALL_EMAIL_ADDRESSES); } if ($formData->accessRank) { - $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::CHANGE_ACCESS_RANK); + $this->privilegeService->assertPrivilege(Privilege::CHANGE_ACCESS_RANK); } if ($formData->browsingSettings) @@ -126,8 +137,8 @@ final class UserController extends AbstractController { $this->privilegeService->assertPrivilege( $this->privilegeService->isLoggedIn($userNameOrEmail) - ? \Szurubooru\Privilege::DELETE_OWN_ACCOUNT - : \Szurubooru\Privilege::DELETE_ACCOUNTS); + ? Privilege::DELETE_OWN_ACCOUNT + : Privilege::DELETE_ACCOUNTS); $user = $this->userService->getByNameOrEmail($userNameOrEmail); return $this->userService->deleteUser($user); diff --git a/src/Controllers/ViewProxies/CommentViewProxy.php b/src/Controllers/ViewProxies/CommentViewProxy.php index a26a9a4d..a3e50e46 100644 --- a/src/Controllers/ViewProxies/CommentViewProxy.php +++ b/src/Controllers/ViewProxies/CommentViewProxy.php @@ -1,5 +1,7 @@ authService = $authService; diff --git a/src/Controllers/ViewProxies/PostViewProxy.php b/src/Controllers/ViewProxies/PostViewProxy.php index 91f49ce9..31e83bd1 100644 --- a/src/Controllers/ViewProxies/PostViewProxy.php +++ b/src/Controllers/ViewProxies/PostViewProxy.php @@ -1,5 +1,13 @@ name = $post->getName(); $result->uploadTime = $post->getUploadTime(); $result->lastEditTime = $post->getLastEditTime(); - $result->safety = \Szurubooru\Helpers\EnumHelper::postSafetyToString($post->getSafety()); - $result->contentType = \Szurubooru\Helpers\EnumHelper::postTypeToString($post->getContentType()); + $result->safety = EnumHelper::postSafetyToString($post->getSafety()); + $result->contentType = EnumHelper::postTypeToString($post->getContentType()); $result->contentChecksum = $post->getContentChecksum(); $result->contentMimeType = $post->getContentMimeType(); - $result->contentExtension = \Szurubooru\Helpers\MimeHelper::getExtension($post->getContentMimeType()); + $result->contentExtension = MimeHelper::getExtension($post->getContentMimeType()); $result->source = $post->getSource(); $result->imageWidth = $post->getImageWidth(); $result->imageHeight = $post->getImageHeight(); @@ -76,7 +84,7 @@ class PostViewProxy extends AbstractViewProxy if (!empty($config[self::FETCH_HISTORY])) { - if ($this->privilegeService->hasPrivilege(\Szurubooru\Privilege::VIEW_HISTORY)) + if ($this->privilegeService->hasPrivilege(Privilege::VIEW_HISTORY)) $result->history = $this->snapshotViewProxy->fromArray($this->historyService->getPostHistory($post)); else $result->history = []; diff --git a/src/Controllers/ViewProxies/UserViewProxy.php b/src/Controllers/ViewProxies/UserViewProxy.php index 27e8b07b..c41615ba 100644 --- a/src/Controllers/ViewProxies/UserViewProxy.php +++ b/src/Controllers/ViewProxies/UserViewProxy.php @@ -1,11 +1,14 @@ privilegeService = $privilegeService; } @@ -17,10 +20,10 @@ class UserViewProxy extends AbstractViewProxy { $result->id = $user->getId(); $result->name = $user->getName(); - $result->accessRank = \Szurubooru\Helpers\EnumHelper::accessRankToString($user->getAccessRank()); + $result->accessRank = EnumHelper::accessRankToString($user->getAccessRank()); $result->registrationTime = $user->getRegistrationTime(); $result->lastLoginTime = $user->getLastLoginTime(); - $result->avatarStyle = \Szurubooru\Helpers\EnumHelper::avatarStyleToString($user->getAvatarStyle()); + $result->avatarStyle = EnumHelper::avatarStyleToString($user->getAvatarStyle()); $result->banned = $user->isBanned(); if ($this->privilegeService->isLoggedIn($user)) @@ -28,7 +31,7 @@ class UserViewProxy extends AbstractViewProxy $result->browsingSettings = $user->getBrowsingSettings(); } - if ($this->privilegeService->hasPrivilege(\Szurubooru\Privilege::VIEW_ALL_EMAIL_ADDRESSES) or + if ($this->privilegeService->hasPrivilege(Privilege::VIEW_ALL_EMAIL_ADDRESSES) or $this->privilegeService->isLoggedIn($user)) { $result->email = $user->getEmail(); diff --git a/src/Dao/AbstractDao.php b/src/Dao/AbstractDao.php index a6d6fa47..5a1fc0c6 100644 --- a/src/Dao/AbstractDao.php +++ b/src/Dao/AbstractDao.php @@ -1,5 +1,14 @@ setDatabaseConnection($databaseConnection); $this->tableName = $tableName; @@ -70,7 +79,7 @@ abstract class AbstractDao implements ICrudDao return $this->findBy($this->getIdColumn(), $entityIds); } - public function findFiltered(\Szurubooru\SearchServices\Filters\IFilter $searchFilter) + public function findFiltered(IFilter $searchFilter) { $query = $this->fpdo->from($this->tableName)->disableSmartJoin(); @@ -90,7 +99,7 @@ abstract class AbstractDao implements ICrudDao $this->decorateQueryFromFilter($query, $searchFilter); $totalRecords = count($query); - $searchResult = new \Szurubooru\SearchServices\Result(); + $searchResult = new Result(); $searchResult->setSearchFilter($searchFilter); $searchResult->setEntities($entities); $searchResult->setTotalRecords($totalRecords); @@ -113,14 +122,14 @@ abstract class AbstractDao implements ICrudDao return $this->deleteBy($this->getIdColumn(), $entityId); } - protected function update(\Szurubooru\Entities\Entity $entity) + protected function update(Entity $entity) { $arrayEntity = $this->entityConverter->toArray($entity); $this->fpdo->update($this->tableName)->set($arrayEntity)->where($this->getIdColumn(), $entity->getId())->execute(); return $entity; } - protected function create(\Szurubooru\Entities\Entity $entity) + protected function create(Entity $entity) { $arrayEntity = $this->entityConverter->toArray($entity); $this->fpdo->insertInto($this->tableName)->values($arrayEntity)->execute(); @@ -164,11 +173,11 @@ abstract class AbstractDao implements ICrudDao $this->fpdo->deleteFrom($this->tableName)->where($columnName, $value)->execute(); } - protected function afterLoad(\Szurubooru\Entities\Entity $entity) + protected function afterLoad(Entity $entity) { } - protected function afterSave(\Szurubooru\Entities\Entity $entity) + protected function afterSave(Entity $entity) { } @@ -176,16 +185,16 @@ abstract class AbstractDao implements ICrudDao { } - protected function beforeDelete(\Szurubooru\Entities\Entity $entity) + protected function beforeDelete(Entity $entity) { } - protected function decorateQueryFromRequirement($query, \Szurubooru\SearchServices\Requirements\Requirement $requirement) + protected function decorateQueryFromRequirement($query, Requirement $requirement) { $value = $requirement->getValue(); $sqlColumn = $requirement->getType(); - if ($value instanceof \Szurubooru\SearchServices\Requirements\RequirementCompositeValue) + if ($value instanceof RequirementCompositeValue) { $sql = $sqlColumn; $bindings = [$value->getValues()]; @@ -194,7 +203,7 @@ abstract class AbstractDao implements ICrudDao $sql = 'NOT ' . $sql; } - else if ($value instanceof \Szurubooru\SearchServices\Requirements\RequirementRangedValue) + else if ($value instanceof RequirementRangedValue) { if ($value->getMinValue() and $value->getMaxValue()) { @@ -218,7 +227,7 @@ abstract class AbstractDao implements ICrudDao $sql = 'NOT (' . $sql . ')'; } - else if ($value instanceof \Szurubooru\SearchServices\Requirements\RequirementSingleValue) + else if ($value instanceof RequirementSingleValue) { $sql = $sqlColumn; $bindings = [$value->getValue()]; @@ -230,7 +239,7 @@ abstract class AbstractDao implements ICrudDao else throw new \Exception('Bad value: ' . get_class($value)); - call_user_func_array([$query, 'where'], array_merge([$sql], $bindings)); + $query->where($sql, ...$bindings); } protected function arrayToEntities(array $arrayEntities) @@ -244,14 +253,14 @@ abstract class AbstractDao implements ICrudDao return $entities; } - private function setDatabaseConnection(\Szurubooru\DatabaseConnection $databaseConnection) + private function setDatabaseConnection(DatabaseConnection $databaseConnection) { $this->pdo = $databaseConnection->getPDO(); $this->fpdo = new \FluentPDO($this->pdo); $this->driver = $databaseConnection->getDriver(); } - private function decorateQueryFromFilter($query, \Szurubooru\SearchServices\Filters\IFilter $filter) + private function decorateQueryFromFilter($query, IFilter $filter) { foreach ($filter->getRequirements() as $requirement) { @@ -264,7 +273,7 @@ abstract class AbstractDao implements ICrudDao $orderByString = ''; foreach ($order as $orderColumn => $orderDir) { - if ($orderColumn === \Szurubooru\SearchServices\Filters\BasicFilter::ORDER_RANDOM) + if ($orderColumn === IFilter::ORDER_RANDOM) { $driver = $this->driver; if ($driver === 'sqlite') @@ -276,12 +285,12 @@ abstract class AbstractDao implements ICrudDao $orderColumn = 'RAND()'; } } - $orderByString .= $orderColumn . ' ' . ($orderDir === \Szurubooru\SearchServices\Filters\IFilter::ORDER_DESC ? 'DESC' : 'ASC') . ', '; + $orderByString .= $orderColumn . ' ' . ($orderDir === IFilter::ORDER_DESC ? 'DESC' : 'ASC') . ', '; } return substr($orderByString, 0, -2); } - private function upsert(\Szurubooru\Entities\Entity $entity) + private function upsert(Entity $entity) { if ($entity->getId()) { diff --git a/src/Dao/CommentDao.php b/src/Dao/CommentDao.php index 734db687..cfa84f0b 100644 --- a/src/Dao/CommentDao.php +++ b/src/Dao/CommentDao.php @@ -1,5 +1,12 @@ userDao = $userDao; $this->postDao = $postDao; } - public function findByPost(\Szurubooru\Entities\Post $post) + public function findByPost(Post $post) { return $this->findBy('postId', $post->getId()); } - protected function afterLoad(\Szurubooru\Entities\Entity $comment) + protected function afterLoad(Entity $comment) { $comment->setLazyLoader( - \Szurubooru\Entities\Comment::LAZY_LOADER_USER, - function (\Szurubooru\Entities\Comment $comment) + Comment::LAZY_LOADER_USER, + function (Comment $comment) { return $this->userDao->findById($comment->getUserId()); }); $comment->setLazyLoader( - \Szurubooru\Entities\Comment::LAZY_LOADER_POST, - function (\Szurubooru\Entities\Comment $comment) + Comment::LAZY_LOADER_POST, + function (Comment $comment) { return $this->postDao->findById($comment->getPostId()); }); diff --git a/src/Dao/EntityConverters/AbstractEntityConverter.php b/src/Dao/EntityConverters/AbstractEntityConverter.php index fee0dab4..c3268109 100644 --- a/src/Dao/EntityConverters/AbstractEntityConverter.php +++ b/src/Dao/EntityConverters/AbstractEntityConverter.php @@ -5,7 +5,7 @@ abstract class AbstractEntityConverter implements IEntityConverter { private $entityDecorator = null; - public function setEntityDecorator($entityDecorator) + public function setEntityDecorator(callable $entityDecorator) { $this->entityDecorator = $entityDecorator; } @@ -13,8 +13,9 @@ abstract class AbstractEntityConverter implements IEntityConverter public function toEntity(array $array) { $entity = $this->toBasicEntity($array); - if ($this->entityDecorator !== null) - call_user_func($this->entityDecorator, $entity); + $func = $this->entityDecorator; + if ($func !== null) + $func($entity); return $entity; } diff --git a/src/Dao/EntityConverters/CommentEntityConverter.php b/src/Dao/EntityConverters/CommentEntityConverter.php index 3335a217..3d618549 100644 --- a/src/Dao/EntityConverters/CommentEntityConverter.php +++ b/src/Dao/EntityConverters/CommentEntityConverter.php @@ -1,9 +1,11 @@ setUserId($array['userId']); $entity->setPostId($array['postId']); $entity->setText($array['text']); $entity->setCreationTime($this->dbTimeToEntityTime($array['creationTime'])); $entity->setLastEditTime($this->dbTimeToEntityTime($array['lastEditTime'])); - $entity->setMeta(\Szurubooru\Entities\Comment::META_SCORE, intval($array['score'])); + $entity->setMeta(Comment::META_SCORE, intval($array['score'])); return $entity; } } diff --git a/src/Dao/EntityConverters/FavoriteEntityConverter.php b/src/Dao/EntityConverters/FavoriteEntityConverter.php index 3db49b67..db50785a 100644 --- a/src/Dao/EntityConverters/FavoriteEntityConverter.php +++ b/src/Dao/EntityConverters/FavoriteEntityConverter.php @@ -1,9 +1,11 @@ setUserId($array['userId']); $entity->setPostId($array['postId']); $entity->setTime($this->dbTimeToEntityTime($array['time'])); diff --git a/src/Dao/EntityConverters/GlobalParamEntityConverter.php b/src/Dao/EntityConverters/GlobalParamEntityConverter.php index 5ff69a97..56ea827d 100644 --- a/src/Dao/EntityConverters/GlobalParamEntityConverter.php +++ b/src/Dao/EntityConverters/GlobalParamEntityConverter.php @@ -1,9 +1,11 @@ setKey($array['dataKey']); $entity->setValue($array['dataValue']); return $entity; diff --git a/src/Dao/EntityConverters/IEntityConverter.php b/src/Dao/EntityConverters/IEntityConverter.php index 70f28211..f35b50a1 100644 --- a/src/Dao/EntityConverters/IEntityConverter.php +++ b/src/Dao/EntityConverters/IEntityConverter.php @@ -1,9 +1,10 @@ setName($array['name']); $entity->setUserId($array['userId']); $entity->setUploadTime($this->dbTimeToEntityTime($array['uploadTime'])); @@ -44,10 +46,10 @@ class PostEntityConverter extends AbstractEntityConverter implements IEntityConv $entity->setOriginalFileName($array['originalFileName']); $entity->setFeatureCount(intval($array['featureCount'])); $entity->setLastFeatureTime($this->dbTimeToEntityTime($array['lastFeatureTime'])); - $entity->setMeta(\Szurubooru\Entities\Post::META_TAG_COUNT, intval($array['tagCount'])); - $entity->setMeta(\Szurubooru\Entities\Post::META_FAV_COUNT, intval($array['favCount'])); - $entity->setMeta(\Szurubooru\Entities\Post::META_COMMENT_COUNT, intval($array['commentCount'])); - $entity->setMeta(\Szurubooru\Entities\Post::META_SCORE, intval($array['score'])); + $entity->setMeta(Post::META_TAG_COUNT, intval($array['tagCount'])); + $entity->setMeta(Post::META_FAV_COUNT, intval($array['favCount'])); + $entity->setMeta(Post::META_COMMENT_COUNT, intval($array['commentCount'])); + $entity->setMeta(Post::META_SCORE, intval($array['score'])); return $entity; } } diff --git a/src/Dao/EntityConverters/ScoreEntityConverter.php b/src/Dao/EntityConverters/ScoreEntityConverter.php index ce7ec43b..9b99f21d 100644 --- a/src/Dao/EntityConverters/ScoreEntityConverter.php +++ b/src/Dao/EntityConverters/ScoreEntityConverter.php @@ -1,9 +1,11 @@ setUserId($array['userId']); $entity->setPostId($array['postId']); $entity->setCommentId($array['commentId']); diff --git a/src/Dao/EntityConverters/SnapshotEntityConverter.php b/src/Dao/EntityConverters/SnapshotEntityConverter.php index 3a869385..c8e160c6 100644 --- a/src/Dao/EntityConverters/SnapshotEntityConverter.php +++ b/src/Dao/EntityConverters/SnapshotEntityConverter.php @@ -1,9 +1,11 @@ setTime($this->dbTimeToEntityTime($array['time'])); $entity->setType(intval($array['type'])); $entity->setPrimaryKey($array['primaryKey']); diff --git a/src/Dao/EntityConverters/TagEntityConverter.php b/src/Dao/EntityConverters/TagEntityConverter.php index 9856ece3..c25a4341 100644 --- a/src/Dao/EntityConverters/TagEntityConverter.php +++ b/src/Dao/EntityConverters/TagEntityConverter.php @@ -1,9 +1,11 @@ setName($array['name']); $entity->setCreationTime($this->dbTimeToEntityTime($array['creationTime'])); - $entity->setMeta(\Szurubooru\Entities\Tag::META_USAGES, intval($array['usages'])); + $entity->setMeta(Tag::META_USAGES, intval($array['usages'])); return $entity; } } diff --git a/src/Dao/EntityConverters/TokenEntityConverter.php b/src/Dao/EntityConverters/TokenEntityConverter.php index 3b940299..6d1105d3 100644 --- a/src/Dao/EntityConverters/TokenEntityConverter.php +++ b/src/Dao/EntityConverters/TokenEntityConverter.php @@ -1,9 +1,11 @@ setName($array['name']); $entity->setPurpose($array['purpose']); $entity->setAdditionalData($array['additionalData']); diff --git a/src/Dao/EntityConverters/UserEntityConverter.php b/src/Dao/EntityConverters/UserEntityConverter.php index be474290..b53ebb7d 100644 --- a/src/Dao/EntityConverters/UserEntityConverter.php +++ b/src/Dao/EntityConverters/UserEntityConverter.php @@ -1,9 +1,11 @@ setName($array['name']); $entity->setEmail($array['email']); $entity->setEmailUnconfirmed($array['emailUnconfirmed']); diff --git a/src/Dao/FavoritesDao.php b/src/Dao/FavoritesDao.php index 5feba010..99e7afc5 100644 --- a/src/Dao/FavoritesDao.php +++ b/src/Dao/FavoritesDao.php @@ -1,40 +1,47 @@ timeService = $timeService; } - public function findByEntity(\Szurubooru\Entities\Entity $entity) + public function findByEntity(Entity $entity) { - if ($entity instanceof \Szurubooru\Entities\Post) + if ($entity instanceof Post) return $this->findBy('postId', $entity->getId()); else throw new \InvalidArgumentException(); } - public function set(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity) + public function set(User $user, Entity $entity) { $favorite = $this->get($user, $entity); if (!$favorite) { - $favorite = new \Szurubooru\Entities\Favorite(); + $favorite = new Favorite(); $favorite->setTime($this->timeService->getCurrentTime()); $favorite->setUserId($user->getId()); - if ($entity instanceof \Szurubooru\Entities\Post) + if ($entity instanceof Post) $favorite->setPostId($entity->getId()); else throw new \InvalidArgumentException(); @@ -44,18 +51,18 @@ class FavoritesDao extends AbstractDao implements ICrudDao return $favorite; } - public function delete(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity) + public function delete(User $user, Entity $entity) { $favorite = $this->get($user, $entity); if ($favorite) $this->deleteById($favorite->getId()); } - private function get(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity) + private function get(User $user, Entity $entity) { $query = $this->fpdo->from($this->tableName)->where('userId', $user->getId()); - if ($entity instanceof \Szurubooru\Entities\Post) + if ($entity instanceof Post) $query->where('postId', $entity->getId()); else throw new \InvalidArgumentException(); diff --git a/src/Dao/GlobalParamDao.php b/src/Dao/GlobalParamDao.php index d00c1c02..ba0817c5 100644 --- a/src/Dao/GlobalParamDao.php +++ b/src/Dao/GlobalParamDao.php @@ -1,14 +1,16 @@ tagDao = $tagDao; $this->userDao = $userDao; @@ -47,45 +57,45 @@ class PostDao extends AbstractDao implements ICrudDao return $this->findOneBy('contentChecksum', $checksum); } - protected function afterLoad(\Szurubooru\Entities\Entity $post) + protected function afterLoad(Entity $post) { $post->setLazyLoader( - \Szurubooru\Entities\Post::LAZY_LOADER_CONTENT, - function (\Szurubooru\Entities\Post $post) + Post::LAZY_LOADER_CONTENT, + function (Post $post) { return $this->fileService->load($post->getContentPath()); }); $post->setLazyLoader( - \Szurubooru\Entities\Post::LAZY_LOADER_THUMBNAIL_SOURCE_CONTENT, - function (\Szurubooru\Entities\Post $post) + Post::LAZY_LOADER_THUMBNAIL_SOURCE_CONTENT, + function (Post $post) { return $this->fileService->load($post->getThumbnailSourceContentPath()); }); $post->setLazyLoader( - \Szurubooru\Entities\Post::LAZY_LOADER_USER, - function (\Szurubooru\Entities\Post $post) + Post::LAZY_LOADER_USER, + function (Post $post) { return $this->getUser($post); }); $post->setLazyLoader( - \Szurubooru\Entities\Post::LAZY_LOADER_TAGS, - function (\Szurubooru\Entities\Post $post) + Post::LAZY_LOADER_TAGS, + function (Post $post) { return $this->getTags($post); }); $post->setLazyLoader( - \Szurubooru\Entities\Post::LAZY_LOADER_RELATED_POSTS, - function (\Szurubooru\Entities\Post $post) + Post::LAZY_LOADER_RELATED_POSTS, + function (Post $post) { return $this->getRelatedPosts($post); }); } - protected function afterSave(\Szurubooru\Entities\Entity $post) + protected function afterSave(Entity $post) { $this->syncContent($post); $this->syncThumbnailSourceContent($post); @@ -93,9 +103,9 @@ class PostDao extends AbstractDao implements ICrudDao $this->syncPostRelations($post); } - protected function decorateQueryFromRequirement($query, \Szurubooru\SearchServices\Requirements\Requirement $requirement) + protected function decorateQueryFromRequirement($query, Requirement $requirement) { - if ($requirement->getType() === \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_TAG) + if ($requirement->getType() === PostFilter::REQUIREMENT_TAG) { $sql = 'EXISTS ( SELECT 1 FROM postTags @@ -110,24 +120,24 @@ class PostDao extends AbstractDao implements ICrudDao return; } - elseif ($requirement->getType() === \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_FAVORITE) + elseif ($requirement->getType() === PostFilter::REQUIREMENT_FAVORITE) { $query->innerJoin('favorites _fav ON _fav.postId = posts.id'); $query->innerJoin('users favoritedBy ON favoritedBy.id = _fav.userId'); } - elseif ($requirement->getType() === \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_COMMENT) + elseif ($requirement->getType() === PostFilter::REQUIREMENT_COMMENT) { $query->innerJoin('comments _comment ON _comment.postId = posts.id'); $query->innerJoin('users commentedBy ON commentedBy.id = _comment.userId'); } - elseif ($requirement->getType() === \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_UPLOADER) + elseif ($requirement->getType() === PostFilter::REQUIREMENT_UPLOADER) { $query->innerJoin('users uploader ON uploader.id = userId'); } - elseif ($requirement->getType() === \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_USER_SCORE) + elseif ($requirement->getType() === PostFilter::REQUIREMENT_USER_SCORE) { $values = $requirement->getValue()->getValues(); $userName = $values[0]; @@ -147,17 +157,17 @@ class PostDao extends AbstractDao implements ICrudDao parent::decorateQueryFromRequirement($query, $requirement); } - private function getTags(\Szurubooru\Entities\Post $post) + private function getTags(Post $post) { return $this->tagDao->findByPostId($post->getId()); } - private function getUser(\Szurubooru\Entities\Post $post) + private function getUser(Post $post) { return $this->userDao->findById($post->getUserId()); } - private function getRelatedPosts(\Szurubooru\Entities\Post $post) + private function getRelatedPosts(Post $post) { $query = $this->fpdo ->from('postRelations') @@ -179,7 +189,7 @@ class PostDao extends AbstractDao implements ICrudDao return $this->findByIds($relatedPostIds); } - private function syncContent(\Szurubooru\Entities\Post $post) + private function syncContent(Post $post) { $targetPath = $post->getContentPath(); $content = $post->getContent(); @@ -190,7 +200,7 @@ class PostDao extends AbstractDao implements ICrudDao $this->thumbnailService->deleteUsedThumbnails($targetPath); } - private function syncThumbnailSourceContent(\Szurubooru\Entities\Post $post) + private function syncThumbnailSourceContent(Post $post) { $targetPath = $post->getThumbnailSourceContentPath(); $content = $post->getThumbnailSourceContent(); @@ -201,7 +211,7 @@ class PostDao extends AbstractDao implements ICrudDao $this->thumbnailService->deleteUsedThumbnails($targetPath); } - private function syncTags(\Szurubooru\Entities\Post $post) + private function syncTags(Post $post) { $tagIds = array_map( function ($tag) @@ -232,7 +242,7 @@ class PostDao extends AbstractDao implements ICrudDao } } - private function syncPostRelations(\Szurubooru\Entities\Post $post) + private function syncPostRelations(Post $post) { $this->fpdo->deleteFrom('postRelations')->where('post1id', $post->getId())->execute(); $this->fpdo->deleteFrom('postRelations')->where('post2id', $post->getId())->execute(); diff --git a/src/Dao/ScoreDao.php b/src/Dao/ScoreDao.php index 5b43f596..f77ebfbd 100644 --- a/src/Dao/ScoreDao.php +++ b/src/Dao/ScoreDao.php @@ -1,29 +1,37 @@ timeService = $timeService; } - public function getScore(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity) + public function getScore(User $user, Entity $entity) { $query = $this->fpdo->from($this->tableName)->where('userId', $user->getId()); - if ($entity instanceof \Szurubooru\Entities\Post) + if ($entity instanceof Post) $query->where('postId', $entity->getId()); - elseif ($entity instanceof \Szurubooru\Entities\Comment) + elseif ($entity instanceof Comment) $query->where('commentId', $entity->getId()); else throw new \InvalidArgumentException(); @@ -33,18 +41,18 @@ class ScoreDao extends AbstractDao implements ICrudDao return array_shift($entities); } - public function setScore(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity, $scoreValue) + public function setScore(User $user, Entity $entity, $scoreValue) { $score = $this->getScore($user, $entity); if (!$score) { - $score = new \Szurubooru\Entities\Score(); + $score = new Score(); $score->setTime($this->timeService->getCurrentTime()); $score->setUserId($user->getId()); - if ($entity instanceof \Szurubooru\Entities\Post) + if ($entity instanceof Post) $score->setPostId($entity->getId()); - elseif ($entity instanceof \Szurubooru\Entities\Comment) + elseif ($entity instanceof Comment) $score->setCommentId($entity->getId()); else throw new \InvalidArgumentException(); diff --git a/src/Dao/SnapshotDao.php b/src/Dao/SnapshotDao.php index e8d04498..8da43d49 100644 --- a/src/Dao/SnapshotDao.php +++ b/src/Dao/SnapshotDao.php @@ -1,18 +1,23 @@ userDao = $userDao; } @@ -27,17 +32,17 @@ class SnapshotDao extends AbstractDao return $this->arrayToEntities(iterator_to_array($query)); } - public function afterLoad(\Szurubooru\Entities\Entity $snapshot) + public function afterLoad(Entity $snapshot) { $snapshot->setLazyLoader( - \Szurubooru\Entities\Snapshot::LAZY_LOADER_USER, - function (\Szurubooru\Entities\Snapshot $snapshot) + Snapshot::LAZY_LOADER_USER, + function (Snapshot $snapshot) { return $this->getUser($snapshot); }); } - private function getUser(\Szurubooru\Entities\Snapshot $snapshot) + private function getUser(Snapshot $snapshot) { $userId = $snapshot->getUserId(); return $this->userDao->findById($userId); diff --git a/src/Dao/TagDao.php b/src/Dao/TagDao.php index 29fa2f16..e69324d3 100644 --- a/src/Dao/TagDao.php +++ b/src/Dao/TagDao.php @@ -1,15 +1,16 @@ databaseConnection = $databaseConnection; } diff --git a/src/Dao/UserDao.php b/src/Dao/UserDao.php index b2e494fb..c9de8f6e 100644 --- a/src/Dao/UserDao.php +++ b/src/Dao/UserDao.php @@ -1,5 +1,11 @@ fileService = $fileService; $this->thumbnailService = $thumbnailService; @@ -49,18 +55,18 @@ class UserDao extends AbstractDao implements ICrudDao $this->fpdo->deleteFrom('tokens')->where('additionalData', $userName); } - protected function afterLoad(\Szurubooru\Entities\Entity $user) + protected function afterLoad(Entity $user) { $user->setLazyLoader( - \Szurubooru\Entities\User::LAZY_LOADER_CUSTOM_AVATAR_SOURCE_CONTENT, - function(\Szurubooru\Entities\User $user) + User::LAZY_LOADER_CUSTOM_AVATAR_SOURCE_CONTENT, + function(User $user) { $avatarSource = $user->getCustomAvatarSourceContentPath(); return $this->fileService->load($avatarSource); }); } - protected function afterSave(\Szurubooru\Entities\Entity $user) + protected function afterSave(Entity $user) { $targetPath = $user->getCustomAvatarSourceContentPath(); $content = $user->getCustomAvatarSourceContent(); @@ -71,7 +77,7 @@ class UserDao extends AbstractDao implements ICrudDao $this->thumbnailService->deleteUsedThumbnails($targetPath); } - protected function afterDelete(\Szurubooru\Entities\Entity $user) + protected function afterDelete(Entity $user) { $avatarSource = $user->getCustomAvatarSourceContentPath(); $this->fileService->delete($avatarSource); diff --git a/src/DatabaseConnection.php b/src/DatabaseConnection.php index 30ac36d7..4068b3e8 100644 --- a/src/DatabaseConnection.php +++ b/src/DatabaseConnection.php @@ -1,12 +1,13 @@ config = $config; } diff --git a/src/Dispatcher.php b/src/Dispatcher.php index c7b64689..8667e60d 100644 --- a/src/Dispatcher.php +++ b/src/Dispatcher.php @@ -1,5 +1,13 @@ router = $router; $this->config = $config; @@ -52,7 +60,7 @@ final class Dispatcher ]; } $end = microtime(true); - $json['__time'] = $end - \Szurubooru\Bootstrap::getStartTime(); + $json['__time'] = $end - Bootstrap::getStartTime(); if ($this->config->misc->dumpSqlIntoQueries) { $json['__queries'] = $this->databaseConnection->getPDO()->getQueryCount(); diff --git a/src/Entities/Comment.php b/src/Entities/Comment.php index f255b114..153026c9 100644 --- a/src/Entities/Comment.php +++ b/src/Entities/Comment.php @@ -1,5 +1,7 @@ lazyLoad(self::LAZY_LOADER_USER, null); } - public function setUser(\Szurubooru\Entities\User $user = null) + public function setUser(User $user = null) { $this->lazySave(self::LAZY_LOADER_USER, $user); $this->userId = $user ? $user->getId() : null; @@ -80,7 +82,7 @@ final class Comment extends Entity return $this->lazyLoad(self::LAZY_LOADER_POST, null); } - public function setPost(\Szurubooru\Entities\Post $post) + public function setPost(Post $post) { $this->lazySave(self::LAZY_LOADER_POST, $post); $this->postId = $post->getId(); diff --git a/src/Entities/Favorite.php b/src/Entities/Favorite.php index edd7af40..8eb05734 100644 --- a/src/Entities/Favorite.php +++ b/src/Entities/Favorite.php @@ -1,5 +1,7 @@ lazyLoad(self::LAZY_LOADER_USER, null); } - public function setUser(\Szurubooru\Entities\User $user) + public function setUser(User $user) { $this->lazySave(self::LAZY_LOADER_USER, $user); $this->userId = $user->getId(); @@ -56,7 +58,7 @@ final class Favorite extends Entity return $this->lazyLoad(self::LAZY_LOADER_POST, null); } - public function setPost(\Szurubooru\Entities\Post $post) + public function setPost(Post $post) { $this->lazySave(self::LAZY_LOADER_POST, $post); $this->postId = $post->getId(); diff --git a/src/Entities/Post.php b/src/Entities/Post.php index f6979cf9..661cc4a6 100644 --- a/src/Entities/Post.php +++ b/src/Entities/Post.php @@ -1,5 +1,6 @@ lazyLoad(self::LAZY_LOADER_USER, null); } - public function setUser(\Szurubooru\Entities\User $user = null) + public function setUser(User $user = null) { $this->lazySave(self::LAZY_LOADER_USER, $user); $this->userId = $user ? $user->getId() : null; diff --git a/src/Entities/Score.php b/src/Entities/Score.php index 5f19fb0f..29a64ed6 100644 --- a/src/Entities/Score.php +++ b/src/Entities/Score.php @@ -4,10 +4,10 @@ namespace Szurubooru\Entities; final class Score extends Entity { private $postId; - private $userId; private $commentId; - private $time; private $score; + private $time; + private $userId; public function getUserId() { diff --git a/src/Entities/Snapshot.php b/src/Entities/Snapshot.php index 5eaed75a..0acafef3 100644 --- a/src/Entities/Snapshot.php +++ b/src/Entities/Snapshot.php @@ -1,5 +1,6 @@ lazyLoad(self::LAZY_LOADER_USER, null); } - public function setUser(\Szurubooru\Entities\User $user = null) + public function setUser(User $user = null) { $this->lazySave(self::LAZY_LOADER_USER, $user); $this->userId = $user ? $user->getId() : null; diff --git a/src/FormData/LoginFormData.php b/src/FormData/LoginFormData.php index 8b86fa30..2fb3977d 100644 --- a/src/FormData/LoginFormData.php +++ b/src/FormData/LoginFormData.php @@ -1,7 +1,9 @@ content = $inputReader->decodeBase64($inputReader->content); $this->thumbnail = $inputReader->decodebase64($inputReader->thumbnail); - $this->safety = \Szurubooru\Helpers\EnumHelper::postSafetyFromString($inputReader->safety); + $this->safety = EnumHelper::postSafetyFromString($inputReader->safety); $this->source = $inputReader->source; $this->tags = preg_split('/[\s+]/', $inputReader->tags); $this->relations = array_filter(preg_split('/[\s+]/', $inputReader->relations)); @@ -26,7 +29,7 @@ class PostEditFormData implements \Szurubooru\IValidatable } } - public function validate(\Szurubooru\Validator $validator) + public function validate(Validator $validator) { $validator->validatePostTags($this->tags); diff --git a/src/FormData/RegistrationFormData.php b/src/FormData/RegistrationFormData.php index 06a7b318..96bd3b7c 100644 --- a/src/FormData/RegistrationFormData.php +++ b/src/FormData/RegistrationFormData.php @@ -1,7 +1,9 @@ validateUserName($this->userName); $validator->validatePassword($this->password); diff --git a/src/FormData/UploadFormData.php b/src/FormData/UploadFormData.php index 63319bbd..674d8706 100644 --- a/src/FormData/UploadFormData.php +++ b/src/FormData/UploadFormData.php @@ -1,7 +1,10 @@ content = $inputReader->decodeBase64($inputReader->content); $this->url = $inputReader->url; $this->anonymous = $inputReader->anonymous; - $this->safety = \Szurubooru\Helpers\EnumHelper::postSafetyFromString($inputReader->safety); + $this->safety = EnumHelper::postSafetyFromString($inputReader->safety); $this->source = $inputReader->source; $this->tags = preg_split('/[\s+]/', $inputReader->tags); } } - public function validate(\Szurubooru\Validator $validator) + public function validate(Validator $validator) { if ($this->content === null and $this->url === null) throw new \DomainException('Neither data or URL provided.'); diff --git a/src/FormData/UserEditFormData.php b/src/FormData/UserEditFormData.php index 9f5bbcc9..04054c00 100644 --- a/src/FormData/UserEditFormData.php +++ b/src/FormData/UserEditFormData.php @@ -1,7 +1,11 @@ email = $inputReader->email; $this->password = $inputReader->password; if ($inputReader->accessRank !== null) - $this->accessRank = \Szurubooru\Helpers\EnumHelper::accessRankFromString($inputReader->accessRank); + $this->accessRank = EnumHelper::accessRankFromString($inputReader->accessRank); if ($inputReader->avatarStyle !== null) - $this->avatarStyle = \Szurubooru\Helpers\EnumHelper::avatarStyleFromString($inputReader->avatarStyle); + $this->avatarStyle = EnumHelper::avatarStyleFromString($inputReader->avatarStyle); $this->avatarContent = $inputReader->decodeBase64($inputReader->avatarContent); $this->browsingSettings = json_decode($inputReader->browsingSettings); $this->banned = boolval($inputReader->banned); } } - public function validate(\Szurubooru\Validator $validator) + public function validate(Validator $validator) { if ($this->userName !== null) $validator->validateUserName($this->userName); @@ -45,8 +49,8 @@ class UserEditFormData implements \Szurubooru\IValidatable if ($this->avatarContent) { - $avatarContentMimeType = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromBuffer($this->avatarContent); - if (!\Szurubooru\Helpers\MimeHelper::isImage($avatarContentMimeType)) + $avatarContentMimeType = MimeHelper::getMimeTypeFromBuffer($this->avatarContent); + if (!MimeHelper::isImage($avatarContentMimeType)) throw new \DomainException('Avatar must be an image (detected: ' . $avatarContentMimeType . ').'); } diff --git a/src/Helpers/EnumHelper.php b/src/Helpers/EnumHelper.php index c31e476c..68e02cea 100644 --- a/src/Helpers/EnumHelper.php +++ b/src/Helpers/EnumHelper.php @@ -1,43 +1,46 @@ \Szurubooru\Entities\User::ACCESS_RANK_ANONYMOUS, - 'regularUser' => \Szurubooru\Entities\User::ACCESS_RANK_REGULAR_USER, - 'powerUser' => \Szurubooru\Entities\User::ACCESS_RANK_POWER_USER, - 'moderator' => \Szurubooru\Entities\User::ACCESS_RANK_MODERATOR, - 'administrator' => \Szurubooru\Entities\User::ACCESS_RANK_ADMINISTRATOR, + 'anonymous' => User::ACCESS_RANK_ANONYMOUS, + 'regularUser' => User::ACCESS_RANK_REGULAR_USER, + 'powerUser' => User::ACCESS_RANK_POWER_USER, + 'moderator' => User::ACCESS_RANK_MODERATOR, + 'administrator' => User::ACCESS_RANK_ADMINISTRATOR, ]; private static $avatarStyleMap = [ - 'gravatar' => \Szurubooru\Entities\User::AVATAR_STYLE_GRAVATAR, - 'manual' => \Szurubooru\Entities\User::AVATAR_STYLE_MANUAL, - 'none' => \Szurubooru\Entities\User::AVATAR_STYLE_BLANK, - 'blank' => \Szurubooru\Entities\User::AVATAR_STYLE_BLANK, + 'gravatar' => User::AVATAR_STYLE_GRAVATAR, + 'manual' => User::AVATAR_STYLE_MANUAL, + 'none' => User::AVATAR_STYLE_BLANK, + 'blank' => User::AVATAR_STYLE_BLANK, ]; private static $postSafetyMap = [ - 'safe' => \Szurubooru\Entities\Post::POST_SAFETY_SAFE, - 'sketchy' => \Szurubooru\Entities\Post::POST_SAFETY_SKETCHY, - 'unsafe' => \Szurubooru\Entities\Post::POST_SAFETY_UNSAFE, + 'safe' => Post::POST_SAFETY_SAFE, + 'sketchy' => Post::POST_SAFETY_SKETCHY, + 'unsafe' => Post::POST_SAFETY_UNSAFE, ]; private static $postTypeMap = [ - 'image' => \Szurubooru\Entities\Post::POST_TYPE_IMAGE, - 'video' => \Szurubooru\Entities\Post::POST_TYPE_VIDEO, - 'flash' => \Szurubooru\Entities\Post::POST_TYPE_FLASH, - 'youtube' => \Szurubooru\Entities\Post::POST_TYPE_YOUTUBE, + 'image' => Post::POST_TYPE_IMAGE, + 'video' => Post::POST_TYPE_VIDEO, + 'flash' => Post::POST_TYPE_FLASH, + 'youtube' => Post::POST_TYPE_YOUTUBE, ]; private static $snapshotTypeMap = [ - 'post' => \Szurubooru\Entities\Snapshot::TYPE_POST, + 'post' => Snapshot::TYPE_POST, ]; public static function accessRankToString($accessRank) diff --git a/src/IValidatable.php b/src/IValidatable.php index a61df0dc..be2913cf 100644 --- a/src/IValidatable.php +++ b/src/IValidatable.php @@ -1,7 +1,8 @@ setDefinitionCache(new \Doctrine\Common\Cache\ArrayCache()); + $builder = new ContainerBuilder(); + $builder->setDefinitionCache(new ArrayCache()); $builder->addDefinitions($definitionsPath); self::$container = $builder->build(); } diff --git a/src/Route.php b/src/Route.php index 3ee77b11..c71f7f4b 100644 --- a/src/Route.php +++ b/src/Route.php @@ -6,7 +6,7 @@ final class Route public $query; public $route; - public function __construct($query, $route) + public function __construct($query, callable $route) { $this->query = $query; $this->route = $route; @@ -19,7 +19,8 @@ final class Route if (!preg_match($this->regex, $query, $matches)) return false; $routeArguments = $this->getRouteArguments($matches); - $output = call_user_func_array($this->route, $routeArguments); + $func = $this->route; + $output = $func(...array_values($routeArguments)); return true; } diff --git a/src/Router.php b/src/Router.php index 1e28ec72..8c6f94a6 100644 --- a/src/Router.php +++ b/src/Router.php @@ -5,27 +5,27 @@ class Router { private $routes; - public function get($query, $route) + public function get($query, callable $route) { $this->route('GET', $query, $route); } - public function put($query, $route) + public function put($query, callable $route) { $this->route('PUT', $query, $route); } - public function delete($query, $route) + public function delete($query, callable $route) { $this->route('DELETE', $query, $route); } - public function post($query, $route) + public function post($query, callable $route) { $this->route('POST', $query, $route); } - private function route($method, $query, $route) + private function route($method, $query, callable $route) { $this->routes[$method][] = new Route($query, $route); } diff --git a/src/SearchServices/Filters/BasicFilter.php b/src/SearchServices/Filters/BasicFilter.php index 1f08c45a..082d1dea 100644 --- a/src/SearchServices/Filters/BasicFilter.php +++ b/src/SearchServices/Filters/BasicFilter.php @@ -1,10 +1,9 @@ order = $order; } - public function addRequirement(\Szurubooru\SearchServices\Requirements\Requirement $requirement) + public function addRequirement(Requirement $requirement) { $this->requirements[] = $requirement; } diff --git a/src/SearchServices/Filters/IFilter.php b/src/SearchServices/Filters/IFilter.php index 93709119..c9f7bf5d 100644 --- a/src/SearchServices/Filters/IFilter.php +++ b/src/SearchServices/Filters/IFilter.php @@ -1,8 +1,11 @@ createFilter(); $filter->setOrder($this->getOrder($inputReader->order) + $filter->getOrder()); @@ -21,14 +29,14 @@ abstract class AbstractSearchParser foreach ($tokens as $token) { - if ($token instanceof \Szurubooru\SearchServices\Tokens\NamedSearchToken) + if ($token instanceof NamedSearchToken) { if ($token->getKey() === 'order') $filter->setOrder($this->getOrder($token->getValue()) + $filter->getOrder()); else $this->decorateFilterFromNamedToken($filter, $token); } - elseif ($token instanceof \Szurubooru\SearchServices\Tokens\SearchToken) + elseif ($token instanceof SearchToken) $this->decorateFilterFromToken($filter, $token); else throw new \RuntimeException('Invalid search token type: ' . get_class($token)); @@ -39,13 +47,13 @@ abstract class AbstractSearchParser protected abstract function createFilter(); - protected abstract function decorateFilterFromToken($filter, $token); + protected abstract function decorateFilterFromToken(IFilter $filter, SearchToken $token); - protected abstract function decorateFilterFromNamedToken($filter, $namedToken); + protected abstract function decorateFilterFromNamedToken(IFilter $filter, NamedSearchToken $namedToken); - protected abstract function getOrderColumn($token); + protected abstract function getOrderColumn($tokenText); - protected function createRequirementValue($text, $flags = 0, $valueDecorator = null) + protected function createRequirementValue($text, $flags = 0, callable $valueDecorator = null) { if ($valueDecorator === null) { @@ -60,7 +68,7 @@ abstract class AbstractSearchParser list ($minValue, $maxValue) = explode('..', $text); $minValue = $valueDecorator($minValue); $maxValue = $valueDecorator($maxValue); - $tokenValue = new \Szurubooru\SearchServices\Requirements\RequirementRangedValue(); + $tokenValue = new RequirementRangedValue(); $tokenValue->setMinValue($minValue); $tokenValue->setMaxValue($maxValue); return $tokenValue; @@ -69,18 +77,18 @@ abstract class AbstractSearchParser { $values = explode(',', $text); $values = array_map($valueDecorator, $values); - $tokenValue = new \Szurubooru\SearchServices\Requirements\RequirementCompositeValue(); + $tokenValue = new RequirementCompositeValue(); $tokenValue->setValues($values); return $tokenValue; } $value = $valueDecorator($text); - return new \Szurubooru\SearchServices\Requirements\RequirementSingleValue($value); + return new RequirementSingleValue($value); } - protected function addRequirementFromToken($filter, $token, $type, $flags, $valueDecorator = null) + protected function addRequirementFromToken($filter, $token, $type, $flags, callable $valueDecorator = null) { - $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); + $requirement = new Requirement(); $requirement->setType($type); $requirement->setValue($this->createRequirementValue($token->getValue(), $flags, $valueDecorator)); $requirement->setNegated($token->isNegated()); @@ -99,14 +107,14 @@ abstract class AbstractSearchParser if (count($token) === 1) { - $orderDir = \Szurubooru\SearchServices\Filters\IFilter::ORDER_DESC; + $orderDir = IFilter::ORDER_DESC; } elseif (count($token) === 2) { if ($token[1] === 'desc') - $orderDir = \Szurubooru\SearchServices\Filters\IFilter::ORDER_DESC; + $orderDir = IFilter::ORDER_DESC; elseif ($token[1] === 'asc') - $orderDir = \Szurubooru\SearchServices\Filters\IFilter::ORDER_ASC; + $orderDir = IFilter::ORDER_ASC; else throw new \Exception('Wrong search order direction'); } @@ -139,14 +147,14 @@ abstract class AbstractSearchParser $colonPosition = strpos($tokenText, ':'); if (($colonPosition !== false) and ($colonPosition > 0)) { - $searchToken = new \Szurubooru\SearchServices\Tokens\NamedSearchToken(); + $searchToken = new NamedSearchToken(); list ($tokenKey, $tokenValue) = explode(':', $tokenText, 2); $searchToken->setKey($tokenKey); $searchToken->setValue($tokenValue); } else { - $searchToken = new \Szurubooru\SearchServices\Tokens\SearchToken(); + $searchToken = new SearchToken(); $searchToken->setValue($tokenText); } diff --git a/src/SearchServices/Parsers/PostSearchParser.php b/src/SearchServices/Parsers/PostSearchParser.php index 7468ec7f..33d5b233 100644 --- a/src/SearchServices/Parsers/PostSearchParser.php +++ b/src/SearchServices/Parsers/PostSearchParser.php @@ -1,5 +1,15 @@ authService = $authService; $this->privilegeService = $privilegeService; @@ -16,19 +26,19 @@ class PostSearchParser extends AbstractSearchParser protected function createFilter() { - return new \Szurubooru\SearchServices\Filters\PostFilter; + return new PostFilter; } - protected function decorateFilterFromToken($filter, $token) + protected function decorateFilterFromToken(IFilter $filter, SearchToken $token) { - $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); - $requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_TAG); + $requirement = new Requirement(); + $requirement->setType(PostFilter::REQUIREMENT_TAG); $requirement->setValue($this->createRequirementValue($token->getValue())); $requirement->setNegated($token->isNegated()); $filter->addRequirement($requirement); } - protected function decorateFilterFromNamedToken($filter, $token) + protected function decorateFilterFromNamedToken(IFilter $filter, NamedSearchToken $token) { if ($token->getKey() === 'id') $this->addIdRequirement($filter, $token); @@ -81,53 +91,53 @@ class PostSearchParser extends AbstractSearchParser elseif ($token->getKey() === 'special' and $token->getValue() === 'fav') { $this->privilegeService->assertLoggedIn(); - $token = new \Szurubooru\SearchServices\Tokens\NamedSearchToken(); + $token = new NamedSearchToken(); $token->setKey('fav'); $token->setValue($this->authService->getLoggedInUser()->getName()); $this->decorateFilterFromNamedToken($filter, $token); } else - throw new \Szurubooru\NotSupportedException(); + throw new NotSupportedException(); } - protected function getOrderColumn($token) + protected function getOrderColumn($tokenText) { - if ($token === 'id') - return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_ID; + if ($tokenText === 'id') + return PostFilter::ORDER_ID; - elseif ($token === 'fav_time') - return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_FAV_TIME; + elseif ($tokenText === 'fav_time') + return PostFilter::ORDER_FAV_TIME; - elseif ($token === 'fav_count') - return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_FAV_COUNT; + elseif ($tokenText === 'fav_count') + return PostFilter::ORDER_FAV_COUNT; - elseif ($token === 'tag_count') - return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_TAG_COUNT; + elseif ($tokenText === 'tag_count') + return PostFilter::ORDER_TAG_COUNT; - elseif ($token === 'time') - return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_LAST_EDIT_TIME; + elseif ($tokenText === 'time') + return PostFilter::ORDER_LAST_EDIT_TIME; - elseif ($token === 'score') - return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_SCORE; + elseif ($tokenText === 'score') + return PostFilter::ORDER_SCORE; - elseif ($token === 'file_size') - return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_FILE_SIZE; + elseif ($tokenText === 'file_size') + return PostFilter::ORDER_FILE_SIZE; - elseif ($token === 'random') - return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_RANDOM; + elseif ($tokenText === 'random') + return PostFilter::ORDER_RANDOM; - elseif ($token === 'feature_time') - return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_LAST_FEATURE_TIME; + elseif ($tokenText === 'feature_time') + return PostFilter::ORDER_LAST_FEATURE_TIME; - elseif ($token === 'comment_time') - return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_LAST_COMMENT_TIME; + elseif ($tokenText === 'comment_time') + return PostFilter::ORDER_LAST_COMMENT_TIME; - elseif ($token === 'fav_time') - return \Szurubooru\SearchServices\Filters\PostFilter::ORDER_LAST_FAV_TIME; + elseif ($tokenText === 'fav_time') + return PostFilter::ORDER_LAST_FAV_TIME; else - throw new \Szurubooru\NotSupportedException(); + throw new NotSupportedException(); } private function addIdRequirement($filter, $token) @@ -135,7 +145,7 @@ class PostSearchParser extends AbstractSearchParser $this->addRequirementFromToken( $filter, $token, - \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_ID, + PostFilter::REQUIREMENT_ID, self::ALLOW_COMPOSITE | self::ALLOW_RANGES); } @@ -144,7 +154,7 @@ class PostSearchParser extends AbstractSearchParser $this->addRequirementFromToken( $filter, $token, - \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_HASH, + PostFilter::REQUIREMENT_HASH, self::ALLOW_COMPOSITE); } @@ -173,7 +183,7 @@ class PostSearchParser extends AbstractSearchParser $this->addRequirementFromToken( $filter, $token, - \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_DATE, + PostFilter::REQUIREMENT_DATE, self::ALLOW_RANGES); } @@ -182,7 +192,7 @@ class PostSearchParser extends AbstractSearchParser $this->addRequirementFromToken( $filter, $token, - \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_TAG_COUNT, + PostFilter::REQUIREMENT_TAG_COUNT, self::ALLOW_COMPOSITE | self::ALLOW_RANGES); } @@ -191,7 +201,7 @@ class PostSearchParser extends AbstractSearchParser $this->addRequirementFromToken( $filter, $token, - \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_FAV_COUNT, + PostFilter::REQUIREMENT_FAV_COUNT, self::ALLOW_COMPOSITE | self::ALLOW_RANGES); } @@ -200,7 +210,7 @@ class PostSearchParser extends AbstractSearchParser $this->addRequirementFromToken( $filter, $token, - \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_COMMENT_COUNT, + PostFilter::REQUIREMENT_COMMENT_COUNT, self::ALLOW_COMPOSITE | self::ALLOW_RANGES); } @@ -209,7 +219,7 @@ class PostSearchParser extends AbstractSearchParser $this->addRequirementFromToken( $filter, $token, - \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_SCORE, + PostFilter::REQUIREMENT_SCORE, self::ALLOW_COMPOSITE | self::ALLOW_RANGES); } @@ -218,7 +228,7 @@ class PostSearchParser extends AbstractSearchParser $this->addRequirementFromToken( $filter, $token, - \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_UPLOADER, + PostFilter::REQUIREMENT_UPLOADER, self::ALLOW_COMPOSITE); } @@ -227,11 +237,11 @@ class PostSearchParser extends AbstractSearchParser $this->addRequirementFromToken( $filter, $token, - \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_SAFETY, + PostFilter::REQUIREMENT_SAFETY, self::ALLOW_COMPOSITE, function ($value) { - return \Szurubooru\Helpers\EnumHelper::postSafetyFromString($value); + return EnumHelper::postSafetyFromString($value); }); } @@ -240,7 +250,7 @@ class PostSearchParser extends AbstractSearchParser $this->addRequirementFromToken( $filter, $token, - \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_FAVORITE, + PostFilter::REQUIREMENT_FAVORITE, self::ALLOW_COMPOSITE); } @@ -249,11 +259,11 @@ class PostSearchParser extends AbstractSearchParser $this->addRequirementFromToken( $filter, $token, - \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_TYPE, + PostFilter::REQUIREMENT_TYPE, self::ALLOW_COMPOSITE, function ($value) { - return \Szurubooru\Helpers\EnumHelper::postTypeFromSTring($value); + return EnumHelper::postTypeFromString($value); }); } @@ -262,16 +272,16 @@ class PostSearchParser extends AbstractSearchParser $this->addRequirementFromToken( $filter, $token, - \Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_COMMENT, + PostFilter::REQUIREMENT_COMMENT, self::ALLOW_COMPOSITE); } private function addUserScoreRequirement($filter, $userName, $score, $isNegated) { - $tokenValue = new \Szurubooru\SearchServices\Requirements\RequirementCompositeValue(); + $tokenValue = new RequirementCompositeValue(); $tokenValue->setValues([$userName, $score]); - $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); - $requirement->setType(\Szurubooru\SearchServices\Filters\PostFilter::REQUIREMENT_USER_SCORE); + $requirement = new Requirement(); + $requirement->setType(PostFilter::REQUIREMENT_USER_SCORE); $requirement->setValue($tokenValue); $requirement->setNegated($isNegated); $filter->addRequirement($requirement); diff --git a/src/SearchServices/Parsers/SnapshotSearchParser.php b/src/SearchServices/Parsers/SnapshotSearchParser.php index a51c7a7e..4d683589 100644 --- a/src/SearchServices/Parsers/SnapshotSearchParser.php +++ b/src/SearchServices/Parsers/SnapshotSearchParser.php @@ -1,41 +1,48 @@ getValue(), ',') !== 1) - throw new \BadMethodCallException('Not supported'); + throw new NotSupportedException(); if ($token->isNegated()) - throw new \BadMethodCallException('Not supported'); + throw new NotSupportedException(); list ($type, $primaryKey) = explode(',', $token->getValue()); - $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); - $requirement->setType(\Szurubooru\SearchServices\Filters\SnapshotFilter::REQUIREMENT_PRIMARY_KEY); + $requirement = new Requirement(); + $requirement->setType(SnapshotFilter::REQUIREMENT_PRIMARY_KEY); $requirement->setValue($this->createRequirementValue($primaryKey)); $filter->addRequirement($requirement); - $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); - $requirement->setType(\Szurubooru\SearchServices\Filters\SnapshotFilter::REQUIREMENT_TYPE); - $requirement->setValue($this->createRequirementValue(\Szurubooru\Helpers\EnumHelper::snapshotTypeFromString($type))); + $requirement = new Requirement(); + $requirement->setType(SnapshotFilter::REQUIREMENT_TYPE); + $requirement->setValue($this->createRequirementValue(EnumHelper::snapshotTypeFromString($type))); $filter->addRequirement($requirement); } - protected function decorateFilterFromNamedToken($filter, $namedToken) + protected function decorateFilterFromNamedToken(IFilter $filter, NamedSearchToken $namedToken) { - throw new \BadMethodCallException('Not supported'); + throw new NotSupportedException(); } - protected function getOrderColumn($token) + protected function getOrderColumn($tokenText) { - throw new \BadMethodCallException('Not supported'); + throw new NotSupportedException(); } } diff --git a/src/SearchServices/Parsers/TagSearchParser.php b/src/SearchServices/Parsers/TagSearchParser.php index 7dbc274f..6d3bd569 100644 --- a/src/SearchServices/Parsers/TagSearchParser.php +++ b/src/SearchServices/Parsers/TagSearchParser.php @@ -1,38 +1,43 @@ searchFilter = $searchFilter; } diff --git a/src/Services/AuthService.php b/src/Services/AuthService.php index 047fcb3f..9cdd502e 100644 --- a/src/Services/AuthService.php +++ b/src/Services/AuthService.php @@ -1,5 +1,12 @@ config = $config; $this->passwordService = $passwordService; @@ -60,9 +67,9 @@ class AuthService $this->loggedInUser = $user; } - public function loginFromToken(\Szurubooru\Entities\Token $token) + public function loginFromToken(Token $token) { - if ($token->getPurpose() !== \Szurubooru\Entities\Token::PURPOSE_LOGIN) + if ($token->getPurpose() !== Token::PURPOSE_LOGIN) throw new \Exception('This token is not a login token.'); $user = $this->userService->getById($token->getAdditionalData()); @@ -74,10 +81,10 @@ class AuthService public function getAnonymousUser() { - $user = new \Szurubooru\Entities\User(); + $user = new User(); $user->setName('Anonymous user'); - $user->setAccessRank(\Szurubooru\Entities\User::ACCESS_RANK_ANONYMOUS); - $user->setAvatarStyle(\Szurubooru\Entities\User::AVATAR_STYLE_BLANK); + $user->setAccessRank(User::ACCESS_RANK_ANONYMOUS); + $user->setAvatarStyle(User::AVATAR_STYLE_BLANK); return $user; } @@ -96,9 +103,9 @@ class AuthService $this->loginToken = null; } - private function createAndSaveLoginToken(\Szurubooru\Entities\User $user) + private function createAndSaveLoginToken(User $user) { - return $this->tokenService->createAndSaveToken($user->getId(), \Szurubooru\Entities\Token::PURPOSE_LOGIN); + return $this->tokenService->createAndSaveToken($user->getId(), Token::PURPOSE_LOGIN); } private function doFinalChecksOnUser($user) diff --git a/src/Services/CommentService.php b/src/Services/CommentService.php index f029b123..cd10b12a 100644 --- a/src/Services/CommentService.php +++ b/src/Services/CommentService.php @@ -1,5 +1,13 @@ validator = $validator; $this->commentDao = $commentDao; @@ -35,7 +43,7 @@ class CommentService return $this->transactionManager->rollback($transactionFunc); } - public function getByPost(\Szurubooru\Entities\Post $post) + public function getByPost(Post $post) { $transactionFunc = function() use ($post) { @@ -44,7 +52,7 @@ class CommentService return $this->transactionManager->rollback($transactionFunc); } - public function getFiltered(\Szurubooru\SearchServices\Filters\CommentFilter $filter) + public function getFiltered(CommentFilter $filter) { $transactionFunc = function() use ($filter) { @@ -53,11 +61,11 @@ class CommentService return $this->transactionManager->rollback($transactionFunc); } - public function createComment(\Szurubooru\Entities\Post $post, $text) + public function createComment(Post $post, $text) { $transactionFunc = function() use ($post, $text) { - $comment = new \Szurubooru\Entities\Comment(); + $comment = new Comment(); $comment->setCreationTime($this->timeService->getCurrentTime()); $comment->setLastEditTime($this->timeService->getCurrentTime()); $comment->setUser($this->authService->isLoggedIn() ? $this->authService->getLoggedInUser() : null); @@ -70,7 +78,7 @@ class CommentService return $this->transactionManager->commit($transactionFunc); } - public function updateComment(\Szurubooru\Entities\Comment $comment, $newText) + public function updateComment(Comment $comment, $newText) { $transactionFunc = function() use ($comment, $newText) { @@ -82,7 +90,7 @@ class CommentService return $this->transactionManager->commit($transactionFunc); } - public function deleteComment(\Szurubooru\Entities\Comment $comment) + public function deleteComment(Comment $comment) { $transactionFunc = function() use ($comment) { @@ -91,7 +99,7 @@ class CommentService $this->transactionManager->commit($transactionFunc); } - private function updateCommentText(\Szurubooru\Entities\Comment $comment, $text) + private function updateCommentText(Comment $comment, $text) { $this->validator->validateLength($text, 5, 2000, 'Comment text'); $comment->setText($text); diff --git a/src/Services/EmailService.php b/src/Services/EmailService.php index 3a2bd455..17951dc7 100644 --- a/src/Services/EmailService.php +++ b/src/Services/EmailService.php @@ -1,16 +1,19 @@ config = $config; } - public function sendPasswordResetEmail(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Token $token) + public function sendPasswordResetEmail(User $user, Token $token) { if (!$user->getEmail()) throw new \BadMethodCall('An activated e-mail addreses is needed to reset the password.'); @@ -25,7 +28,7 @@ class EmailService $this->sendEmail($user->getEmail(), $mailSubject, $mailBody); } - public function sendActivationEmail(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Token $token) + public function sendActivationEmail(User $user, Token $token) { if (!$user->getEmailUnconfirmed()) throw new \BadMethodCallException('An e-mail address is needed to activate the account.'); diff --git a/src/Services/FavoritesService.php b/src/Services/FavoritesService.php index 60aa2c6c..437127d2 100644 --- a/src/Services/FavoritesService.php +++ b/src/Services/FavoritesService.php @@ -1,5 +1,12 @@ favoritesDao = $favoritesDao; $this->scoreDao = $scoreDao; @@ -23,7 +30,7 @@ class FavoritesService $this->timeService = $timeService; } - public function getFavoriteUsers(\Szurubooru\Entities\Entity $entity) + public function getFavoriteUsers(Entity $entity) { $transactionFunc = function() use ($entity) { @@ -38,7 +45,7 @@ class FavoritesService return $this->transactionManager->rollback($transactionFunc); } - public function addFavorite(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity) + public function addFavorite(User $user, Entity $entity) { $transactionFunc = function() use ($user, $entity) { @@ -49,7 +56,7 @@ class FavoritesService return $this->transactionManager->commit($transactionFunc); } - public function deleteFavorite(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity) + public function deleteFavorite(User $user, Entity $entity) { $transactionFunc = function() use ($user, $entity) { diff --git a/src/Services/FileService.php b/src/Services/FileService.php index 25e7cf1e..272eda06 100644 --- a/src/Services/FileService.php +++ b/src/Services/FileService.php @@ -1,12 +1,14 @@ dataDirectory = $config->getPublicDataDirectory(); $this->httpHelper = $httpHelper; diff --git a/src/Services/HistoryService.php b/src/Services/HistoryService.php index 04b36423..b6511289 100644 --- a/src/Services/HistoryService.php +++ b/src/Services/HistoryService.php @@ -1,5 +1,18 @@ validator = $validator; $this->snapshotDao = $snapshotDao; @@ -26,7 +39,7 @@ class HistoryService $this->transactionManager = $transactionManager; } - public function getFiltered(\Szurubooru\SearchServices\Filters\SnapshotFilter $filter) + public function getFiltered(SnapshotFilter $filter) { $transactionFunc = function() use ($filter) { @@ -35,24 +48,24 @@ class HistoryService return $this->transactionManager->rollback($transactionFunc); } - public function getPostHistory(\Szurubooru\Entities\Post $post) + public function getPostHistory(Post $post) { - $filter = new \Szurubooru\SearchServices\Filters\SnapshotFilter(); + $filter = new SnapshotFilter(); - $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); - $requirement->setType(\Szurubooru\SearchServices\Filters\SnapshotFilter::REQUIREMENT_PRIMARY_KEY); - $requirement->setValue(new \Szurubooru\SearchServices\Requirements\RequirementSingleValue($post->getId())); + $requirement = new Requirement(); + $requirement->setType(SnapshotFilter::REQUIREMENT_PRIMARY_KEY); + $requirement->setValue(new RequirementSingleValue($post->getId())); $filter->addRequirement($requirement); - $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); - $requirement->setType(\Szurubooru\SearchServices\Filters\SnapshotFilter::REQUIREMENT_TYPE); - $requirement->setValue(new \Szurubooru\SearchServices\Requirements\RequirementSingleValue(\Szurubooru\Entities\Snapshot::TYPE_POST)); + $requirement = new Requirement(); + $requirement->setType(SnapshotFilter::REQUIREMENT_TYPE); + $requirement->setValue(new RequirementSingleValue(Snapshot::TYPE_POST)); $filter->addRequirement($requirement); return $this->getFiltered($filter)->getEntities(); } - public function saveSnapshot(\Szurubooru\Entities\Snapshot $snapshot) + public function saveSnapshot(Snapshot $snapshot) { $transactionFunc = function() use ($snapshot) { @@ -79,23 +92,23 @@ class HistoryService return $this->transactionManager->commit($transactionFunc); } - public function getPostDeleteSnapshot(\Szurubooru\Entities\Post $post) + public function getPostDeleteSnapshot(Post $post) { $snapshot = $this->getPostSnapshot($post); $snapshot->setData([]); - $snapshot->setOperation(\Szurubooru\Entities\Snapshot::OPERATION_DELETE); + $snapshot->setOperation(Snapshot::OPERATION_DELETE); return $snapshot; } - public function getPostChangeSnapshot(\Szurubooru\Entities\Post $post) + public function getPostChangeSnapshot(Post $post) { - $featuredPostParam = $this->globalParamDao->findByKey(\Szurubooru\Entities\GlobalParam::KEY_FEATURED_POST); + $featuredPostParam = $this->globalParamDao->findByKey(GlobalParam::KEY_FEATURED_POST); $isFeatured = ($featuredPostParam and intval($featuredPostParam->getValue()) === $post->getId()); $data = [ 'source' => $post->getSource(), - 'safety' => \Szurubooru\Helpers\EnumHelper::postSafetyToString($post->getSafety()), + 'safety' => EnumHelper::postSafetyToString($post->getSafety()), 'contentChecksum' => $post->getContentChecksum(), 'featured' => $isFeatured, @@ -118,7 +131,7 @@ class HistoryService ]; $snapshot = $this->getPostSnapshot($post); - $snapshot->setOperation(\Szurubooru\Entities\Snapshot::OPERATION_CHANGE); + $snapshot->setOperation(Snapshot::OPERATION_CHANGE); $snapshot->setData($data); return $snapshot; } @@ -153,10 +166,10 @@ class HistoryService ]; } - private function getPostSnapshot(\Szurubooru\Entities\Post $post) + private function getPostSnapshot(Post $post) { - $snapshot = new \Szurubooru\Entities\Snapshot(); - $snapshot->setType(\Szurubooru\Entities\Snapshot::TYPE_POST); + $snapshot = new Snapshot(); + $snapshot->setType(Snapshot::TYPE_POST); $snapshot->setPrimaryKey($post->getId()); return $snapshot; } diff --git a/src/Services/ImageManipulation/ImageManipulator.php b/src/Services/ImageManipulation/ImageManipulator.php index 34864267..3f23fa51 100644 --- a/src/Services/ImageManipulation/ImageManipulator.php +++ b/src/Services/ImageManipulation/ImageManipulator.php @@ -1,13 +1,15 @@ config = $config; $this->alphabet = diff --git a/src/Services/PostService.php b/src/Services/PostService.php index e3c99859..7a84d8aa 100644 --- a/src/Services/PostService.php +++ b/src/Services/PostService.php @@ -1,5 +1,26 @@ config = $config; $this->validator = $validator; @@ -67,7 +88,7 @@ class PostService return $this->transactionManager->rollback($transactionFunc); } - public function getFiltered(\Szurubooru\SearchServices\Filters\PostFilter $filter) + public function getFiltered(PostFilter $filter) { $transactionFunc = function() use ($filter) { @@ -80,7 +101,7 @@ class PostService { $transactionFunc = function() { - $globalParam = $this->globalParamDao->findByKey(\Szurubooru\Entities\GlobalParam::KEY_FEATURED_POST); + $globalParam = $this->globalParamDao->findByKey(GlobalParam::KEY_FEATURED_POST); if (!$globalParam) return null; return $this->getByNameOrId($globalParam->getValue()); @@ -88,20 +109,20 @@ class PostService return $this->transactionManager->rollback($transactionFunc); } - public function getHistory(\Szurubooru\Entities\Post $post) + public function getHistory(Post $post) { $transactionFunc = function() use ($post) { - $filter = new \Szurubooru\SearchServices\Filters\SnapshotFilter(); + $filter = new SnapshotFilter(); - $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); - $requirement->setType(\Szurubooru\SearchServices\Filters\SnapshotFilter::REQUIREMENT_PRIMARY_KEY); - $requirement->setValue(new \Szurubooru\SearchServices\Requirements\RequirementSingleValue($post->getId())); + $requirement = new Requirement(); + $requirement->setType(SnapshotFilter::REQUIREMENT_PRIMARY_KEY); + $requirement->setValue(new RequirementSingleValue($post->getId())); $filter->addRequirement($requirement); - $requirement = new \Szurubooru\SearchServices\Requirements\Requirement(); - $requirement->setType(\Szurubooru\SearchServices\Filters\SnapshotFilter::REQUIREMENT_TYPE); - $requirement->setValue(new \Szurubooru\SearchServices\Requirements\RequirementSingleValue(\Szurubooru\Entities\Snapshot::TYPE_POST)); + $requirement = new Requirement(); + $requirement->setType(SnapshotFilter::REQUIREMENT_TYPE); + $requirement->setValue(new RequirementSingleValue(Snapshot::TYPE_POST)); $filter->addRequirement($requirement); return $this->historyService->getFiltered($filter)->getEntities(); @@ -109,13 +130,13 @@ class PostService return $this->transactionManager->rollback($transactionFunc); } - public function createPost(\Szurubooru\FormData\UploadFormData $formData) + public function createPost(UploadFormData $formData) { $transactionFunc = function() use ($formData) { $formData->validate($this->validator); - $post = new \Szurubooru\Entities\Post(); + $post = new Post(); $post->setUploadTime($this->timeService->getCurrentTime()); $post->setLastEditTime($this->timeService->getCurrentTime()); $post->setUser($formData->anonymous ? null : $this->authService->getLoggedInUser()); @@ -138,7 +159,7 @@ class PostService return $ret; } - public function updatePost(\Szurubooru\Entities\Post $post, \Szurubooru\FormData\PostEditFormData $formData) + public function updatePost(Post $post, PostEditFormData $formData) { $transactionFunc = function() use ($post, $formData) { @@ -176,17 +197,17 @@ class PostService return $ret; } - private function updatePostSafety(\Szurubooru\Entities\Post $post, $newSafety) + private function updatePostSafety(Post $post, $newSafety) { $post->setSafety($newSafety); } - private function updatePostSource(\Szurubooru\Entities\Post $post, $newSource) + private function updatePostSource(Post $post, $newSource) { $post->setSource($newSource); } - private function updatePostContentFromStringOrUrl(\Szurubooru\Entities\Post $post, $content, $url) + private function updatePostContentFromStringOrUrl(Post $post, $content, $url) { if ($url) $this->updatePostContentFromUrl($post, $url); @@ -196,7 +217,7 @@ class PostService throw new \DomainException('No content specified'); } - private function updatePostContentFromString(\Szurubooru\Entities\Post $post, $content) + private function updatePostContentFromString(Post $post, $content) { if (!$content) throw new \DomainException('File cannot be empty.'); @@ -204,15 +225,15 @@ class PostService if (strlen($content) > $this->config->database->maxPostSize) throw new \DomainException('Upload is too big.'); - $mime = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromBuffer($content); + $mime = MimeHelper::getMimeTypeFromBuffer($content); $post->setContentMimeType($mime); - if (\Szurubooru\Helpers\MimeHelper::isFlash($mime)) - $post->setContentType(\Szurubooru\Entities\Post::POST_TYPE_FLASH); - elseif (\Szurubooru\Helpers\MimeHelper::isImage($mime)) - $post->setContentType(\Szurubooru\Entities\Post::POST_TYPE_IMAGE); - elseif (\Szurubooru\Helpers\MimeHelper::isVideo($mime)) - $post->setContentType(\Szurubooru\Entities\Post::POST_TYPE_VIDEO); + if (MimeHelper::isFlash($mime)) + $post->setContentType(Post::POST_TYPE_FLASH); + elseif (MimeHelper::isImage($mime)) + $post->setContentType(Post::POST_TYPE_IMAGE); + elseif (MimeHelper::isVideo($mime)) + $post->setContentType(Post::POST_TYPE_VIDEO); else throw new \DomainException('Unhandled file type: "' . $mime . '"'); @@ -228,7 +249,7 @@ class PostService $post->setOriginalFileSize(strlen($content)); } - private function updatePostContentFromUrl(\Szurubooru\Entities\Post $post, $url) + private function updatePostContentFromUrl(Post $post, $url) { if (!preg_match('/^https?:\/\//', $url)) throw new \InvalidArgumentException('Invalid URL "' . $url . '"'); @@ -239,7 +260,7 @@ class PostService if ($youtubeId) { - $post->setContentType(\Szurubooru\Entities\Post::POST_TYPE_YOUTUBE); + $post->setContentType(Post::POST_TYPE_YOUTUBE); $post->setImageWidth(null); $post->setImageHeight(null); $post->setContentChecksum($url); @@ -259,7 +280,7 @@ class PostService } } - private function updatePostThumbnailFromString(\Szurubooru\Entities\Post $post, $newThumbnail) + private function updatePostThumbnailFromString(Post $post, $newThumbnail) { if (strlen($newThumbnail) > $this->config->database->maxCustomThumbnailSize) throw new \DomainException('Thumbnail is too big.'); @@ -267,12 +288,12 @@ class PostService $post->setThumbnailSourceContent($newThumbnail); } - private function updatePostTags(\Szurubooru\Entities\Post $post, array $newTagNames) + private function updatePostTags(Post $post, array $newTagNames) { $tags = []; foreach ($newTagNames as $tagName) { - $tag = new \Szurubooru\Entities\Tag(); + $tag = new Tag(); $tag->setName($tagName); $tags[] = $tag; } @@ -280,7 +301,7 @@ class PostService $post->setTags($tags); } - private function updatePostRelations(\Szurubooru\Entities\Post $post, array $newRelatedPostIds) + private function updatePostRelations(Post $post, array $newRelatedPostIds) { $relatedPosts = $this->postDao->findByIds($newRelatedPostIds); foreach ($newRelatedPostIds as $postId) @@ -292,7 +313,7 @@ class PostService $post->setRelatedPosts($relatedPosts); } - public function deletePost(\Szurubooru\Entities\Post $post) + public function deletePost(Post $post) { $transactionFunc = function() use ($post) { @@ -302,7 +323,7 @@ class PostService $this->transactionManager->commit($transactionFunc); } - public function featurePost(\Szurubooru\Entities\Post $post) + public function featurePost(Post $post) { $transactionFunc = function() use ($post) { @@ -311,8 +332,8 @@ class PostService $post->setLastFeatureTime($this->timeService->getCurrentTime()); $post->setFeatureCount($post->getFeatureCount() + 1); $this->postDao->save($post); - $globalParam = new \Szurubooru\Entities\GlobalParam(); - $globalParam->setKey(\Szurubooru\Entities\GlobalParam::KEY_FEATURED_POST); + $globalParam = new GlobalParam(); + $globalParam->setKey(GlobalParam::KEY_FEATURED_POST); $globalParam->setValue($post->getId()); $this->globalParamDao->save($globalParam); @@ -327,20 +348,20 @@ class PostService { $transactionFunc = function() { - $countParam = new \Szurubooru\Entities\GlobalParam(); - $countParam->setKey(\Szurubooru\Entities\GlobalParam::KEY_POST_COUNT); + $countParam = new GlobalParam(); + $countParam->setKey(GlobalParam::KEY_POST_COUNT); $countParam->setValue($this->postDao->getCount()); $this->globalParamDao->save($countParam); - $fileSizeParam = new \Szurubooru\Entities\GlobalParam(); - $fileSizeParam->setKey(\Szurubooru\Entities\GlobalParam::KEY_POST_SIZE); + $fileSizeParam = new GlobalParam(); + $fileSizeParam->setKey(GlobalParam::KEY_POST_SIZE); $fileSizeParam->setValue($this->postDao->getTotalFileSize()); $this->globalParamDao->save($fileSizeParam); }; $this->transactionManager->commit($transactionFunc); } - private function assertNoPostWithThisContentChecksum(\Szurubooru\Entities\Post $parent) + private function assertNoPostWithThisContentChecksum(Post $parent) { $checksumToCheck = $parent->getContentChecksum(); $postWithThisChecksum = $this->postDao->findByContentChecksum($checksumToCheck); diff --git a/src/Services/PrivilegeService.php b/src/Services/PrivilegeService.php index c5940895..69cba68b 100644 --- a/src/Services/PrivilegeService.php +++ b/src/Services/PrivilegeService.php @@ -1,5 +1,9 @@ authService = $authService; @@ -30,7 +34,7 @@ class PrivilegeService public function getCurrentPrivileges() { $currentAccessRank = $this->authService->getLoggedInUser()->getAccessRank(); - $currentAccessRankName = \Szurubooru\Helpers\EnumHelper::accessRankToString($currentAccessRank); + $currentAccessRankName = EnumHelper::accessRankToString($currentAccessRank); if (!isset($this->privilegeMap[$currentAccessRankName])) return []; return $this->privilegeMap[$currentAccessRankName]; @@ -64,7 +68,7 @@ class PrivilegeService public function isLoggedIn($userIdentifier) { $loggedInUser = $this->authService->getLoggedInUser(); - if ($userIdentifier instanceof \Szurubooru\Entities\User) + if ($userIdentifier instanceof User) { return $loggedInUser->getId() and ($loggedInUser->getId() === $userIdentifier->getId()); } diff --git a/src/Services/ScoreService.php b/src/Services/ScoreService.php index f4361995..f85d6156 100644 --- a/src/Services/ScoreService.php +++ b/src/Services/ScoreService.php @@ -1,5 +1,13 @@ scoreDao = $scoreDao; $this->favoritesDao = $favoritesDao; @@ -23,7 +31,7 @@ class ScoreService $this->timeService = $timeService; } - public function getScore(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity) + public function getScore(User $user, Entity $entity) { $transactionFunc = function() use ($user, $entity) { @@ -32,7 +40,7 @@ class ScoreService return $this->transactionManager->rollback($transactionFunc); } - public function getScoreValue(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity) + public function getScoreValue(User $user, Entity $entity) { $score = $this->getScore($user, $entity); if (!$score) @@ -40,14 +48,14 @@ class ScoreService return $score->getScore(); } - public function setScore(\Szurubooru\Entities\User $user, \Szurubooru\Entities\Entity $entity, $scoreValue) + public function setScore(User $user, Entity $entity, $scoreValue) { if ($scoreValue !== 1 and $scoreValue !== 0 and $scoreValue !== -1) throw new \DomainException('Bad score'); $transactionFunc = function() use ($user, $entity, $scoreValue) { - if (($scoreValue !== 1) and ($entity instanceof \Szurubooru\Entities\Post)) + if (($scoreValue !== 1) and ($entity instanceof Post)) $this->favoritesDao->delete($user, $entity); return $this->scoreDao->setScore($user, $entity, $scoreValue); diff --git a/src/Services/TagService.php b/src/Services/TagService.php index 281aa4c1..544ec803 100644 --- a/src/Services/TagService.php +++ b/src/Services/TagService.php @@ -1,5 +1,11 @@ transactionManager = $transactionManager; $this->tagDao = $tagDao; @@ -20,7 +26,7 @@ class TagService $this->fileService = $fileService; } - public function getFiltered(\Szurubooru\SearchServices\Filters\TagFilter $filter) + public function getFiltered(TagFilter $filter) { $transactionFunc = function() use ($filter) { @@ -68,7 +74,7 @@ class TagService $tagsToCreate = []; foreach ($tagNamesToCreate as $tagName) { - $tag = new \Szurubooru\Entities\Tag; + $tag = new Tag; $tag->setName($tagName); $tag->setCreationTime($this->timeService->getCurrentTime()); $tagsToCreate[] = $tag; diff --git a/src/Services/ThumbnailGenerators/FlashThumbnailGenerator.php b/src/Services/ThumbnailGenerators/FlashThumbnailGenerator.php index 4ff913b7..22ffeb47 100644 --- a/src/Services/ThumbnailGenerators/FlashThumbnailGenerator.php +++ b/src/Services/ThumbnailGenerators/FlashThumbnailGenerator.php @@ -1,5 +1,6 @@ imageManipulator = $imageManipulator; } @@ -34,7 +36,7 @@ class ImageThumbnailGenerator implements IThumbnailGenerator return $this->imageManipulator->saveToBuffer( $image, - \Szurubooru\Services\ImageManipulation\IImageManipulator::FORMAT_JPEG); + IImageManipulator::FORMAT_JPEG); } catch (\Exception $e) { diff --git a/src/Services/ThumbnailGenerators/SmartThumbnailGenerator.php b/src/Services/ThumbnailGenerators/SmartThumbnailGenerator.php index fe0e4759..1aaba2bc 100644 --- a/src/Services/ThumbnailGenerators/SmartThumbnailGenerator.php +++ b/src/Services/ThumbnailGenerators/SmartThumbnailGenerator.php @@ -1,5 +1,6 @@ flashThumbnailGenerator->generate($source, $width, $height, $cropStyle); - if (\Szurubooru\Helpers\MimeHelper::isVideo($mime)) + if (MimeHelper::isVideo($mime)) return $this->videoThumbnailGenerator->generate($source, $width, $height, $cropStyle); - if (\Szurubooru\Helpers\MimeHelper::isImage($mime)) + if (MimeHelper::isImage($mime)) return $this->imageThumbnailGenerator->generate($source, $width, $height, $cropStyle); return null; diff --git a/src/Services/ThumbnailGenerators/VideoThumbnailGenerator.php b/src/Services/ThumbnailGenerators/VideoThumbnailGenerator.php index 12907d2e..fc67850b 100644 --- a/src/Services/ThumbnailGenerators/VideoThumbnailGenerator.php +++ b/src/Services/ThumbnailGenerators/VideoThumbnailGenerator.php @@ -1,5 +1,6 @@ config = $config; $this->fileService = $fileService; @@ -40,11 +44,11 @@ class ThumbnailService switch ($this->config->misc->thumbnailCropStyle) { case 'outside': - $cropStyle = \Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator::CROP_OUTSIDE; + $cropStyle = IThumbnailGenerator::CROP_OUTSIDE; break; case 'inside': - $cropStyle = \Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator::CROP_INSIDE; + $cropStyle = IThumbnailGenerator::CROP_INSIDE; break; default: diff --git a/src/Services/TokenService.php b/src/Services/TokenService.php index 5bf67ff2..acefe29f 100644 --- a/src/Services/TokenService.php +++ b/src/Services/TokenService.php @@ -1,5 +1,8 @@ transactionManager = $transactionManager; $this->tokenDao = $tokenDao; @@ -52,7 +55,7 @@ class TokenService if (!$token) { - $token = new \Szurubooru\Entities\Token(); + $token = new Token(); $token->setName(sha1(date('r') . uniqid() . microtime(true))); $token->setAdditionalData($additionalData); $token->setPurpose($tokenPurpose); diff --git a/src/Services/UpgradeService.php b/src/Services/UpgradeService.php index b805e61d..8f9f98c5 100644 --- a/src/Services/UpgradeService.php +++ b/src/Services/UpgradeService.php @@ -1,5 +1,9 @@ config = $config; $this->databaseConnection = $databaseConnection; @@ -42,12 +46,12 @@ final class UpgradeService } } - private function isUpgradeNeeded(\Szurubooru\Upgrades\IUpgrade $upgrade) + private function isUpgradeNeeded(IUpgrade $upgrade) { return !in_array(get_class($upgrade), $this->executedUpgradeNames); } - private function runUpgrade(\Szurubooru\Upgrades\IUpgrade $upgrade) + private function runUpgrade(IUpgrade $upgrade) { $upgrade->run($this->databaseConnection); $this->executedUpgradeNames[] = get_class($upgrade); diff --git a/src/Services/UserService.php b/src/Services/UserService.php index 35b24b95..6c56ca0c 100644 --- a/src/Services/UserService.php +++ b/src/Services/UserService.php @@ -1,5 +1,21 @@ config = $config; $this->validator = $validator; @@ -79,7 +95,7 @@ class UserService return $this->transactionManager->rollback($transactionFunc); } - public function getFiltered(\Szurubooru\SearchServices\Filters\UserFilter $filter) + public function getFiltered(UserFilter $filter) { $transactionFunc = function() use ($filter) { @@ -88,30 +104,30 @@ class UserService return $this->transactionManager->rollback($transactionFunc); } - public function createUser(\Szurubooru\FormData\RegistrationFormData $formData) + public function createUser(RegistrationFormData $formData) { $transactionFunc = function() use ($formData) { $formData->validate($this->validator); - $user = new \Szurubooru\Entities\User(); + $user = new User(); $user->setRegistrationTime($this->timeService->getCurrentTime()); $user->setLastLoginTime(null); $user->setAccessRank($this->userDao->hasAnyUsers() - ? \Szurubooru\Entities\User::ACCESS_RANK_REGULAR_USER - : \Szurubooru\Entities\User::ACCESS_RANK_ADMINISTRATOR); + ? User::ACCESS_RANK_REGULAR_USER + : User::ACCESS_RANK_ADMINISTRATOR); $user->setPasswordSalt($this->passwordService->getRandomPassword()); $this->updateUserName($user, $formData->userName); $this->updateUserPassword($user, $formData->password); - $this->updateUserAvatarStyle($user, \Szurubooru\Entities\User::AVATAR_STYLE_GRAVATAR); + $this->updateUserAvatarStyle($user, User::AVATAR_STYLE_GRAVATAR); $this->updateUserEmail($user, $formData->email); return $this->userDao->save($user); }; return $this->transactionManager->commit($transactionFunc); } - public function updateUser(\Szurubooru\Entities\User $user, \Szurubooru\FormData\UserEditFormData $formData) + public function updateUser(User $user, UserEditFormData $formData) { $transactionFunc = function() use ($user, $formData) { @@ -146,7 +162,7 @@ class UserService return $this->transactionManager->commit($transactionFunc); } - public function deleteUser(\Szurubooru\Entities\User $user) + public function deleteUser(User $user) { $transactionFunc = function() use ($user) { @@ -155,21 +171,21 @@ class UserService $this->transactionManager->commit($transactionFunc); } - public function sendPasswordResetEmail(\Szurubooru\Entities\User $user) + public function sendPasswordResetEmail(User $user) { $transactionFunc = function() use ($user) { - $token = $this->tokenService->createAndSaveToken($user->getName(), \Szurubooru\Entities\Token::PURPOSE_PASSWORD_RESET); + $token = $this->tokenService->createAndSaveToken($user->getName(), Token::PURPOSE_PASSWORD_RESET); $this->emailService->sendPasswordResetEmail($user, $token); }; $this->transactionManager->commit($transactionFunc); } - public function finishPasswordReset(\Szurubooru\Entities\Token $token) + public function finishPasswordReset(Token $token) { $transactionFunc = function() use ($token) { - if ($token->getPurpose() !== \Szurubooru\Entities\Token::PURPOSE_PASSWORD_RESET) + if ($token->getPurpose() !== Token::PURPOSE_PASSWORD_RESET) throw new \Exception('This token is not a password reset token.'); $user = $this->getByName($token->getAdditionalData()); @@ -182,21 +198,21 @@ class UserService return $this->transactionManager->commit($transactionFunc); } - public function sendActivationEmail(\Szurubooru\Entities\User $user) + public function sendActivationEmail(User $user) { $transactionFunc = function() use ($user) { - $token = $this->tokenService->createAndSaveToken($user->getName(), \Szurubooru\Entities\Token::PURPOSE_ACTIVATE); + $token = $this->tokenService->createAndSaveToken($user->getName(), Token::PURPOSE_ACTIVATE); $this->emailService->sendActivationEmail($user, $token); }; $this->transactionManager->commit($transactionFunc); } - public function finishActivation(\Szurubooru\Entities\Token $token) + public function finishActivation(Token $token) { $transactionFunc = function() use ($token) { - if ($token->getPurpose() !== \Szurubooru\Entities\Token::PURPOSE_ACTIVATE) + if ($token->getPurpose() !== Token::PURPOSE_ACTIVATE) throw new \Exception('This token is not an activation token.'); $user = $this->getByName($token->getAdditionalData()); @@ -207,15 +223,15 @@ class UserService $this->transactionManager->commit($transactionFunc); } - private function updateUserAvatarStyle(\Szurubooru\Entities\User $user, $newAvatarStyle) + private function updateUserAvatarStyle(User $user, $newAvatarStyle) { $user->setAvatarStyle($newAvatarStyle); } - private function updateUserAvatarContent(\Szurubooru\Entities\User $user, $newAvatarContent) + private function updateUserAvatarContent(User $user, $newAvatarContent) { - $mime = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromBuffer($newAvatarContent); - if (!\Szurubooru\Helpers\MimeHelper::isImage($mime)) + $mime = MimeHelper::getMimeTypeFromBuffer($newAvatarContent); + if (!MimeHelper::isImage($mime)) throw new \DomainException('Avatar must be an image.'); if (strlen($newAvatarContent) > $this->config->database->maxCustomThumbnailSize) @@ -224,18 +240,18 @@ class UserService $user->setCustomAvatarSourceContent($newAvatarContent); } - private function updateUserName(\Szurubooru\Entities\User $user, $newName) + private function updateUserName(User $user, $newName) { $this->assertNoUserWithThisName($user, $newName); $user->setName($newName); } - private function updateUserPassword(\Szurubooru\Entities\User $user, $newPassword) + private function updateUserPassword(User $user, $newPassword) { $user->setPasswordHash($this->passwordService->getHash($newPassword, $user->getPasswordSalt())); } - private function updateUserEmail(\Szurubooru\Entities\User $user, $newEmail) + private function updateUserEmail(User $user, $newEmail) { if ($user->getEmail() === $newEmail) { @@ -249,17 +265,17 @@ class UserService } } - private function updateUserAccessRank(\Szurubooru\Entities\User $user, $newAccessRank) + private function updateUserAccessRank(User $user, $newAccessRank) { $user->setAccessRank($newAccessRank); } - private function updateUserBrowsingSettings(\Szurubooru\Entities\User $user, $newBrowsingSettings) + private function updateUserBrowsingSettings(User $user, $newBrowsingSettings) { $user->setBrowsingSettings($newBrowsingSettings); } - public function updateUserLastLoginTime(\Szurubooru\Entities\User $user) + public function updateUserLastLoginTime(User $user) { $transactionFunc = function() use ($user) { @@ -269,9 +285,9 @@ class UserService $this->transactionManager->commit($transactionFunc); } - private function sendActivationEmailIfNeeded(\Szurubooru\Entities\User $user) + private function sendActivationEmailIfNeeded(User $user) { - if ($user->getAccessRank() === \Szurubooru\Entities\User::ACCESS_RANK_ADMINISTRATOR + if ($user->getAccessRank() === User::ACCESS_RANK_ADMINISTRATOR or !$this->config->security->needEmailActivationToRegister) { $user = $this->confirmUserEmail($user); @@ -283,7 +299,7 @@ class UserService return $user; } - private function confirmUserEmail(\Szurubooru\Entities\User $user) + private function confirmUserEmail(User $user) { //security issue: //1. two users set their unconfirmed mail to godzilla@empire.gov @@ -301,14 +317,14 @@ class UserService return $user; } - private function assertNoUserWithThisName(\Szurubooru\Entities\User $owner, $nameToCheck) + private function assertNoUserWithThisName(User $owner, $nameToCheck) { $userWithThisName = $this->userDao->findByName($nameToCheck); if ($userWithThisName and $userWithThisName->getId() !== $owner->getId()) throw new \DomainException('User with this name already exists.'); } - private function assertNoUserWithThisEmail(\Szurubooru\Entities\User $owner, $emailToCheck) + private function assertNoUserWithThisEmail(User $owner, $emailToCheck) { if (!$emailToCheck) return; diff --git a/src/Upgrades/IUpgrade.php b/src/Upgrades/IUpgrade.php index 27213f2d..90e66ee9 100644 --- a/src/Upgrades/IUpgrade.php +++ b/src/Upgrades/IUpgrade.php @@ -1,7 +1,8 @@ getDriver(); diff --git a/src/Upgrades/Upgrade02.php b/src/Upgrades/Upgrade02.php index d774ba59..80254361 100644 --- a/src/Upgrades/Upgrade02.php +++ b/src/Upgrades/Upgrade02.php @@ -1,9 +1,10 @@ getPDO()->exec(' ALTER TABLE users ADD COLUMN accountConfirmed BOOLEAN NOT NULL DEFAULT FALSE'); diff --git a/src/Upgrades/Upgrade03.php b/src/Upgrades/Upgrade03.php index f9e555e7..3750054e 100644 --- a/src/Upgrades/Upgrade03.php +++ b/src/Upgrades/Upgrade03.php @@ -1,9 +1,10 @@ getPDO(); $driver = $databaseConnection->getDriver(); diff --git a/src/Upgrades/Upgrade04.php b/src/Upgrades/Upgrade04.php index b9f884a0..07d468a8 100644 --- a/src/Upgrades/Upgrade04.php +++ b/src/Upgrades/Upgrade04.php @@ -1,5 +1,11 @@ postDao = $postDao; $this->postService = $postService; $this->fileService = $fileService; } - public function run(\Szurubooru\DatabaseConnection $databaseConnection) + public function run(DatabaseConnection $databaseConnection) { $databaseConnection->getPDO()->exec('ALTER TABLE posts ADD COLUMN contentMimeType VARCHAR(64) DEFAULT NULL'); $posts = $this->postDao->findAll(); foreach ($posts as $post) { - if ($post->getContentType() !== \Szurubooru\Entities\Post::POST_TYPE_YOUTUBE) + if ($post->getContentType() !== Post::POST_TYPE_YOUTUBE) { $fullPath = $this->fileService->getFullPath($post->getContentPath()); - $mime = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromFile($fullPath); + $mime = MimeHelper::getMimeTypeFromFile($fullPath); $post->setContentMimeType($mime); $this->postDao->save($post); } diff --git a/src/Upgrades/Upgrade05.php b/src/Upgrades/Upgrade05.php index ecfcf782..1f2db4c2 100644 --- a/src/Upgrades/Upgrade05.php +++ b/src/Upgrades/Upgrade05.php @@ -1,9 +1,10 @@ getPDO(); $driver = $databaseConnection->getDriver(); diff --git a/src/Upgrades/Upgrade06.php b/src/Upgrades/Upgrade06.php index 815f27b5..05166178 100644 --- a/src/Upgrades/Upgrade06.php +++ b/src/Upgrades/Upgrade06.php @@ -1,9 +1,10 @@ getPDO(); diff --git a/src/Upgrades/Upgrade07.php b/src/Upgrades/Upgrade07.php index 1878875e..4be6d3f1 100644 --- a/src/Upgrades/Upgrade07.php +++ b/src/Upgrades/Upgrade07.php @@ -1,9 +1,10 @@ getPDO(); $driver = $databaseConnection->getDriver(); diff --git a/src/Upgrades/Upgrade08.php b/src/Upgrades/Upgrade08.php index 7b34fb3b..6ae259cf 100644 --- a/src/Upgrades/Upgrade08.php +++ b/src/Upgrades/Upgrade08.php @@ -1,9 +1,10 @@ getPDO(); $driver = $databaseConnection->getDriver(); diff --git a/src/Upgrades/Upgrade09.php b/src/Upgrades/Upgrade09.php index 179ac3b0..69e02c02 100644 --- a/src/Upgrades/Upgrade09.php +++ b/src/Upgrades/Upgrade09.php @@ -1,5 +1,8 @@ postDao = $postDao; $this->historyService = $historyService; } - public function run(\Szurubooru\DatabaseConnection $databaseConnection) + public function run(DatabaseConnection $databaseConnection) { $pdo = $databaseConnection->getPDO(); $driver = $databaseConnection->getDriver(); diff --git a/src/Upgrades/Upgrade10.php b/src/Upgrades/Upgrade10.php index 2515939d..f6fa78c3 100644 --- a/src/Upgrades/Upgrade10.php +++ b/src/Upgrades/Upgrade10.php @@ -1,9 +1,10 @@ getPDO(); $driver = $databaseConnection->getDriver(); diff --git a/src/Upgrades/Upgrade11.php b/src/Upgrades/Upgrade11.php index ae01d61f..1ab3d945 100644 --- a/src/Upgrades/Upgrade11.php +++ b/src/Upgrades/Upgrade11.php @@ -1,9 +1,10 @@ getPDO(); $driver = $databaseConnection->getDriver(); diff --git a/src/Upgrades/Upgrade12.php b/src/Upgrades/Upgrade12.php index 5ec1920c..3c4d1bed 100644 --- a/src/Upgrades/Upgrade12.php +++ b/src/Upgrades/Upgrade12.php @@ -1,16 +1,18 @@ tagService = $tagService; } - public function run(\Szurubooru\DatabaseConnection $databaseConnection) + public function run(DatabaseConnection $databaseConnection) { $this->tagService->exportJson(); } diff --git a/src/Upgrades/Upgrade13.php b/src/Upgrades/Upgrade13.php index 17f740f6..70aaf79d 100644 --- a/src/Upgrades/Upgrade13.php +++ b/src/Upgrades/Upgrade13.php @@ -1,9 +1,10 @@ getPDO(); diff --git a/src/Upgrades/Upgrade14.php b/src/Upgrades/Upgrade14.php index d3dd4926..ad42b4dd 100644 --- a/src/Upgrades/Upgrade14.php +++ b/src/Upgrades/Upgrade14.php @@ -1,9 +1,10 @@ getPDO(); $driver = $databaseConnection->getDriver(); diff --git a/src/Upgrades/Upgrade15.php b/src/Upgrades/Upgrade15.php index 46aa3050..638bec43 100644 --- a/src/Upgrades/Upgrade15.php +++ b/src/Upgrades/Upgrade15.php @@ -1,9 +1,10 @@ getPDO(); $driver = $databaseConnection->getDriver(); diff --git a/src/Upgrades/Upgrade16.php b/src/Upgrades/Upgrade16.php index 2304c833..30269078 100644 --- a/src/Upgrades/Upgrade16.php +++ b/src/Upgrades/Upgrade16.php @@ -1,9 +1,10 @@ getPDO(); diff --git a/src/Upgrades/Upgrade17.php b/src/Upgrades/Upgrade17.php index 28098471..35fb5f73 100644 --- a/src/Upgrades/Upgrade17.php +++ b/src/Upgrades/Upgrade17.php @@ -1,9 +1,10 @@ getPDO(); diff --git a/src/Upgrades/Upgrade18.php b/src/Upgrades/Upgrade18.php index 425721b7..afb5f205 100644 --- a/src/Upgrades/Upgrade18.php +++ b/src/Upgrades/Upgrade18.php @@ -1,9 +1,10 @@ getPDO(); diff --git a/src/Validator.php b/src/Validator.php index f6cdf7ba..71c592bb 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -1,16 +1,18 @@ config = $config; } - public function validate(\Szurubooru\IValidatable $validatable) + public function validate(IValidatable $validatable) { $validatable->validate($this); } diff --git a/tests/AbstractDatabaseTestCase.php b/tests/AbstractDatabaseTestCase.php index 6b7275bd..c53cc4ed 100644 --- a/tests/AbstractDatabaseTestCase.php +++ b/tests/AbstractDatabaseTestCase.php @@ -1,7 +1,16 @@ set('database/password', ''); $fileService = $this->prepareFileService(); - $this->databaseConnection = new \Szurubooru\DatabaseConnection($config); - \Szurubooru\Injector::set(\Szurubooru\DatabaseConnection::class, $this->databaseConnection); - \Szurubooru\Injector::set(\Szurubooru\Services\FileService::class, $fileService); + $this->databaseConnection = new DatabaseConnection($config); + Injector::set(DatabaseConnection::class, $this->databaseConnection); + Injector::set(FileService::class, $fileService); - $upgradeRepository = \Szurubooru\Injector::get(\Szurubooru\Upgrades\UpgradeRepository::class); - $upgradeService = new \Szurubooru\Services\UpgradeService($config, $this->databaseConnection, $upgradeRepository); + $upgradeRepository = Injector::get(UpgradeRepository::class); + $upgradeService = new UpgradeService($config, $this->databaseConnection, $upgradeRepository); $upgradeService->runUpgradesQuiet(); } @@ -27,8 +36,8 @@ abstract class AbstractDatabaseTestCase extends \Szurubooru\Tests\AbstractTestCa { $testDirectory = $this->createTestDirectory(); $configMock = $this->mockConfig(null, $testDirectory); - $httpHelper = \Szurubooru\Injector::get(\Szurubooru\Helpers\HttpHelper::class); - return new \Szurubooru\Services\FileService($configMock, $httpHelper); + $httpHelper = Injector::get(HttpHelper::class); + return new FileService($configMock, $httpHelper); } public function tearDown() @@ -40,23 +49,23 @@ abstract class AbstractDatabaseTestCase extends \Szurubooru\Tests\AbstractTestCa protected static function getTestPost() { - $post = new \Szurubooru\Entities\Post(); + $post = new Post(); $post->setName('test'); $post->setUploadTime(date('c')); - $post->setSafety(\Szurubooru\Entities\Post::POST_SAFETY_SAFE); - $post->setContentType(\Szurubooru\Entities\Post::POST_TYPE_YOUTUBE); + $post->setSafety(Post::POST_SAFETY_SAFE); + $post->setContentType(Post::POST_TYPE_YOUTUBE); $post->setContentChecksum('whatever'); return $post; } protected static function getTestUser($userName = 'test') { - $user = new \Szurubooru\Entities\User(); + $user = new User(); $user->setName($userName); $user->setPasswordHash('whatever'); $user->setLastLoginTime(date('c', mktime(1, 2, 3))); $user->setRegistrationTime(date('c', mktime(3, 2, 1))); - $user->setAccessRank(\Szurubooru\Entities\User::ACCESS_RANK_REGULAR_USER); + $user->setAccessRank(User::ACCESS_RANK_REGULAR_USER); return $user; } } diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php index 110ba2c6..2d8fc7c6 100644 --- a/tests/AbstractTestCase.php +++ b/tests/AbstractTestCase.php @@ -1,11 +1,13 @@ mock(\Szurubooru\DatabaseConnection::class)); + return new TransactionManagerMock($this->mock(DatabaseConnection::class)); } protected function createTestDirectory() diff --git a/tests/ConfigMock.php b/tests/ConfigMock.php index 8212844a..0893bf2e 100644 --- a/tests/ConfigMock.php +++ b/tests/ConfigMock.php @@ -1,7 +1,8 @@ testDirectory, null); + return new Config($this->testDirectory, null); } } diff --git a/tests/ControllerRepositoryTest.php b/tests/ControllerRepositoryTest.php index 36d33b82..218472dd 100644 --- a/tests/ControllerRepositoryTest.php +++ b/tests/ControllerRepositoryTest.php @@ -1,11 +1,13 @@ assertNotEmpty($controllerRepository->getControllers()); } } diff --git a/tests/Dao/CommentDaoTest.php b/tests/Dao/CommentDaoTest.php index 1c8044fb..75da8e2d 100644 --- a/tests/Dao/CommentDaoTest.php +++ b/tests/Dao/CommentDaoTest.php @@ -1,7 +1,15 @@ userDaoMock = $this->mock(\Szurubooru\Dao\UserDao::class); - $this->postDaoMock = $this->mock(\Szurubooru\Dao\PostDao::class); + $this->userDaoMock = $this->mock(UserDao::class); + $this->postDaoMock = $this->mock(PostDao::class); } public function testSaving() { - $user = new \Szurubooru\Entities\User(1); + $user = new User(1); $user->setName('olivia'); - $post = new \Szurubooru\Entities\Post(2); + $post = new Post(2); $post->setName('sword'); - $comment = new \Szurubooru\Entities\Comment(); + $comment = new Comment(); $comment->setUser($user); $comment->setPost($post); $comment->setCreationTime(date('c')); @@ -45,9 +53,9 @@ class CommentDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testPostMetadataSyncInsert() { - $userDao = \Szurubooru\Injector::get(\Szurubooru\Dao\UserDao::class); - $postDao = \Szurubooru\Injector::get(\Szurubooru\Dao\PostDao::class); - $commentDao = \Szurubooru\Injector::get(\Szurubooru\Dao\CommentDao::class); + $userDao = Injector::get(UserDao::class); + $postDao = Injector::get(PostDao::class); + $commentDao = Injector::get(CommentDao::class); $user = self::getTestUser('olivia'); $userDao->save($user); @@ -58,7 +66,7 @@ class CommentDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase $this->assertEquals(0, $post->getCommentCount()); $this->assertNotNull($post->getId()); - $comment = new \Szurubooru\Entities\Comment(); + $comment = new Comment(); $comment->setUser($user); $comment->setPost($post); $comment->setCreationTime(date('c')); @@ -87,14 +95,14 @@ class CommentDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase $this->assertEquals(0, $post->getCommentCount()); } - public function findByPost(\Szurubooru\Entities\Post $post) + public function findByPost(Post $post) { return $this->findOneBy('postId', $post->getId()); } private function getCommentDao() { - return new \Szurubooru\Dao\CommentDao( + return new CommentDao( $this->databaseConnection, $this->userDaoMock, $this->postDaoMock); diff --git a/tests/Dao/FavoritesDaoTest.php b/tests/Dao/FavoritesDaoTest.php index d24cc4a5..2216a010 100644 --- a/tests/Dao/FavoritesDaoTest.php +++ b/tests/Dao/FavoritesDaoTest.php @@ -1,25 +1,31 @@ timeServiceMock = $this->mock(\Szurubooru\Services\TimeService::class); + $this->timeServiceMock = $this->mock(TimeService::class); } public function testSaving() { - $user = new \Szurubooru\Entities\User(1); + $user = new User(1); $user->setName('olivia'); - $post = new \Szurubooru\Entities\Post(2); + $post = new Post(2); $post->setName('sword'); - $favorite = new \Szurubooru\Entities\Favorite(); + $favorite = new Favorite(); $favorite->setUserId($user->getId()); $favorite->setPostId($post->getId()); $favorite->setTime(date('c')); @@ -36,7 +42,7 @@ class FavoritesDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase private function getFavoritesDao() { - return new \Szurubooru\Dao\FavoritesDao( + return new FavoritesDao( $this->databaseConnection, $this->timeServiceMock); } diff --git a/tests/Dao/GlobalParamDaoTest.php b/tests/Dao/GlobalParamDaoTest.php index 4ce94377..301a1f9b 100644 --- a/tests/Dao/GlobalParamDaoTest.php +++ b/tests/Dao/GlobalParamDaoTest.php @@ -1,11 +1,14 @@ setKey('key'); $expected->setValue('test'); @@ -18,11 +21,11 @@ class GlobalParamDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testInsertingSameKeyTwice() { - $param1 = new \Szurubooru\Entities\GlobalParam(); + $param1 = new GlobalParam(); $param1->setKey('key'); $param1->setValue('value1'); - $param2 = new \Szurubooru\Entities\GlobalParam(); + $param2 = new GlobalParam(); $param2->setKey('key'); $param2->setValue('value2'); @@ -35,7 +38,7 @@ class GlobalParamDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testUpdatingValues() { - $expected = new \Szurubooru\Entities\GlobalParam(); + $expected = new GlobalParam(); $expected->setKey('key'); $expected->setValue('test'); @@ -59,6 +62,6 @@ class GlobalParamDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase private function getGlobalParamDao() { - return new \Szurubooru\Dao\GlobalParamDao($this->databaseConnection); + return new GlobalParamDao($this->databaseConnection); } } diff --git a/tests/Dao/PostDaoTest.php b/tests/Dao/PostDaoTest.php index 771e7fe4..40dcbe7e 100644 --- a/tests/Dao/PostDaoTest.php +++ b/tests/Dao/PostDaoTest.php @@ -1,7 +1,15 @@ fileServiceMock = $this->mock(\Szurubooru\Services\FileService::class); - $this->thumbnailServiceMock = $this->mock(\Szurubooru\Services\ThumbnailService::class); + $this->fileServiceMock = $this->mock(FileService::class); + $this->thumbnailServiceMock = $this->mock(ThumbnailService::class); - $this->tagDao = new \Szurubooru\Dao\TagDao( + $this->tagDao = new TagDao( $this->databaseConnection, $this->fileServiceMock); - $this->userDao = new \Szurubooru\Dao\UserDao( + $this->userDao = new UserDao( $this->databaseConnection, $this->fileServiceMock, $this->thumbnailServiceMock); @@ -141,10 +149,10 @@ final class PostDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testSavingTags() { - $tag1 = new \Szurubooru\Entities\Tag(); + $tag1 = new Tag(); $tag1->setName('tag1'); $tag1->setCreationTime(date('c')); - $tag2 = new \Szurubooru\Entities\Tag(); + $tag2 = new Tag(); $tag2->setName('tag2'); $tag2->setCreationTime(date('c')); $this->tagDao->save($tag1); @@ -200,7 +208,7 @@ final class PostDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testSavingUser() { - $testUser = new \Szurubooru\Entities\User(5); + $testUser = new User(5); $testUser->setName('it\'s me'); $postDao = $this->getPostDao(); @@ -286,7 +294,7 @@ final class PostDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase private function getPostDao() { - return new \Szurubooru\Dao\PostDao( + return new PostDao( $this->databaseConnection, $this->tagDao, $this->userDao, diff --git a/tests/Dao/ScoreDaoTest.php b/tests/Dao/ScoreDaoTest.php index 003de372..6c4c0958 100644 --- a/tests/Dao/ScoreDaoTest.php +++ b/tests/Dao/ScoreDaoTest.php @@ -1,25 +1,31 @@ timeServiceMock = $this->mock(\Szurubooru\Services\TimeService::class); + $this->timeServiceMock = $this->mock(TimeService::class); } public function testSaving() { - $user = new \Szurubooru\Entities\User(1); + $user = new User(1); $user->setName('olivia'); - $post = new \Szurubooru\Entities\Post(2); + $post = new Post(2); $post->setName('sword'); - $score = new \Szurubooru\Entities\Score(); + $score = new Score(); $score->setUserId($user->getId()); $score->setPostId($post->getId()); $score->setTime(date('c')); @@ -37,24 +43,24 @@ class ScoreDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testFindingByUserAndPost() { - $post1 = new \Szurubooru\Entities\Post(1); - $post2 = new \Szurubooru\Entities\Post(2); - $user1 = new \Szurubooru\Entities\User(3); - $user2 = new \Szurubooru\Entities\User(4); + $post1 = new Post(1); + $post2 = new Post(2); + $user1 = new User(3); + $user2 = new User(4); - $score1 = new \Szurubooru\Entities\Score(); + $score1 = new Score(); $score1->setUserId($user1->getId()); $score1->setPostId($post1->getId()); $score1->setTime(date('c', mktime(1))); $score1->setScore(1); - $score2 = new \Szurubooru\Entities\Score(); + $score2 = new Score(); $score2->setUserId($user2->getId()); $score2->setPostId($post2->getId()); $score2->setTime(date('c', mktime(2))); $score2->setScore(0); - $score3 = new \Szurubooru\Entities\Score(); + $score3 = new Score(); $score3->setUserId($user1->getId()); $score3->setPostId($post2->getId()); $score3->setTime(date('c', mktime(3))); @@ -71,14 +77,14 @@ class ScoreDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase $this->assertNull($scoreDao->getScore($user2, $post1)); } - public function findByPost(\Szurubooru\Entities\Post $post) + public function findByPost(Post $post) { return $this->findOneBy('postId', $post->getId()); } private function getScoreDao() { - return new \Szurubooru\Dao\ScoreDao( + return new ScoreDao( $this->databaseConnection, $this->timeServiceMock); } diff --git a/tests/Dao/SnapshotDaoTest.php b/tests/Dao/SnapshotDaoTest.php index a245a0c1..07fdd0d7 100644 --- a/tests/Dao/SnapshotDaoTest.php +++ b/tests/Dao/SnapshotDaoTest.php @@ -1,12 +1,17 @@ userDaoMock = $this->mock(\Szurubooru\Dao\UserDao::class); + $this->userDaoMock = $this->mock(UserDao::class); } public function testSaving() @@ -21,7 +26,7 @@ class SnapshotDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testUserLazyLoader() { $snapshot = $this->getTestSnapshot(); - $snapshot->setUser(new \Szurubooru\Entities\User(5)); + $snapshot->setUser(new User(5)); $this->assertEquals(5, $snapshot->getUserId()); $snapshotDao = $this->getSnapshotDao(); $snapshotDao->save($snapshot); @@ -36,19 +41,19 @@ class SnapshotDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase private function getTestSnapshot() { - $snapshot = new \Szurubooru\Entities\Snapshot(); - $snapshot->setType(\Szurubooru\Entities\Snapshot::TYPE_POST); + $snapshot = new Snapshot(); + $snapshot->setType(Snapshot::TYPE_POST); $snapshot->setData(['wake up', 'neo', ['follow' => 'white rabbit']]); $snapshot->setPrimaryKey(1); $snapshot->setTime(date('c', mktime(1, 2, 3))); $snapshot->setUserId(null); - $snapshot->setOperation(\Szurubooru\Entities\Snapshot::OPERATION_CHANGE); + $snapshot->setOperation(Snapshot::OPERATION_CHANGE); return $snapshot; } private function getSnapshotDao() { - return new \Szurubooru\Dao\SnapshotDao( + return new SnapshotDao( $this->databaseConnection, $this->userDaoMock); } diff --git a/tests/Dao/TagDaoTest.php b/tests/Dao/TagDaoTest.php index bd507f5e..019d7265 100644 --- a/tests/Dao/TagDaoTest.php +++ b/tests/Dao/TagDaoTest.php @@ -1,7 +1,10 @@ exec('INSERT INTO postTags(postId, tagId) VALUES (5, 2)'); $pdo->exec('INSERT INTO postTags(postId, tagId) VALUES (6, 2)'); - $tag1 = new \Szurubooru\Entities\Tag(1); + $tag1 = new Tag(1); $tag1->setName('test1'); $tag1->setCreationTime(date('c', mktime(0, 0, 0, 10, 1, 2014))); - $tag2 = new \Szurubooru\Entities\Tag(2); + $tag2 = new Tag(2); $tag2->setName('test2'); $tag2->setCreationTime(date('c', mktime(0, 0, 0, 10, 1, 2014))); @@ -37,10 +40,10 @@ final class TagDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testRemovingUnused() { - $tag1 = new \Szurubooru\Entities\Tag(); + $tag1 = new Tag(); $tag1->setName('test1'); $tag1->setCreationTime(date('c')); - $tag2 = new \Szurubooru\Entities\Tag(); + $tag2 = new Tag(); $tag2->setName('test2'); $tag2->setCreationTime(date('c')); $tagDao = $this->getTagDao(); @@ -61,6 +64,6 @@ final class TagDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase private function getTagDao() { - return new \Szurubooru\Dao\TagDao($this->databaseConnection); + return new TagDao($this->databaseConnection); } } diff --git a/tests/Dao/TokenDaoTest.php b/tests/Dao/TokenDaoTest.php index f09cea57..45cca05f 100644 --- a/tests/Dao/TokenDaoTest.php +++ b/tests/Dao/TokenDaoTest.php @@ -1,13 +1,16 @@ setName('test'); - $token->setPurpose(\Szurubooru\Entities\Token::PURPOSE_LOGIN); + $token->setPurpose(Token::PURPOSE_LOGIN); $tokenDao = $this->getTokenDao(); $tokenDao->save($token); @@ -27,20 +30,20 @@ final class TokenDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testRetrievingByAdditionalDataAndPurpose() { - $token = new \Szurubooru\Entities\Token(); + $token = new Token(); $token->setName('test'); - $token->setPurpose(\Szurubooru\Entities\Token::PURPOSE_LOGIN); + $token->setPurpose(Token::PURPOSE_LOGIN); $tokenDao = $this->getTokenDao(); $tokenDao->save($token); $expected = $token; - $this->assertEntitiesEqual($expected, $tokenDao->findByAdditionalDataAndPurpose(null, \Szurubooru\Entities\Token::PURPOSE_LOGIN)); - $this->assertNull($tokenDao->findByAdditionalDataAndPurpose(null, \Szurubooru\Entities\Token::PURPOSE_ACTIVATE)); + $this->assertEntitiesEqual($expected, $tokenDao->findByAdditionalDataAndPurpose(null, Token::PURPOSE_LOGIN)); + $this->assertNull($tokenDao->findByAdditionalDataAndPurpose(null, Token::PURPOSE_ACTIVATE)); } private function getTokenDao() { - return new \Szurubooru\Dao\TokenDao($this->databaseConnection); + return new TokenDao($this->databaseConnection); } } diff --git a/tests/Dao/TransactionManagerTest.php b/tests/Dao/TransactionManagerTest.php index 22325fcd..d1d4d6e7 100644 --- a/tests/Dao/TransactionManagerTest.php +++ b/tests/Dao/TransactionManagerTest.php @@ -1,7 +1,11 @@ setName('yo'); - $token->setPurpose(\Szurubooru\Entities\Token::PURPOSE_ACTIVATE); + $token->setPurpose(Token::PURPOSE_ACTIVATE); return $token; } private function getTestDao() { - return new \Szurubooru\Dao\TokenDao($this->databaseConnection); + return new TokenDao($this->databaseConnection); } private function getTransactionManager() { - return new \Szurubooru\Dao\TransactionManager($this->databaseConnection); + return new TransactionManager($this->databaseConnection); } } diff --git a/tests/Dao/UserDaoFilterTest.php b/tests/Dao/UserDaoFilterTest.php index e7becb4e..d9c802cd 100644 --- a/tests/Dao/UserDaoFilterTest.php +++ b/tests/Dao/UserDaoFilterTest.php @@ -1,7 +1,13 @@ fileServiceMock = $this->mock(\Szurubooru\Services\FileService::class); - $this->thumbnailServiceMock = $this->mock(\Szurubooru\Services\ThumbnailService::class); + $this->fileServiceMock = $this->mock(FileService::class); + $this->thumbnailServiceMock = $this->mock(ThumbnailService::class); } public function pagingProvider() @@ -27,7 +33,7 @@ class UserDaoFilterTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testNothing() { - $searchFilter = new \Szurubooru\SearchServices\Filters\UserFilter(); + $searchFilter = new UserFilter(); $searchFilter->setPageNumber(1); $searchFilter->setPageSize(2); $userDao = $this->getUserDao(); @@ -53,10 +59,10 @@ class UserDaoFilterTest extends \Szurubooru\Tests\AbstractDatabaseTestCase $expectedUsers[] = $user; } - $searchFilter = new \Szurubooru\SearchServices\Filters\UserFilter(); + $searchFilter = new UserFilter(); $searchFilter->setOrder([ - \Szurubooru\SearchServices\Filters\UserFilter::ORDER_NAME => - \Szurubooru\SearchServices\Filters\UserFilter::ORDER_DESC]); + UserFilter::ORDER_NAME => + UserFilter::ORDER_DESC]); $searchFilter->setPageNumber($pageNumber); $searchFilter->setPageSize($pageSize); @@ -77,8 +83,8 @@ class UserDaoFilterTest extends \Szurubooru\Tests\AbstractDatabaseTestCase { list ($user1, $user2) = $this->prepareUsers(); $this->doTestSorting( - \Szurubooru\SearchServices\Filters\UserFilter::ORDER_NAME, - \Szurubooru\SearchServices\Filters\UserFilter::ORDER_ASC, + UserFilter::ORDER_NAME, + UserFilter::ORDER_ASC, [$user1, $user2]); } @@ -86,8 +92,8 @@ class UserDaoFilterTest extends \Szurubooru\Tests\AbstractDatabaseTestCase { list ($user1, $user2) = $this->prepareUsers(); $this->doTestSorting( - \Szurubooru\SearchServices\Filters\UserFilter::ORDER_NAME, - \Szurubooru\SearchServices\Filters\UserFilter::ORDER_DESC, + UserFilter::ORDER_NAME, + UserFilter::ORDER_DESC, [$user2, $user1]); } @@ -95,8 +101,8 @@ class UserDaoFilterTest extends \Szurubooru\Tests\AbstractDatabaseTestCase { list ($user1, $user2) = $this->prepareUsers(); $this->doTestSorting( - \Szurubooru\SearchServices\Filters\UserFilter::ORDER_REGISTRATION_TIME, - \Szurubooru\SearchServices\Filters\UserFilter::ORDER_ASC, + UserFilter::ORDER_REGISTRATION_TIME, + UserFilter::ORDER_ASC, [$user2, $user1]); } @@ -104,8 +110,8 @@ class UserDaoFilterTest extends \Szurubooru\Tests\AbstractDatabaseTestCase { list ($user1, $user2) = $this->prepareUsers(); $this->doTestSorting( - \Szurubooru\SearchServices\Filters\UserFilter::ORDER_REGISTRATION_TIME, - \Szurubooru\SearchServices\Filters\UserFilter::ORDER_DESC, + UserFilter::ORDER_REGISTRATION_TIME, + UserFilter::ORDER_DESC, [$user1, $user2]); } @@ -125,12 +131,12 @@ class UserDaoFilterTest extends \Szurubooru\Tests\AbstractDatabaseTestCase private function doTestSorting($order, $orderDirection, $expectedUsers) { $userDao = $this->getUserDao(); - $searchFilter = new \Szurubooru\SearchServices\Filters\UserFilter(); + $searchFilter = new UserFilter(); if ($order !== null) $searchFilter->setOrder([$order => $orderDirection]); $result = $userDao->findFiltered($searchFilter, 1, 10); - $this->assertInstanceOf(\Szurubooru\SearchServices\Result::class, $result); + $this->assertInstanceOf(Result::class, $result); $this->assertEquals($searchFilter, $result->getSearchFilter()); $this->assertEntitiesEqual(array_values($expectedUsers), array_values($result->getEntities())); $this->assertEquals(count($expectedUsers), $result->getTotalRecords()); @@ -140,7 +146,7 @@ class UserDaoFilterTest extends \Szurubooru\Tests\AbstractDatabaseTestCase private function getUserDao() { - return new \Szurubooru\Dao\UserDao( + return new UserDao( $this->databaseConnection, $this->fileServiceMock, $this->thumbnailServiceMock); diff --git a/tests/Dao/UserDaoTest.php b/tests/Dao/UserDaoTest.php index f98f42af..3a0c955a 100644 --- a/tests/Dao/UserDaoTest.php +++ b/tests/Dao/UserDaoTest.php @@ -1,7 +1,12 @@ fileServiceMock = $this->mock(\Szurubooru\Services\FileService::class); - $this->thumbnailServiceMock = $this->mock(\Szurubooru\Services\ThumbnailService::class); + $this->fileServiceMock = $this->mock(FileService::class); + $this->thumbnailServiceMock = $this->mock(ThumbnailService::class); } public function testRetrievingByValidName() @@ -49,7 +54,7 @@ final class UserDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase { $userDao = $this->getUserDao(); $user = self::getTestUser(); - $user->setAvatarStyle(\Szurubooru\Entities\User::AVATAR_STYLE_MANUAL); + $user->setAvatarStyle(User::AVATAR_STYLE_MANUAL); $userDao->save($user); $this->assertNull($user->getCustomAvatarSourceContent()); @@ -59,7 +64,7 @@ final class UserDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase { $userDao = $this->getUserDao(); $user = self::getTestUser(); - $user->setAvatarStyle(\Szurubooru\Entities\User::AVATAR_STYLE_MANUAL); + $user->setAvatarStyle(User::AVATAR_STYLE_MANUAL); $userDao->save($user); $user = $userDao->findById($user->getId()); @@ -76,7 +81,7 @@ final class UserDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase { $userDao = $this->getUserDao(); $user = self::getTestUser(); - $user->setAvatarStyle(\Szurubooru\Entities\User::AVATAR_STYLE_MANUAL); + $user->setAvatarStyle(User::AVATAR_STYLE_MANUAL); $user->setCustomAvatarSourceContent('whatever'); $this->thumbnailServiceMock @@ -103,7 +108,7 @@ final class UserDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase private function getUserDao() { - return new \Szurubooru\Dao\UserDao( + return new UserDao( $this->databaseConnection, $this->fileServiceMock, $this->thumbnailServiceMock); diff --git a/tests/DispatcherTest.php b/tests/DispatcherTest.php index 29e09315..ea603433 100644 --- a/tests/DispatcherTest.php +++ b/tests/DispatcherTest.php @@ -1,7 +1,14 @@ routerMock = $this->mock(\Szurubooru\Router::class); + $this->routerMock = $this->mock(Router::class); $this->configMock = $this->mockConfig(); - $this->httpHelperMock = $this->mock(\Szurubooru\Helpers\HttpHelper::class); - $this->authServiceMock = $this->mock(\Szurubooru\Services\AuthService::class); - $this->tokenServiceMock = $this->mock(\Szurubooru\Services\TokenService::class); - $this->controllerRepositoryMock = $this->mock(\Szurubooru\ControllerRepository::class); + $this->httpHelperMock = $this->mock(HttpHelper::class); + $this->authServiceMock = $this->mock(AuthService::class); + $this->tokenServiceMock = $this->mock(TokenService::class); + $this->controllerRepositoryMock = $this->mock(ControllerRepository::class); $this->configMock->set('misc/dumpSqlIntoQueries', 0); } @@ -68,7 +75,7 @@ final class DispatcherTest extends \Szurubooru\Tests\AbstractDatabaseTestCase private function getDispatcher() { - return new \Szurubooru\Dispatcher( + return new Dispatcher( $this->routerMock, $this->configMock, $this->databaseConnection, diff --git a/tests/Helpers/InputReaderTest.php b/tests/Helpers/InputReaderTest.php index c60c9d88..fe81d4f9 100644 --- a/tests/Helpers/InputReaderTest.php +++ b/tests/Helpers/InputReaderTest.php @@ -1,11 +1,13 @@ decodeBase64('data:text/plain,YXdlc29tZSBkb2c='); $expected = 'awesome dog'; $this->assertEquals($expected, $actual); @@ -13,7 +15,7 @@ class InputReaderTest extends \Szurubooru\Tests\AbstractTestCase public function testDecodingEmptyBase64() { - $inputReader = new \Szurubooru\Helpers\InputReader(); + $inputReader = new InputReader(); $this->assertNull($inputReader->decodeBase64($inputReader->iDontEvenExist)); } } diff --git a/tests/Helpers/MimeHelperTest.php b/tests/Helpers/MimeHelperTest.php index 17285705..8362dc06 100644 --- a/tests/Helpers/MimeHelperTest.php +++ b/tests/Helpers/MimeHelperTest.php @@ -1,39 +1,41 @@ getTestFile('image.jpg')); + $actual = MimeHelper::getMimeTypeFromBuffer($this->getTestFile('image.jpg')); $this->assertEquals($expected, $actual); } public function testIsFlash() { - $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isFlash('application/x-shockwave-flash')); - $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isFlash('APPLICATION/X-SHOCKWAVE-FLASH')); - $this->assertFalse(\Szurubooru\Helpers\MimeHelper::isFlash('something else')); + $this->assertTrue(MimeHelper::isFlash('application/x-shockwave-flash')); + $this->assertTrue(MimeHelper::isFlash('APPLICATION/X-SHOCKWAVE-FLASH')); + $this->assertFalse(MimeHelper::isFlash('something else')); } public function testIsImage() { - $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isImage('IMAGE/JPEG')); - $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isImage('IMAGE/PNG')); - $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isImage('IMAGE/GIF')); - $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isImage('image/jpeg')); - $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isImage('image/png')); - $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isImage('image/gif')); - $this->assertFalse(\Szurubooru\Helpers\MimeHelper::isImage('something else')); + $this->assertTrue(MimeHelper::isImage('IMAGE/JPEG')); + $this->assertTrue(MimeHelper::isImage('IMAGE/PNG')); + $this->assertTrue(MimeHelper::isImage('IMAGE/GIF')); + $this->assertTrue(MimeHelper::isImage('image/jpeg')); + $this->assertTrue(MimeHelper::isImage('image/png')); + $this->assertTrue(MimeHelper::isImage('image/gif')); + $this->assertFalse(MimeHelper::isImage('something else')); } public function testIsVideo() { - $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isVideo('VIDEO/MP4')); - $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isVideo('video/mp4')); - $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isVideo('APPLICATION/OGG')); - $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isVideo('application/ogg')); - $this->assertFalse(\Szurubooru\Helpers\MimeHelper::isVideo('something else')); + $this->assertTrue(MimeHelper::isVideo('VIDEO/MP4')); + $this->assertTrue(MimeHelper::isVideo('video/mp4')); + $this->assertTrue(MimeHelper::isVideo('APPLICATION/OGG')); + $this->assertTrue(MimeHelper::isVideo('application/ogg')); + $this->assertFalse(MimeHelper::isVideo('something else')); } } diff --git a/tests/Helpers/ProgramExecutorTest.php b/tests/Helpers/ProgramExecutorTest.php index bc94a868..6d2ce0b2 100644 --- a/tests/Helpers/ProgramExecutorTest.php +++ b/tests/Helpers/ProgramExecutorTest.php @@ -1,10 +1,12 @@ assertFalse(\Szurubooru\Helpers\ProgramExecutor::isProgramAvailable('there_is_no_way_my_os_can_have_this_program')); + $this->assertFalse(ProgramExecutor::isProgramAvailable('there_is_no_way_my_os_can_have_this_program')); } } diff --git a/tests/PrivilegeTest.php b/tests/PrivilegeTest.php index 04105b80..1ddec749 100644 --- a/tests/PrivilegeTest.php +++ b/tests/PrivilegeTest.php @@ -1,11 +1,15 @@ getConstants() as $key => $value) { $value = strtoupper(ltrim(preg_replace('/[A-Z]/', '_\0', $value), '_')); @@ -15,10 +19,10 @@ class PrivilegeTest extends \Szurubooru\Tests\AbstractTestCase public function testConfigSectionNaming() { - $refl = new \ReflectionClass(\Szurubooru\Privilege::class); + $refl = new \ReflectionClass(Privilege::class); $constants = array_values($refl->getConstants()); - $config = \Szurubooru\Injector::get(\Szurubooru\Config::class); + $config = Injector::get(Config::class); foreach ($config->security->privileges as $key => $value) { $this->assertTrue(in_array($key, $constants), "$key not in constants"); diff --git a/tests/RouterTest.php b/tests/RouterTest.php index 59401de6..fbef5edc 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -1,11 +1,14 @@ get('/test', function() use (&$testOk) { $testOk = true; }); $router->handle('GET', '/test'); @@ -14,7 +17,7 @@ final class PostDaoTest extends \Szurubooru\Tests\AbstractTestCase public function testTrailingSlashes() { - $router = new \Szurubooru\Router; + $router = new Router; $testOk = false; $router->get('/test', function() use (&$testOk) { $testOk = true; }); $router->handle('GET', '/test/'); @@ -23,7 +26,7 @@ final class PostDaoTest extends \Szurubooru\Tests\AbstractTestCase public function testUnhandledMethod() { - $router = new \Szurubooru\Router; + $router = new Router; $router->get('/test', function() { $this->fail('Route shouldn\'t be executed'); }); $this->setExpectedException(\DomainException::class); $router->handle('POST', '/test'); @@ -31,7 +34,7 @@ final class PostDaoTest extends \Szurubooru\Tests\AbstractTestCase public function testUnhandledQuery() { - $router = new \Szurubooru\Router; + $router = new Router; $router->get('/test', function() { $this->fail('Route shouldn\'t be executed'); }); $this->setExpectedException(\DomainException::class); $router->handle('GET', '/test2'); @@ -39,7 +42,7 @@ final class PostDaoTest extends \Szurubooru\Tests\AbstractTestCase public function testTwoMethodsHandling() { - $router = new \Szurubooru\Router; + $router = new Router; $testOk = false; $router->get('/test', function() { $this->fail('Route shouldn\'t be executed'); }); $router->post('/test', function() use (&$testOk) { $testOk = true; }); @@ -49,7 +52,7 @@ final class PostDaoTest extends \Szurubooru\Tests\AbstractTestCase public function testParameterHandling() { - $router = new \Szurubooru\Router; + $router = new Router; $testOk = false; $router->get('/tests/:id', function($id) use (&$testOk) { $this->assertEquals($id, 'test_id'); @@ -61,7 +64,7 @@ final class PostDaoTest extends \Szurubooru\Tests\AbstractTestCase public function testTwoParameterHandling() { - $router = new \Szurubooru\Router; + $router = new Router; $testOk = false; $router->get('/tests/:id/:page', function($id, $page) use (&$testOk) { $this->assertEquals($id, 'test_id'); @@ -74,7 +77,7 @@ final class PostDaoTest extends \Szurubooru\Tests\AbstractTestCase public function testMissingParameterHandling() { - $router = new \Szurubooru\Router; + $router = new Router; $testOk = false; $router->get('/tests/:id', function($id, $page) use (&$testOk) { $this->assertEquals($id, 'test_id'); @@ -87,7 +90,7 @@ final class PostDaoTest extends \Szurubooru\Tests\AbstractTestCase public function testMissingDefaultParameterHandling() { - $router = new \Szurubooru\Router; + $router = new Router; $testOk = false; $router->get('/tests/:id', function($id, $page = 1) use (&$testOk) { $this->assertEquals($id, 'test_id'); @@ -100,7 +103,7 @@ final class PostDaoTest extends \Szurubooru\Tests\AbstractTestCase public function testOutputHandling() { - $router = new \Szurubooru\Router; + $router = new Router; $router->get('/test', function() { return 'ok'; }); $output = $router->handle('GET', '/test'); $this->assertEquals('ok', $output); @@ -108,10 +111,10 @@ final class PostDaoTest extends \Szurubooru\Tests\AbstractTestCase public function testRoutingToClassMethods() { - $router = new \Szurubooru\Router; + $router = new Router; $testController = new TestController(); $router->get('/normal', [$testController, 'normalRoute']); - $router->get('/static', [\Szurubooru\Tests\TestController::class, 'staticRoute']); + $router->get('/static', [TestController::class, 'staticRoute']); $this->assertEquals('normal', $router->handle('GET', '/normal')); $this->assertEquals('static', $router->handle('GET', '/static')); } diff --git a/tests/SearchServices/UserSearchParserTest.php b/tests/SearchServices/UserSearchParserTest.php index e6b16bac..10b256f5 100644 --- a/tests/SearchServices/UserSearchParserTest.php +++ b/tests/SearchServices/UserSearchParserTest.php @@ -1,12 +1,11 @@ configMock = $this->mockConfig(); - $this->passwordServiceMock = $this->mock(\Szurubooru\Services\PasswordService::class); - $this->timeServiceMock = $this->mock(\Szurubooru\Services\TimeService::class); - $this->tokenServiceMock = $this->mock(\Szurubooru\Services\TokenService::class); - $this->userServiceMock = $this->mock(\Szurubooru\Services\UserService::class); + $this->passwordServiceMock = $this->mock(PasswordService::class); + $this->timeServiceMock = $this->mock(TimeService::class); + $this->tokenServiceMock = $this->mock(TokenService::class); + $this->userServiceMock = $this->mock(UserService::class); } public function testInvalidPassword() @@ -24,7 +33,7 @@ class AuthServiceTest extends \Szurubooru\Tests\AbstractTestCase $this->configMock->set('security/needEmailActivationToRegister', false); $this->passwordServiceMock->expects($this->once())->method('isHashValid')->with('godzilla', 'salt', 'hash')->willReturn(false); - $testUser = new \Szurubooru\Entities\User(); + $testUser = new User(); $testUser->setName('dummy'); $testUser->setPasswordHash('hash'); $testUser->setPasswordSalt('salt'); @@ -32,7 +41,7 @@ class AuthServiceTest extends \Szurubooru\Tests\AbstractTestCase $this->setExpectedException(\Exception::class, 'Specified password is invalid'); $authService = $this->getAuthService(); - $formData = new \Szurubooru\FormData\LoginFormData(); + $formData = new LoginFormData(); $formData->userNameOrEmail = 'dummy'; $formData->password = 'godzilla'; $authService->loginFromCredentials($formData); @@ -43,20 +52,20 @@ class AuthServiceTest extends \Szurubooru\Tests\AbstractTestCase $this->configMock->set('security/needEmailActivationToRegister', false); $this->passwordServiceMock->expects($this->once())->method('isHashValid')->with('godzilla', 'salt', 'hash')->willReturn(true); - $testUser = new \Szurubooru\Entities\User('an unusual database identifier'); + $testUser = new User('an unusual database identifier'); $testUser->setName('dummy'); $testUser->setPasswordHash('hash'); $testUser->setPasswordSalt('salt'); $this->userServiceMock->expects($this->once())->method('getByNameOrEmail')->willReturn($testUser); - $testToken = new \Szurubooru\Entities\Token(); + $testToken = new Token(); $testToken->setName('mummy'); $this->tokenServiceMock->expects($this->once())->method('createAndSaveToken')->with( $testUser->getId(), - \Szurubooru\Entities\Token::PURPOSE_LOGIN)->willReturn($testToken); + Token::PURPOSE_LOGIN)->willReturn($testToken); $authService = $this->getAuthService(); - $formData = new \Szurubooru\FormData\LoginFormData(); + $formData = new LoginFormData(); $formData->userNameOrEmail = 'dummy'; $formData->password = 'godzilla'; $authService->loginFromCredentials($formData); @@ -72,14 +81,14 @@ class AuthServiceTest extends \Szurubooru\Tests\AbstractTestCase $this->configMock->set('security/needEmailActivationToRegister', true); $this->passwordServiceMock->expects($this->never())->method('isHashValid')->willReturn('hash'); - $testUser = new \Szurubooru\Entities\User(); + $testUser = new User(); $testUser->setName('dummy'); $testUser->setPasswordHash('hash'); $this->userServiceMock->expects($this->once())->method('getByNameOrEmail')->willReturn($testUser); $this->setExpectedException(\Exception::class, 'User didn\'t confirm account yet'); $authService = $this->getAuthService(); - $formData = new \Szurubooru\FormData\LoginFormData(); + $formData = new LoginFormData(); $formData->userNameOrEmail = 'dummy'; $formData->password = 'godzilla'; $authService->loginFromCredentials($formData); @@ -95,21 +104,21 @@ class AuthServiceTest extends \Szurubooru\Tests\AbstractTestCase $this->setExpectedException(\Exception::class); $authService = $this->getAuthService(); - $testToken = new \Szurubooru\Entities\Token(); + $testToken = new Token(); $authService->loginFromToken($testToken); } public function testValidToken() { $this->configMock->set('security/needEmailActivationToRegister', false); - $testUser = new \Szurubooru\Entities\User(5); + $testUser = new User(5); $testUser->setName('dummy'); $this->userServiceMock->expects($this->once())->method('getById')->willReturn($testUser); - $testToken = new \Szurubooru\Entities\Token(); + $testToken = new Token(); $testToken->setName('dummy_token'); $testToken->setAdditionalData($testUser->getId()); - $testToken->setPurpose(\Szurubooru\Entities\Token::PURPOSE_LOGIN); + $testToken->setPurpose(Token::PURPOSE_LOGIN); $authService = $this->getAuthService(); $authService->loginFromToken($testToken); @@ -123,7 +132,7 @@ class AuthServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testValidTokenInvalidPurpose() { $this->configMock->set('security/needEmailActivationToRegister', false); - $testToken = new \Szurubooru\Entities\Token(); + $testToken = new Token(); $testToken->setName('dummy_token'); $testToken->setAdditionalData('whatever'); $testToken->setPurpose(null); @@ -140,14 +149,14 @@ class AuthServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testValidTokenUnconfirmedEmail() { $this->configMock->set('security/needEmailActivationToRegister', true); - $testUser = new \Szurubooru\Entities\User(5); + $testUser = new User(5); $testUser->setName('dummy'); $this->userServiceMock->expects($this->once())->method('getById')->willReturn($testUser); - $testToken = new \Szurubooru\Entities\Token(); + $testToken = new Token(); $testToken->setName('dummy_token'); $testToken->setAdditionalData($testUser->getId()); - $testToken->setPurpose(\Szurubooru\Entities\Token::PURPOSE_LOGIN); + $testToken->setPurpose(Token::PURPOSE_LOGIN); $this->setExpectedException(\Exception::class, 'User didn\'t confirm account yet'); $authService = $this->getAuthService(); @@ -160,7 +169,7 @@ class AuthServiceTest extends \Szurubooru\Tests\AbstractTestCase private function getAuthService() { - return new \Szurubooru\Services\AuthService( + return new AuthService( $this->configMock, $this->passwordServiceMock, $this->timeServiceMock, diff --git a/tests/Services/FavoritesServiceTest.php b/tests/Services/FavoritesServiceTest.php index 99d035e3..366055d2 100644 --- a/tests/Services/FavoritesServiceTest.php +++ b/tests/Services/FavoritesServiceTest.php @@ -1,7 +1,16 @@ favoritesDaoMock = $this->mock(\Szurubooru\Dao\FavoritesDao::class); - $this->scoreDaoMock = $this->mock(\Szurubooru\Dao\ScoreDao::class); - $this->userDaoMock = $this->mock(\Szurubooru\Dao\UserDao::class); + $this->favoritesDaoMock = $this->mock(FavoritesDao::class); + $this->scoreDaoMock = $this->mock(ScoreDao::class); + $this->userDaoMock = $this->mock(UserDao::class); $this->transactionManagerMock = $this->mockTransactionManager(); - $this->timeServiceMock = $this->mock(\Szurubooru\Services\TimeService::class); + $this->timeServiceMock = $this->mock(TimeService::class); } public function testAdding() { - $user = new \Szurubooru\Entities\User(1); - $post = new \Szurubooru\Entities\Post(2); - $fav = new \Szurubooru\Entities\Favorite(); + $user = new User(1); + $post = new Post(2); + $fav = new Favorite(); $fav->setUserId($user->getId()); $fav->setPostId($post->getId()); $this->favoritesDaoMock->expects($this->once())->method('set')->with($user, $post); @@ -34,9 +43,9 @@ final class FavoritesServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testDeleting() { - $user = new \Szurubooru\Entities\User(); - $post = new \Szurubooru\Entities\Post(); - $fav = new \Szurubooru\Entities\Favorite(3); + $user = new User(); + $post = new Post(); + $fav = new Favorite(3); $this->favoritesDaoMock->expects($this->once())->method('delete')->with($user, $post); $favoritesService = $this->getFavoritesService(); @@ -45,11 +54,11 @@ final class FavoritesServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testGettingByPost() { - $post = new \Szurubooru\Entities\Post(); - $fav1 = new \Szurubooru\Entities\Favorite(); - $fav2 = new \Szurubooru\Entities\Favorite(); - $fav1->setUser(new \Szurubooru\Entities\User(1)); - $fav2->setUser(new \Szurubooru\Entities\User(2)); + $post = new Post(); + $fav1 = new Favorite(); + $fav2 = new Favorite(); + $fav1->setUser(new User(1)); + $fav2->setUser(new User(2)); $this->favoritesDaoMock->expects($this->once())->method('findByEntity')->with($post)->willReturn([$fav1, $fav2]); $this->userDaoMock->expects($this->once())->method('findByIds')->with([1, 2]); @@ -60,7 +69,7 @@ final class FavoritesServiceTest extends \Szurubooru\Tests\AbstractTestCase private function getFavoritesService() { - return new \Szurubooru\Services\FavoritesService( + return new FavoritesService( $this->favoritesDaoMock, $this->scoreDaoMock, $this->userDaoMock, diff --git a/tests/Services/FileServiceTest.php b/tests/Services/FileServiceTest.php index 7248bda9..64d53727 100644 --- a/tests/Services/FileServiceTest.php +++ b/tests/Services/FileServiceTest.php @@ -1,14 +1,17 @@ createTestDirectory(); $configMock = $this->mockConfig(null, $testDirectory); - $httpHelper = $this->mock(\Szurubooru\Helpers\HttpHelper::class); - $fileService = new \Szurubooru\Services\FileService($configMock, $httpHelper); + $httpHelper = $this->mock(HttpHelper::class); + $fileService = new FileService($configMock, $httpHelper); $fileService->save('dog.txt', 'awesome dog'); $expected = 'awesome dog'; $actual = file_get_contents($testDirectory . DIRECTORY_SEPARATOR . 'dog.txt'); @@ -18,8 +21,8 @@ class FileServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testDownload() { $configMock = $this->mockConfig(); - $httpHelper = $this->mock(\Szurubooru\Helpers\HttpHelper::class); - $fileService = new \Szurubooru\Services\FileService($configMock, $httpHelper); + $httpHelper = $this->mock(HttpHelper::class); + $fileService = new FileService($configMock, $httpHelper); $content = $fileService->download('http://modernseoul.files.wordpress.com/2012/04/korean-alphabet-chart-modern-seoul.jpg'); $this->assertGreaterThan(0, strlen($content)); } diff --git a/tests/Services/HistoryServiceTest.php b/tests/Services/HistoryServiceTest.php index 7fe15341..77d02e15 100644 --- a/tests/Services/HistoryServiceTest.php +++ b/tests/Services/HistoryServiceTest.php @@ -1,7 +1,19 @@ validatorMock = $this->mock(\Szurubooru\Validator::class); - $this->snapshotDaoMock = $this->mock(\Szurubooru\Dao\SnapshotDao::class); - $this->globalParamDaoMock = $this->mock(\Szurubooru\Dao\GlobalParamDao::class); - $this->transactionManagerMock = $this->mock(\Szurubooru\Dao\TransactionManager::class); - $this->timeServiceMock = $this->mock(\Szurubooru\Services\TimeService::class); - $this->authServiceMock = $this->mock(\Szurubooru\Services\AuthService::class); + $this->validatorMock = $this->mock(Validator::class); + $this->snapshotDaoMock = $this->mock(SnapshotDao::class); + $this->globalParamDaoMock = $this->mock(GlobalParamDao::class); + $this->transactionManagerMock = $this->mock(TransactionManager::class); + $this->timeServiceMock = $this->mock(TimeService::class); + $this->authServiceMock = $this->mock(AuthService::class); } public function testPostChangeSnapshot() { - $tag1 = new \Szurubooru\Entities\Tag(); - $tag2 = new \Szurubooru\Entities\Tag(); + $tag1 = new Tag(); + $tag2 = new Tag(); $tag1->setName('tag1'); $tag2->setName('tag2'); - $post1 = new \Szurubooru\Entities\Post(1); - $post2 = new \Szurubooru\Entities\Post(2); + $post1 = new Post(1); + $post2 = new Post(2); - $post = new \Szurubooru\Entities\Post(5); + $post = new Post(5); $post->setTags([$tag1, $tag2]); $post->setRelatedPosts([$post1, $post2]); $post->setContentChecksum('checksum'); - $post->setSafety(\Szurubooru\Entities\Post::POST_SAFETY_SKETCHY); + $post->setSafety(Post::POST_SAFETY_SKETCHY); $post->setSource('amazing source'); $historyService = $this->getHistoryService(); @@ -136,7 +148,7 @@ class HistoryServiceTest extends \Szurubooru\Tests\AbstractTestCase 'relations' => [1, 2] ], $snapshot->getData()); - $this->assertEquals(\Szurubooru\Entities\Snapshot::TYPE_POST, $snapshot->getType()); + $this->assertEquals(Snapshot::TYPE_POST, $snapshot->getType()); $this->assertEquals(5, $snapshot->getPrimaryKey()); return $post; @@ -147,12 +159,12 @@ class HistoryServiceTest extends \Szurubooru\Tests\AbstractTestCase */ public function testPostChangeSnapshotFeature($post) { - $param = new \Szurubooru\Entities\GlobalParam; + $param = new GlobalParam; $param->setValue($post->getId()); $this->globalParamDaoMock ->expects($this->once()) ->method('findByKey') - ->with(\Szurubooru\Entities\GlobalParam::KEY_FEATURED_POST) + ->with(GlobalParam::KEY_FEATURED_POST) ->willReturn($param); $historyService = $this->getHistoryService(); @@ -172,7 +184,7 @@ class HistoryServiceTest extends \Szurubooru\Tests\AbstractTestCase private function getHistoryService() { - return new \Szurubooru\Services\HistoryService( + return new HistoryService( $this->validatorMock, $this->snapshotDaoMock, $this->globalParamDaoMock, diff --git a/tests/Services/ImageManipulatorTest.php b/tests/Services/ImageManipulatorTest.php index 5bbeb716..329fe434 100644 --- a/tests/Services/ImageManipulatorTest.php +++ b/tests/Services/ImageManipulatorTest.php @@ -1,7 +1,13 @@ loadFromBuffer($this->getTestFile('image.jpg')); - $jpegBuffer = $imageManipulator->saveToBuffer($image, \Szurubooru\Services\ImageManipulation\IImageManipulator::FORMAT_JPEG); - $pngBuffer = $imageManipulator->saveToBuffer($image, \Szurubooru\Services\ImageManipulation\IImageManipulator::FORMAT_PNG); - $this->assertEquals('image/jpeg', \Szurubooru\Helpers\MimeHelper::getMimeTypeFromBuffer($jpegBuffer)); - $this->assertEquals('image/png', \Szurubooru\Helpers\MimeHelper::getMimeTypeFromBuffer($pngBuffer)); + $jpegBuffer = $imageManipulator->saveToBuffer($image, IImageManipulator::FORMAT_JPEG); + $pngBuffer = $imageManipulator->saveToBuffer($image, IImageManipulator::FORMAT_PNG); + $this->assertEquals('image/jpeg', MimeHelper::getMimeTypeFromBuffer($jpegBuffer)); + $this->assertEquals('image/png', MimeHelper::getMimeTypeFromBuffer($pngBuffer)); } private static function getImagickImageManipulator() { if (extension_loaded('imagick')) - return new \Szurubooru\Services\ImageManipulation\ImagickImageManipulator(); + return new ImagickImageManipulator(); else return null; } @@ -125,7 +131,7 @@ class ImageManipulatorTest extends \Szurubooru\Tests\AbstractTestCase private static function getGdImageManipulator() { if (extension_loaded('gd')) - return new \Szurubooru\Services\ImageManipulation\GdImageManipulator(); + return new GdImageManipulator(); else return null; } @@ -134,7 +140,7 @@ class ImageManipulatorTest extends \Szurubooru\Tests\AbstractTestCase { if (extension_loaded('gd') and extension_loaded('imagick')) { - return new \Szurubooru\Services\ImageManipulation\ImageManipulator( + return new ImageManipulator( self::getImagickImageManipulator(), self::getGdImageManipulator()); } diff --git a/tests/Services/PasswordServiceTest.php b/tests/Services/PasswordServiceTest.php index 5923f21d..65d2f29d 100644 --- a/tests/Services/PasswordServiceTest.php +++ b/tests/Services/PasswordServiceTest.php @@ -1,7 +1,9 @@ configMock); + return new PasswordService($this->configMock); } } diff --git a/tests/Services/PostServiceTest.php b/tests/Services/PostServiceTest.php index 8c0881e8..dc6dff07 100644 --- a/tests/Services/PostServiceTest.php +++ b/tests/Services/PostServiceTest.php @@ -1,7 +1,23 @@ configMock = $this->mockConfig(); - $this->validatorMock = $this->mock(\Szurubooru\Validator::class); + $this->validatorMock = $this->mock(Validator::class); $this->transactionManagerMock = $this->mockTransactionManager(); - $this->postDaoMock = $this->mock(\Szurubooru\Dao\PostDao::class); - $this->globalParamDaoMock = $this->mock(\Szurubooru\Dao\GlobalParamDao::class); - $this->authServiceMock = $this->mock(\Szurubooru\Services\AuthService::class); - $this->timeServiceMock = $this->mock(\Szurubooru\Services\TimeService::class); - $this->fileServiceMock = $this->mock(\Szurubooru\Services\FileService::class); - $this->tagService = \Szurubooru\Injector::get(\Szurubooru\Services\TagService::class); - $this->historyServiceMock = $this->mock(\Szurubooru\Services\HistoryService::class); + $this->postDaoMock = $this->mock(PostDao::class); + $this->globalParamDaoMock = $this->mock(GlobalParamDao::class); + $this->authServiceMock = $this->mock(AuthService::class); + $this->timeServiceMock = $this->mock(TimeService::class); + $this->fileServiceMock = $this->mock(FileService::class); + $this->tagService = Injector::get(TagService::class); + $this->historyServiceMock = $this->mock(HistoryService::class); $this->configMock->set('database/maxPostSize', 1000000); - $this->imageManipulatorMock = $this->mock(\Szurubooru\Services\ImageManipulation\ImageManipulator::class); + $this->imageManipulatorMock = $this->mock(ImageManipulator::class); } public function testCreatingYoutubePost() { - $formData = new \Szurubooru\FormData\UploadFormData; - $formData->safety = \Szurubooru\Entities\Post::POST_SAFETY_SAFE; + $formData = new UploadFormData; + $formData->safety = Post::POST_SAFETY_SAFE; $formData->source = 'source'; $formData->tags = ['test', 'test2']; $formData->url = 'https://www.youtube.com/watch?v=QYK2c4OVG6s'; $this->postDaoMock->expects($this->once())->method('save')->will($this->returnArgument(0)); - $this->authServiceMock->expects($this->once())->method('getLoggedInUser')->willReturn(new \Szurubooru\Entities\User(5)); - $this->historyServiceMock->expects($this->once())->method('getPostChangeSnapshot')->willReturn(new \Szurubooru\Entities\Snapshot()); + $this->authServiceMock->expects($this->once())->method('getLoggedInUser')->willReturn(new User(5)); + $this->historyServiceMock->expects($this->once())->method('getPostChangeSnapshot')->willReturn(new Snapshot()); $this->postService = $this->getPostService(); $savedPost = $this->postService->createPost($formData); - $this->assertEquals(\Szurubooru\Entities\Post::POST_SAFETY_SAFE, $savedPost->getSafety()); + $this->assertEquals(Post::POST_SAFETY_SAFE, $savedPost->getSafety()); $this->assertEquals(5, $savedPost->getUserId()); - $this->assertEquals(\Szurubooru\Entities\Post::POST_TYPE_YOUTUBE, $savedPost->getContentType()); + $this->assertEquals(Post::POST_TYPE_YOUTUBE, $savedPost->getContentType()); $this->assertEquals('QYK2c4OVG6s', $savedPost->getContentChecksum()); $this->assertEquals('source', $savedPost->getSource()); $this->assertNull($savedPost->getImageWidth()); @@ -62,8 +78,8 @@ class PostServiceTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testCreatingPosts() { - $formData = new \Szurubooru\FormData\UploadFormData; - $formData->safety = \Szurubooru\Entities\Post::POST_SAFETY_SAFE; + $formData = new UploadFormData; + $formData->safety = Post::POST_SAFETY_SAFE; $formData->tags = ['test']; $formData->content = $this->getTestFile('image.jpg'); $formData->contentFileName = 'blah'; @@ -71,11 +87,11 @@ class PostServiceTest extends \Szurubooru\Tests\AbstractDatabaseTestCase $this->postDaoMock->expects($this->once())->method('save')->will($this->returnArgument(0)); $this->imageManipulatorMock->expects($this->once())->method('getImageWidth')->willReturn(640); $this->imageManipulatorMock->expects($this->once())->method('getImageHeight')->willReturn(480); - $this->historyServiceMock->expects($this->once())->method('getPostChangeSnapshot')->willReturn(new \Szurubooru\Entities\Snapshot()); + $this->historyServiceMock->expects($this->once())->method('getPostChangeSnapshot')->willReturn(new Snapshot()); $this->postService = $this->getPostService(); $savedPost = $this->postService->createPost($formData); - $this->assertEquals(\Szurubooru\Entities\Post::POST_TYPE_IMAGE, $savedPost->getContentType()); + $this->assertEquals(Post::POST_TYPE_IMAGE, $savedPost->getContentType()); $this->assertEquals('24216edd12328de3a3c55e2f98220ee7613e3be1', $savedPost->getContentChecksum()); $this->assertEquals($formData->contentFileName, $savedPost->getOriginalFileName()); $this->assertEquals(687645, $savedPost->getOriginalFileSize()); @@ -85,18 +101,18 @@ class PostServiceTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testCreatingVideos() { - $formData = new \Szurubooru\FormData\UploadFormData; - $formData->safety = \Szurubooru\Entities\Post::POST_SAFETY_SAFE; + $formData = new UploadFormData; + $formData->safety = Post::POST_SAFETY_SAFE; $formData->tags = ['test']; $formData->content = $this->getTestFile('video.mp4'); $formData->contentFileName = 'blah'; $this->postDaoMock->expects($this->once())->method('save')->will($this->returnArgument(0)); - $this->historyServiceMock->expects($this->once())->method('getPostChangeSnapshot')->willReturn(new \Szurubooru\Entities\Snapshot()); + $this->historyServiceMock->expects($this->once())->method('getPostChangeSnapshot')->willReturn(new Snapshot()); $this->postService = $this->getPostService(); $savedPost = $this->postService->createPost($formData); - $this->assertEquals(\Szurubooru\Entities\Post::POST_TYPE_VIDEO, $savedPost->getContentType()); + $this->assertEquals(Post::POST_TYPE_VIDEO, $savedPost->getContentType()); $this->assertEquals('16dafaa07cda194d03d590529c06c6ec1a5b80b0', $savedPost->getContentChecksum()); $this->assertEquals($formData->contentFileName, $savedPost->getOriginalFileName()); $this->assertEquals(14667, $savedPost->getOriginalFileSize()); @@ -104,18 +120,18 @@ class PostServiceTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testCreatingFlashes() { - $formData = new \Szurubooru\FormData\UploadFormData; - $formData->safety = \Szurubooru\Entities\Post::POST_SAFETY_SAFE; + $formData = new UploadFormData; + $formData->safety = Post::POST_SAFETY_SAFE; $formData->tags = ['test']; $formData->content = $this->getTestFile('flash.swf'); $formData->contentFileName = 'blah'; $this->postDaoMock->expects($this->once())->method('save')->will($this->returnArgument(0)); - $this->historyServiceMock->expects($this->once())->method('getPostChangeSnapshot')->willReturn(new \Szurubooru\Entities\Snapshot()); + $this->historyServiceMock->expects($this->once())->method('getPostChangeSnapshot')->willReturn(new Snapshot()); $this->postService = $this->getPostService(); $savedPost = $this->postService->createPost($formData); - $this->assertEquals(\Szurubooru\Entities\Post::POST_TYPE_FLASH, $savedPost->getContentType()); + $this->assertEquals(Post::POST_TYPE_FLASH, $savedPost->getContentType()); $this->assertEquals('d897e044b801d892291b440534c3be3739034f68', $savedPost->getContentChecksum()); $this->assertEquals($formData->contentFileName, $savedPost->getOriginalFileName()); $this->assertEquals(226172, $savedPost->getOriginalFileSize()); @@ -123,13 +139,13 @@ class PostServiceTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testFileDuplicates() { - $formData = new \Szurubooru\FormData\UploadFormData; - $formData->safety = \Szurubooru\Entities\Post::POST_SAFETY_SAFE; + $formData = new UploadFormData; + $formData->safety = Post::POST_SAFETY_SAFE; $formData->tags = ['test']; $formData->content = $this->getTestFile('flash.swf'); $formData->contentFileName = 'blah'; - $this->postDaoMock->expects($this->once())->method('findByContentChecksum')->willReturn(new \Szurubooru\Entities\Post(5)); + $this->postDaoMock->expects($this->once())->method('findByContentChecksum')->willReturn(new Post(5)); $this->setExpectedException(\Exception::class, 'Duplicate post: @5'); $this->postService = $this->getPostService(); @@ -138,12 +154,12 @@ class PostServiceTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testYoutubeDuplicates() { - $formData = new \Szurubooru\FormData\UploadFormData; - $formData->safety = \Szurubooru\Entities\Post::POST_SAFETY_SAFE; + $formData = new UploadFormData; + $formData->safety = Post::POST_SAFETY_SAFE; $formData->tags = ['test']; $formData->url = 'https://www.youtube.com/watch?v=QYK2c4OVG6s'; - $this->postDaoMock->expects($this->once())->method('findByContentChecksum')->with('QYK2c4OVG6s')->willReturn(new \Szurubooru\Entities\Post(5)); + $this->postDaoMock->expects($this->once())->method('findByContentChecksum')->with('QYK2c4OVG6s')->willReturn(new Post(5)); $this->setExpectedException(\Exception::class, 'Duplicate post: @5'); $this->postService = $this->getPostService(); @@ -152,8 +168,8 @@ class PostServiceTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testTooBigUpload() { - $formData = new \Szurubooru\FormData\UploadFormData; - $formData->safety = \Szurubooru\Entities\Post::POST_SAFETY_SAFE; + $formData = new UploadFormData; + $formData->safety = Post::POST_SAFETY_SAFE; $formData->tags = ['test']; $formData->content = 'aa'; @@ -166,15 +182,15 @@ class PostServiceTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testAnonymousUploads() { - $formData = new \Szurubooru\FormData\UploadFormData; - $formData->safety = \Szurubooru\Entities\Post::POST_SAFETY_SAFE; + $formData = new UploadFormData; + $formData->safety = Post::POST_SAFETY_SAFE; $formData->tags = ['test']; $formData->url = 'https://www.youtube.com/watch?v=QYK2c4OVG6s'; $formData->anonymous = true; $this->postDaoMock->expects($this->once())->method('save')->will($this->returnArgument(0)); $this->authServiceMock->expects($this->never())->method('getLoggedInUser'); - $this->historyServiceMock->expects($this->once())->method('getPostChangeSnapshot')->willReturn(new \Szurubooru\Entities\Snapshot()); + $this->historyServiceMock->expects($this->once())->method('getPostChangeSnapshot')->willReturn(new Snapshot()); $this->postService = $this->getPostService(); $savedPost = $this->postService->createPost($formData); @@ -183,7 +199,7 @@ class PostServiceTest extends \Szurubooru\Tests\AbstractDatabaseTestCase private function getPostService() { - return new \Szurubooru\Services\PostService( + return new PostService( $this->configMock, $this->validatorMock, $this->transactionManagerMock, diff --git a/tests/Services/PrivilegeServiceTest.php b/tests/Services/PrivilegeServiceTest.php index 39ef5482..1787f4bf 100644 --- a/tests/Services/PrivilegeServiceTest.php +++ b/tests/Services/PrivilegeServiceTest.php @@ -1,7 +1,12 @@ configMock = $this->mockConfig(); - $this->authServiceMock = $this->mock(\Szurubooru\Services\AuthService::class); + $this->authServiceMock = $this->mock(AuthService::class); } public function testReadingConfig() { - $testUser = new \Szurubooru\Entities\User(); + $testUser = new User(); $testUser->setName('dummy'); - $testUser->setAccessRank(\Szurubooru\Entities\User::ACCESS_RANK_POWER_USER); + $testUser->setAccessRank(User::ACCESS_RANK_POWER_USER); $this->authServiceMock->expects($this->atLeastOnce())->method('getLoggedInUser')->willReturn($testUser); - $privilege = \Szurubooru\Privilege::LIST_USERS; + $privilege = Privilege::LIST_USERS; $this->configMock->set('security/privileges/' . $privilege, 'powerUser'); $privilegeService = $this->getPrivilegeService(); @@ -30,9 +35,9 @@ class PrivilegeServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testIsLoggedInByNameString() { - $testUser1 = new \Szurubooru\Entities\User(); + $testUser1 = new User(); $testUser1->setName('dummy'); - $testUser2 = new \Szurubooru\Entities\User(); + $testUser2 = new User(); $testUser2->setName('godzilla'); $this->authServiceMock->expects($this->atLeastOnce())->method('getLoggedInUser')->willReturn($testUser1); @@ -43,10 +48,10 @@ class PrivilegeServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testIsLoggedInByEmailString() { - $testUser1 = new \Szurubooru\Entities\User(); + $testUser1 = new User(); $testUser1->setName('user1'); $testUser1->setEmail('dummy'); - $testUser2 = new \Szurubooru\Entities\User(); + $testUser2 = new User(); $testUser2->setName('user2'); $testUser2->setEmail('godzilla'); $this->authServiceMock->expects($this->atLeastOnce())->method('getLoggedInUser')->willReturn($testUser1); @@ -58,8 +63,8 @@ class PrivilegeServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testIsLoggedInByUserId() { - $testUser1 = new \Szurubooru\Entities\User(5); - $testUser2 = new \Szurubooru\Entities\User(13); + $testUser1 = new User(5); + $testUser2 = new User(13); $this->authServiceMock->expects($this->atLeastOnce())->method('getLoggedInUser')->willReturn($testUser1); $privilegeService = $this->getPrivilegeService(); @@ -69,9 +74,9 @@ class PrivilegeServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testIsLoggedInByUserName() { - $testUser1 = new \Szurubooru\Entities\User(); + $testUser1 = new User(); $testUser1->setName('dummy'); - $testUser2 = new \Szurubooru\Entities\User(); + $testUser2 = new User(); $testUser2->setName('godzilla'); $this->authServiceMock->expects($this->atLeastOnce())->method('getLoggedInUser')->willReturn($testUser1); @@ -82,7 +87,7 @@ class PrivilegeServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testIsLoggedInByInvalidObject() { - $testUser = new \Szurubooru\Entities\User(); + $testUser = new User(); $testUser->setName('dummy'); $this->authServiceMock->expects($this->atLeastOnce())->method('getLoggedInUser')->willReturn($testUser); @@ -94,7 +99,7 @@ class PrivilegeServiceTest extends \Szurubooru\Tests\AbstractTestCase private function getPrivilegeService() { - return new \Szurubooru\Services\PrivilegeService( + return new PrivilegeService( $this->configMock, $this->authServiceMock); } diff --git a/tests/Services/ScoreServiceTest.php b/tests/Services/ScoreServiceTest.php index 7626238b..273f7079 100644 --- a/tests/Services/ScoreServiceTest.php +++ b/tests/Services/ScoreServiceTest.php @@ -1,7 +1,16 @@ scoreDaoMock = $this->mock(\Szurubooru\Dao\ScoreDao::class); - $this->favoritesDaoMock = $this->mock(\Szurubooru\Dao\FavoritesDao::class); - $this->userDaoMock = $this->mock(\Szurubooru\Dao\UserDao::class); + $this->scoreDaoMock = $this->mock(ScoreDao::class); + $this->favoritesDaoMock = $this->mock(FavoritesDao::class); + $this->userDaoMock = $this->mock(UserDao::class); $this->transactionManagerMock = $this->mockTransactionManager(); - $this->timeServiceMock = $this->mock(\Szurubooru\Services\TimeService::class); + $this->timeServiceMock = $this->mock(TimeService::class); } public function testSetting() { - $user = new \Szurubooru\Entities\User(1); - $post = new \Szurubooru\Entities\Post(2); - $score = new \Szurubooru\Entities\Score(); + $user = new User(1); + $post = new Post(2); + $score = new Score(); $score->setUserId($user->getId()); $score->setPostId($post->getId()); $score->setScore(1); @@ -35,8 +44,8 @@ final class ScoreServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testSettingInvalid() { - $user = new \Szurubooru\Entities\User(1); - $post = new \Szurubooru\Entities\Post(2); + $user = new User(1); + $post = new Post(2); $this->setExpectedException(\Exception::class); $scoreService = $this->getScoreService(); $scoreService->setScore($user, $post, 2); @@ -44,9 +53,9 @@ final class ScoreServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testGetting() { - $user = new \Szurubooru\Entities\User(); - $post = new \Szurubooru\Entities\Post(); - $score = new \Szurubooru\Entities\Score(3); + $user = new User(); + $post = new Post(); + $score = new Score(3); $this->scoreDaoMock->expects($this->once())->method('getScore')->with($user, $post)->willReturn($score); $scoreService = $this->getScoreService(); @@ -56,7 +65,7 @@ final class ScoreServiceTest extends \Szurubooru\Tests\AbstractTestCase private function getScoreService() { - return new \Szurubooru\Services\ScoreService( + return new ScoreService( $this->scoreDaoMock, $this->favoritesDaoMock, $this->userDaoMock, diff --git a/tests/Services/TagServiceTest.php b/tests/Services/TagServiceTest.php index 9d82f2a4..44321c01 100644 --- a/tests/Services/TagServiceTest.php +++ b/tests/Services/TagServiceTest.php @@ -1,7 +1,12 @@ databaseConnection->getPDO(); - $tag = new \Szurubooru\Entities\Tag(); + $tag = new Tag(); $tag->setName('test'); $tagService = $this->getTagService(); @@ -30,9 +35,9 @@ class TagServiceTest extends \Szurubooru\Tests\AbstractDatabaseTestCase $pdo->exec('INSERT INTO tags(id, name, creationTime) VALUES (1, \'test1\', \'2014-10-01 00:00:00\')'); $pdo->exec('INSERT INTO tags(id, name, creationTime) VALUES (2, \'test2\', \'2014-10-01 00:00:00\')'); - $tag1 = new \Szurubooru\Entities\Tag(); + $tag1 = new Tag(); $tag1->setName('test1'); - $tag2 = new \Szurubooru\Entities\Tag(); + $tag2 = new Tag(); $tag2->setName('test2'); $tagService = $this->getTagService(); @@ -50,9 +55,9 @@ class TagServiceTest extends \Szurubooru\Tests\AbstractDatabaseTestCase $pdo->exec('INSERT INTO tags(id, name, creationTime) VALUES (1, \'test1\', \'2014-10-01 00:00:00\')'); $pdo->exec('INSERT INTO tags(id, name, creationTime) VALUES (2, \'test2\', \'2014-10-01 00:00:00\')'); - $tag1 = new \Szurubooru\Entities\Tag(); + $tag1 = new Tag(); $tag1->setName('test1'); - $tag2 = new \Szurubooru\Entities\Tag(); + $tag2 = new Tag(); $tag2->setName('test3'); $tagService = $this->getTagService(); @@ -66,7 +71,7 @@ class TagServiceTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testExportSingle() { - $tag1 = new \Szurubooru\Entities\Tag(); + $tag1 = new Tag(); $tag1->setName('test'); $tag1->setCreationTime(date('c')); $fileService = $this->getFileService(); @@ -78,10 +83,10 @@ class TagServiceTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testExportMultiple() { - $tag1 = new \Szurubooru\Entities\Tag(); + $tag1 = new Tag(); $tag1->setName('test1'); $tag1->setCreationTime(date('c')); - $tag2 = new \Szurubooru\Entities\Tag(); + $tag2 = new Tag(); $tag2->setName('test2'); $tag2->setCreationTime(date('c')); $fileService = $this->getFileService(); @@ -93,11 +98,11 @@ class TagServiceTest extends \Szurubooru\Tests\AbstractDatabaseTestCase private function getFileService() { - return \Szurubooru\Injector::get(\Szurubooru\Services\FileService::class); + return Injector::get(FileService::class); } private function getTagService() { - return \Szurubooru\Injector::get(\Szurubooru\Services\TagService::class); + return Injector::get(TagService::class); } } diff --git a/tests/Services/ThumbnailGeneratorTest.php b/tests/Services/ThumbnailGeneratorTest.php index aa6eed65..c530142a 100644 --- a/tests/Services/ThumbnailGeneratorTest.php +++ b/tests/Services/ThumbnailGeneratorTest.php @@ -1,12 +1,20 @@ markTestSkipped('External software necessary to run this test is missing.'); } @@ -18,7 +26,7 @@ class ThumbnailGeneratorTest extends \Szurubooru\Tests\AbstractTestCase $this->getTestFile('flash.swf'), 150, 150, - \Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator::CROP_OUTSIDE); + IThumbnailGenerator::CROP_OUTSIDE); $image = $imageManipulator->loadFromBuffer($result); $this->assertEquals(150, $imageManipulator->getImageWidth($image)); @@ -27,8 +35,8 @@ class ThumbnailGeneratorTest extends \Szurubooru\Tests\AbstractTestCase public function testVideoThumbnails() { - if (!\Szurubooru\Helpers\ProgramExecutor::isProgramAvailable(\Szurubooru\Services\ThumbnailGenerators\VideoThumbnailGenerator::PROGRAM_NAME_FFMPEG) - and !\Szurubooru\Helpers\ProgramExecutor::isProgramAvailable(\Szurubooru\Services\ThumbnailGenerators\VideoThumbnailGenerator::PROGRAM_NAME_FFMPEGTHUMBNAILER)) + if (!ProgramExecutor::isProgramAvailable(VideoThumbnailGenerator::PROGRAM_NAME_FFMPEG) + and !ProgramExecutor::isProgramAvailable(VideoThumbnailGenerator::PROGRAM_NAME_FFMPEGTHUMBNAILER)) { $this->markTestSkipped('External software necessary to run this test is missing.'); } @@ -40,7 +48,7 @@ class ThumbnailGeneratorTest extends \Szurubooru\Tests\AbstractTestCase $this->getTestFile('video.mp4'), 150, 150, - \Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator::CROP_OUTSIDE); + IThumbnailGenerator::CROP_OUTSIDE); $image = $imageManipulator->loadFromBuffer($result); $this->assertEquals(150, $imageManipulator->getImageWidth($image)); @@ -56,7 +64,7 @@ class ThumbnailGeneratorTest extends \Szurubooru\Tests\AbstractTestCase $this->getTestFile('image.jpg'), 150, 150, - \Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator::CROP_OUTSIDE); + IThumbnailGenerator::CROP_OUTSIDE); $image = $imageManipulator->loadFromBuffer($result); $this->assertEquals(150, $imageManipulator->getImageWidth($image)); @@ -66,7 +74,7 @@ class ThumbnailGeneratorTest extends \Szurubooru\Tests\AbstractTestCase $this->getTestFile('image.jpg'), 150, 150, - \Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator::CROP_INSIDE); + IThumbnailGenerator::CROP_INSIDE); $image = $imageManipulator->loadFromBuffer($result); $this->assertEquals(150, $imageManipulator->getImageWidth($image)); @@ -82,18 +90,18 @@ class ThumbnailGeneratorTest extends \Szurubooru\Tests\AbstractTestCase $this->getTestFile('text.txt'), 150, 150, - \Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator::CROP_OUTSIDE); + IThumbnailGenerator::CROP_OUTSIDE); $this->assertNull($result); } public function getImageManipulator() { - return \Szurubooru\Injector::get(\Szurubooru\Services\ImageManipulation\ImageManipulator::class); + return Injector::get(ImageManipulator::class); } public function getThumbnailGenerator() { - return \Szurubooru\Injector::get(\Szurubooru\Services\ThumbnailGenerators\SmartThumbnailGenerator::class); + return Injector::get(SmartThumbnailGenerator::class); } } diff --git a/tests/Services/ThumbnailServiceTest.php b/tests/Services/ThumbnailServiceTest.php index f5ee1dbf..9a1baced 100644 --- a/tests/Services/ThumbnailServiceTest.php +++ b/tests/Services/ThumbnailServiceTest.php @@ -1,7 +1,12 @@ configMock = $this->mockConfig(); - $this->fileServiceMock = $this->mock(\Szurubooru\Services\FileService::class); - $this->thumbnailServiceMock = $this->mock(\Szurubooru\Services\ThumbnailService::class); - $this->thumbnailGeneratorMock = $this->mock(\Szurubooru\Services\ThumbnailGenerators\SmartThumbnailGenerator::class); + $this->fileServiceMock = $this->mock(FileService::class); + $this->thumbnailServiceMock = $this->mock(ThumbnailService::class); + $this->thumbnailGeneratorMock = $this->mock(SmartThumbnailGenerator::class); } public function testGetUsedThumbnailSizes() @@ -76,7 +81,7 @@ class ThumbnailServiceTest extends \Szurubooru\Tests\AbstractTestCase 'content of blank thumbnail', 100, 100, - \Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator::CROP_OUTSIDE) + IThumbnailGenerator::CROP_OUTSIDE) ->willReturn('generated thumbnail'); $this->fileServiceMock @@ -112,7 +117,7 @@ class ThumbnailServiceTest extends \Szurubooru\Tests\AbstractTestCase 'content of blank thumbnail', 100, 100, - \Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator::CROP_OUTSIDE) + IThumbnailGenerator::CROP_OUTSIDE) ->willReturn(null); $this->fileServiceMock @@ -127,7 +132,7 @@ class ThumbnailServiceTest extends \Szurubooru\Tests\AbstractTestCase private function getThumbnailService() { - return new \Szurubooru\Services\ThumbnailService( + return new ThumbnailService( $this->configMock, $this->fileServiceMock, $this->thumbnailGeneratorMock); diff --git a/tests/Services/UserServiceTest.php b/tests/Services/UserServiceTest.php index 847db2b9..5e26b544 100644 --- a/tests/Services/UserServiceTest.php +++ b/tests/Services/UserServiceTest.php @@ -1,7 +1,21 @@ configMock = $this->mockConfig(); $this->transactionManagerMock = $this->mockTransactionManager(); - $this->validatorMock = $this->mock(\Szurubooru\Validator::class); - $this->userDaoMock = $this->mock(\Szurubooru\Dao\UserDao::class); - $this->passwordServiceMock = $this->mock(\Szurubooru\Services\PasswordService::class); - $this->emailServiceMock = $this->mock(\Szurubooru\Services\EmailService::class); - $this->fileServiceMock = $this->mock(\Szurubooru\Services\FileService::class); - $this->thumbnailServiceMock = $this->mock(\Szurubooru\Services\ThumbnailService::class); - $this->timeServiceMock = $this->mock(\Szurubooru\Services\TimeService::class); - $this->tokenServiceMock = $this->mock(\Szurubooru\Services\TokenService::class); + $this->validatorMock = $this->mock(Validator::class); + $this->userDaoMock = $this->mock(UserDao::class); + $this->passwordServiceMock = $this->mock(PasswordService::class); + $this->emailServiceMock = $this->mock(EmailService::class); + $this->fileServiceMock = $this->mock(FileService::class); + $this->thumbnailServiceMock = $this->mock(ThumbnailService::class); + $this->timeServiceMock = $this->mock(TimeService::class); + $this->tokenServiceMock = $this->mock(TokenService::class); } public function testGettingByName() { - $testUser = new \Szurubooru\Entities\User; + $testUser = new User; $testUser->setName('godzilla'); $this->userDaoMock->expects($this->once())->method('findByName')->willReturn($testUser); $userService = $this->getUserService(); @@ -49,7 +63,7 @@ final class UserServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testGettingById() { - $testUser = new \Szurubooru\Entities\User; + $testUser = new User; $testUser->setName('godzilla'); $this->userDaoMock->expects($this->once())->method('findById')->willReturn($testUser); $userService = $this->getUserService(); @@ -67,7 +81,7 @@ final class UserServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testValidRegistrationWithoutMailActivation() { - $formData = new \Szurubooru\FormData\RegistrationFormData; + $formData = new RegistrationFormData; $formData->userName = 'user'; $formData->password = 'password'; $formData->email = 'human@people.gov'; @@ -87,14 +101,14 @@ final class UserServiceTest extends \Szurubooru\Tests\AbstractTestCase $this->assertEquals('human@people.gov', $savedUser->getEmail()); $this->assertNull($savedUser->getEmailUnconfirmed()); $this->assertEquals('hash', $savedUser->getPasswordHash()); - $this->assertEquals(\Szurubooru\Entities\User::ACCESS_RANK_REGULAR_USER, $savedUser->getAccessRank()); + $this->assertEquals(User::ACCESS_RANK_REGULAR_USER, $savedUser->getAccessRank()); $this->assertEquals('now', $savedUser->getRegistrationTime()); $this->assertTrue($savedUser->isAccountConfirmed()); } public function testValidRegistrationWithMailActivation() { - $formData = new \Szurubooru\FormData\RegistrationFormData; + $formData = new RegistrationFormData; $formData->userName = 'user'; $formData->password = 'password'; $formData->email = 'human@people.gov'; @@ -106,7 +120,7 @@ final class UserServiceTest extends \Szurubooru\Tests\AbstractTestCase $this->userDaoMock->expects($this->once())->method('hasAnyUsers')->willReturn(true); $this->userDaoMock->expects($this->once())->method('save')->will($this->returnArgument(0)); - $testToken = new \Szurubooru\Entities\Token; + $testToken = new Token; $this->tokenServiceMock->expects($this->once())->method('createAndSaveToken')->willReturn($testToken); $this->emailServiceMock->expects($this->once())->method('sendActivationEmail')->with( $this->anything(), @@ -119,14 +133,14 @@ final class UserServiceTest extends \Szurubooru\Tests\AbstractTestCase $this->assertNull($savedUser->getEmail()); $this->assertEquals('human@people.gov', $savedUser->getEmailUnconfirmed()); $this->assertEquals('hash', $savedUser->getPasswordHash()); - $this->assertEquals(\Szurubooru\Entities\User::ACCESS_RANK_REGULAR_USER, $savedUser->getAccessRank()); + $this->assertEquals(User::ACCESS_RANK_REGULAR_USER, $savedUser->getAccessRank()); $this->assertEquals('now', $savedUser->getRegistrationTime()); $this->assertFalse($savedUser->isAccountConfirmed()); } public function testAccessRankOfFirstUser() { - $formData = new \Szurubooru\FormData\RegistrationFormData; + $formData = new RegistrationFormData; $formData->userName = 'user'; $formData->password = 'password'; $formData->email = 'email'; @@ -138,17 +152,17 @@ final class UserServiceTest extends \Szurubooru\Tests\AbstractTestCase $userService = $this->getUserService(); $savedUser = $userService->createUser($formData); - $this->assertEquals(\Szurubooru\Entities\User::ACCESS_RANK_ADMINISTRATOR, $savedUser->getAccessRank()); + $this->assertEquals(User::ACCESS_RANK_ADMINISTRATOR, $savedUser->getAccessRank()); } public function testRegistrationWhenUserExists() { - $formData = new \Szurubooru\FormData\RegistrationFormData; + $formData = new RegistrationFormData; $formData->userName = 'user'; $formData->password = 'password'; $formData->email = 'email'; - $otherUser = new \Szurubooru\Entities\User('yes, i exist in database'); + $otherUser = new User('yes, i exist in database'); $this->userDaoMock->expects($this->once())->method('hasAnyUsers')->willReturn(true); $this->userDaoMock->expects($this->once())->method('findByName')->willReturn($otherUser); @@ -162,10 +176,10 @@ final class UserServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testUpdatingName() { - $testUser = new \Szurubooru\Entities\User; + $testUser = new User; $testUser->setName('wojtek'); - $formData = new \Szurubooru\FormData\UserEditFormData; + $formData = new UserEditFormData; $formData->userName = 'sebastian'; $this->userDaoMock->expects($this->once())->method('save')->will($this->returnArgument(0)); @@ -177,13 +191,13 @@ final class UserServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testUpdatingNameToExisting() { - $testUser = new \Szurubooru\Entities\User; + $testUser = new User; $testUser->setName('wojtek'); - $formData = new \Szurubooru\FormData\UserEditFormData; + $formData = new UserEditFormData; $formData->userName = 'sebastian'; - $otherUser = new \Szurubooru\Entities\User('yes, i exist in database'); + $otherUser = new User('yes, i exist in database'); $this->userDaoMock->expects($this->once())->method('findByName')->willReturn($otherUser); $this->userDaoMock->expects($this->never())->method('save'); @@ -194,10 +208,10 @@ final class UserServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testUpdatingEmailWithoutConfirmation() { - $testUser = new \Szurubooru\Entities\User; + $testUser = new User; $this->configMock->set('security/needEmailActivationToRegister', false); - $formData = new \Szurubooru\FormData\UserEditFormData; + $formData = new UserEditFormData; $formData->email = 'hikari@geofront.gov'; $this->userDaoMock->expects($this->once())->method('save')->will($this->returnArgument(0)); @@ -211,13 +225,13 @@ final class UserServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testUpdatingEmailWithConfirmation() { - $testUser = new \Szurubooru\Entities\User; + $testUser = new User; $this->configMock->set('security/needEmailActivationToRegister', true); - $formData = new \Szurubooru\FormData\UserEditFormData; + $formData = new UserEditFormData; $formData->email = 'hikari@geofront.gov'; - $this->tokenServiceMock->expects($this->once())->method('createAndSaveToken')->willReturn(new \Szurubooru\Entities\Token()); + $this->tokenServiceMock->expects($this->once())->method('createAndSaveToken')->willReturn(new Token()); $this->userDaoMock->expects($this->once())->method('save')->will($this->returnArgument(0)); $userService = $this->getUserService(); @@ -229,13 +243,13 @@ final class UserServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testUpdatingEmailWithConfirmationToExisting() { - $testUser = new \Szurubooru\Entities\User; + $testUser = new User; $this->configMock->set('security/needEmailActivationToRegister', true); - $formData = new \Szurubooru\FormData\UserEditFormData; + $formData = new UserEditFormData; $formData->email = 'hikari@geofront.gov'; - $otherUser = new \Szurubooru\Entities\User('yes, i exist in database'); + $otherUser = new User('yes, i exist in database'); $this->tokenServiceMock->expects($this->never())->method('createAndSaveToken'); $this->userDaoMock->expects($this->once())->method('findByEmail')->willReturn($otherUser); $this->userDaoMock->expects($this->never())->method('save'); @@ -247,15 +261,15 @@ final class UserServiceTest extends \Szurubooru\Tests\AbstractTestCase public function testUpdatingEmailToAlreadyConfirmed() { - $testUser = new \Szurubooru\Entities\User('yep, still me'); + $testUser = new User('yep, still me'); $testUser->setEmail('hikari@geofront.gov'); $testUser->setAccountConfirmed(true); $testUser->setEmailUnconfirmed('coolcat32@sakura.ne.jp'); - $formData = new \Szurubooru\FormData\UserEditFormData; + $formData = new UserEditFormData; $formData->email = 'hikari@geofront.gov'; - $otherUser = new \Szurubooru\Entities\User('yep, still me'); + $otherUser = new User('yep, still me'); $this->tokenServiceMock->expects($this->never())->method('createAndSaveToken'); $this->userDaoMock->expects($this->never())->method('findByEmail'); $this->userDaoMock->expects($this->once())->method('save')->will($this->returnArgument(0)); @@ -269,7 +283,7 @@ final class UserServiceTest extends \Szurubooru\Tests\AbstractTestCase private function getUserService() { - return new \Szurubooru\Services\UserService( + return new UserService( $this->configMock, $this->validatorMock, $this->transactionManagerMock, diff --git a/tests/TransactionManagerMock.php b/tests/TransactionManagerMock.php index 8ee03175..35957b22 100644 --- a/tests/TransactionManagerMock.php +++ b/tests/TransactionManagerMock.php @@ -1,7 +1,8 @@