diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index ba755ebc..7e35caf4 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -3,19 +3,25 @@ namespace Szurubooru\Controllers; final class PostController extends AbstractController { + private $config; private $privilegeService; private $postService; + private $postSearchParser; private $inputReader; private $postViewProxy; public function __construct( + \Szurubooru\Config $config, \Szurubooru\Services\PrivilegeService $privilegeService, \Szurubooru\Services\PostService $postService, + \Szurubooru\SearchServices\Parsers\PostSearchParser $postSearchParser, \Szurubooru\Helpers\InputReader $inputReader, \Szurubooru\Controllers\ViewProxies\PostViewProxy $postViewProxy) { + $this->config = $config; $this->privilegeService = $privilegeService; $this->postService = $postService; + $this->postSearchParser = $postSearchParser; $this->inputReader = $inputReader; $this->postViewProxy = $postViewProxy; } @@ -46,13 +52,14 @@ final class PostController extends AbstractController public function getFiltered() { - $formData = new \Szurubooru\FormData\SearchFormData($this->inputReader); - $searchResult = $this->postService->getFiltered($formData); - $entities = $this->postViewProxy->fromArray($searchResult->getEntities(), $this->getLightFetchConfig()); + $filter = $this->postSearchParser->createFilterFromInputReader($this->inputReader); + $filter->setPageSize($this->config->posts->postsPerPage); + $result = $this->postService->getFiltered($filter); + $entities = $this->postViewProxy->fromArray($result->getEntities(), $this->getLightFetchConfig()); return [ 'data' => $entities, - 'pageSize' => $searchResult->getPageSize(), - 'totalRecords' => $searchResult->getTotalRecords()]; + 'pageSize' => $result->getPageSize(), + 'totalRecords' => $result->getTotalRecords()]; } public function createPost() diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index b65515c3..38e33bdc 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -3,22 +3,28 @@ namespace Szurubooru\Controllers; final class UserController extends AbstractController { + private $config; private $privilegeService; private $userService; private $tokenService; + private $userSearchParser; private $inputReader; private $userViewProxy; public function __construct( + \Szurubooru\Config $config, \Szurubooru\Services\PrivilegeService $privilegeService, \Szurubooru\Services\UserService $userService, \Szurubooru\Services\TokenService $tokenService, + \Szurubooru\SearchServices\Parsers\UserSearchParser $userSearchParser, \Szurubooru\Helpers\InputReader $inputReader, \Szurubooru\Controllers\ViewProxies\UserViewProxy $userViewProxy) { + $this->config = $config; $this->privilegeService = $privilegeService; $this->userService = $userService; $this->tokenService = $tokenService; + $this->userSearchParser = $userSearchParser; $this->inputReader = $inputReader; $this->userViewProxy = $userViewProxy; } @@ -46,13 +52,14 @@ final class UserController extends AbstractController { $this->privilegeService->assertPrivilege(\Szurubooru\Privilege::LIST_USERS); - $formData = new \Szurubooru\FormData\SearchFormData($this->inputReader); - $searchResult = $this->userService->getFiltered($formData); - $entities = $this->userViewProxy->fromArray($searchResult->getEntities()); + $filter = $this->userSearchParser->createFilterFromInputReader($this->inputReader); + $filter->setPageSize($this->config->users->usersPerPage); + $result = $this->userService->getFiltered($filter); + $entities = $this->userViewProxy->fromArray($result->getEntities()); return [ 'data' => $entities, - 'pageSize' => $searchResult->getPageSize(), - 'totalRecords' => $searchResult->getTotalRecords()]; + 'pageSize' => $result->getPageSize(), + 'totalRecords' => $result->getTotalRecords()]; } public function createUser() diff --git a/src/Dao/AbstractDao.php b/src/Dao/AbstractDao.php index 4355d9f8..4a7ae452 100644 --- a/src/Dao/AbstractDao.php +++ b/src/Dao/AbstractDao.php @@ -69,30 +69,33 @@ abstract class AbstractDao implements ICrudDao return $this->findBy($this->getIdColumn(), $entityIds); } - public function findFiltered(\Szurubooru\SearchServices\AbstractSearchFilter $searchFilter) + public function findFiltered(\Szurubooru\SearchServices\Filters\IFilter $searchFilter) { - $query = $this->prepareBaseQuery($searchFilter); - return $this->arrayToEntities(iterator_to_array($query)); - } + $query = $this->fpdo->from($this->tableName); - public function findFilteredAndPaged(\Szurubooru\SearchServices\AbstractSearchFilter $searchFilter, $pageNumber, $pageSize) - { - $query = $this->prepareBaseQuery($searchFilter); - $query->limit($pageSize); - $query->offset($pageSize * ($pageNumber - 1)); + $orderByString = self::compileOrderBy($searchFilter->getOrder()); + if ($orderByString) + $query->orderBy($orderByString); + + $this->decorateQueryFromFilter($query, $searchFilter); + if ($searchFilter->getPageSize() > 0) + { + $query->limit($searchFilter->getPageSize()); + $query->offset($searchFilter->getPageSize() * ($searchFilter->getPageNumber() - 1)); + } $entities = $this->arrayToEntities(iterator_to_array($query)); - $query = $this->prepareBaseQuery($searchFilter); - $query->orderBy(null); + $query = $this->fpdo->from($this->tableName); + $this->decorateQueryFromFilter($query, $searchFilter); $totalRecords = count($query); - $pagedSearchResult = new \Szurubooru\SearchServices\PagedSearchResult(); - $pagedSearchResult->setSearchFilter($searchFilter); - $pagedSearchResult->setEntities($entities); - $pagedSearchResult->setTotalRecords($totalRecords); - $pagedSearchResult->setPageNumber($pageNumber); - $pagedSearchResult->setPageSize($pageSize); - return $pagedSearchResult; + $searchResult = new \Szurubooru\SearchServices\Result(); + $searchResult->setSearchFilter($searchFilter); + $searchResult->setEntities($entities); + $searchResult->setTotalRecords($totalRecords); + $searchResult->setPageNumber($searchFilter->getPageNumber()); + $searchResult->setPageSize($searchFilter->getPageSize()); + return $searchResult; } public function deleteAll() @@ -175,10 +178,6 @@ abstract class AbstractDao implements ICrudDao { } - protected function decorateQueryFromFilter($query, \Szurubooru\SearchServices\AbstractSearchFilter $filter) - { - } - protected function arrayToEntities(array $arrayEntities) { $entities = []; @@ -190,23 +189,22 @@ abstract class AbstractDao implements ICrudDao return $entities; } - private function prepareBaseQuery(\Szurubooru\SearchServices\AbstractSearchFilter $searchFilter) + private function decorateQueryFromFilter($query, \Szurubooru\SearchServices\Filters\IFilter $filter) { - $query = $this->fpdo->from($this->tableName); - - $orderByString = self::compileOrderBy($searchFilter->getOrder()); - if ($orderByString) - $query->orderBy($orderByString); - - $this->decorateQueryFromFilter($query, $searchFilter); - return $query; + foreach ($filter->getRequirements() as $requirement) + { + if ($requirement->isNegated()) + $query->where('NOT ' . $requirement->getType(), $requirement->getValue()); + else + $query->where($requirement->getType(), $requirement->getValue()); + } } private static function compileOrderBy($order) { $orderByString = ''; foreach ($order as $orderColumn => $orderDir) - $orderByString .= $orderColumn . ' ' . ($orderDir === \Szurubooru\SearchServices\AbstractSearchFilter::ORDER_DESC ? 'DESC' : 'ASC') . ', '; + $orderByString .= $orderColumn . ' ' . ($orderDir === \Szurubooru\SearchServices\Filters\IFilter::ORDER_DESC ? 'DESC' : 'ASC') . ', '; return substr($orderByString, 0, -2); } } diff --git a/src/Dao/UserDao.php b/src/Dao/UserDao.php index 630fb863..b2e494fb 100644 --- a/src/Dao/UserDao.php +++ b/src/Dao/UserDao.php @@ -3,6 +3,9 @@ namespace Szurubooru\Dao; class UserDao extends AbstractDao implements ICrudDao { + const ORDER_NAME = 'name'; + const ORDER_REGISTRATION_TIME = 'registrationTime'; + private $fileService; private $thumbnailService; diff --git a/src/FormData/SearchFormData.php b/src/FormData/SearchFormData.php deleted file mode 100644 index 53eaf253..00000000 --- a/src/FormData/SearchFormData.php +++ /dev/null @@ -1,24 +0,0 @@ -query = trim($inputReader->query); - $this->order = trim($inputReader->order); - $this->pageNumber = intval($inputReader->page); - } - } - - public function validate(\Szurubooru\Validator $validator = null) - { - $validator->validateNumber($this->pageNumber); - } -} diff --git a/src/SearchServices/AbstractSearchFilter.php b/src/SearchServices/AbstractSearchFilter.php deleted file mode 100644 index 01c895fd..00000000 --- a/src/SearchServices/AbstractSearchFilter.php +++ /dev/null @@ -1,25 +0,0 @@ -order; - } - - public function setOrder($order) - { - $this->order = $order; - } - - public function __construct() - { - $this->setOrder(['id' => self::ORDER_DESC]); - } -} diff --git a/src/SearchServices/Filters/BasicFilter.php b/src/SearchServices/Filters/BasicFilter.php new file mode 100644 index 00000000..7b4ec432 --- /dev/null +++ b/src/SearchServices/Filters/BasicFilter.php @@ -0,0 +1,55 @@ +setOrder(['id' => self::ORDER_DESC]); + } + + public function getOrder() + { + return $this->order; + } + + public function setOrder($order) + { + $this->order = $order; + } + + public function addRequirement(\Szurubooru\SearchServices\Requirement $requirement) + { + $this->requirements[] = $requirement; + } + + public function getRequirements() + { + return $this->requirements; + } + + public function getPageSize() + { + return $this->pageSize; + } + + public function setPageSize($pageSize) + { + $this->pageSize = $pageSize; + } + + public function getPageNumber() + { + return $this->pageNumber; + } + + public function setPageNumber($pageNumber) + { + $this->pageNumber = $pageNumber; + } +} diff --git a/src/SearchServices/Filters/IFilter.php b/src/SearchServices/Filters/IFilter.php new file mode 100644 index 00000000..a8eccb8c --- /dev/null +++ b/src/SearchServices/Filters/IFilter.php @@ -0,0 +1,24 @@ +createFilter(); - $filter->setOrder(array_merge($this->getOrder($formData->order), $filter->getOrder())); + $filter->setOrder(array_merge($this->getOrder($inputReader->order), $filter->getOrder())); - $tokens = $this->tokenize($formData->query); + if ($inputReader->page) + { + $filter->setPageNumber($inputReader->page); + $filter->setPageSize(25); + } + + $tokens = $this->tokenize($inputReader->query); foreach ($tokens as $token) { if ($token instanceof \Szurubooru\SearchServices\NamedSearchToken) $this->decorateFilterFromNamedToken($filter, $token); - elseif ($token instanceof \Szurubooru\SearchService\SearchToken) + elseif ($token instanceof \Szurubooru\SearchServices\SearchToken) $this->decorateFilterFromToken($filter, $token); else - throw new \RuntimeException('Invalid search token type'); + throw new \RuntimeException('Invalid search token type: ' . get_class($token)); } return $filter; @@ -34,15 +40,15 @@ abstract class AbstractSearchParser private function getOrder($query) { $order = []; - $tokens = array_filter(preg_split('/\s+/', $query)); + $tokens = array_filter(preg_split('/\s+/', trim($query))); foreach ($tokens as $token) { $token = preg_split('/,|\s+/', $token); $orderToken = $token[0]; $orderDir = (count($token) === 2 and $token[1] === 'desc') - ? \Szurubooru\SearchServices\AbstractSearchFilter::ORDER_DESC - : \Szurubooru\SearchServices\AbstractSearchFilter::ORDER_ASC; + ? \Szurubooru\SearchServices\Filters\IFilter::ORDER_DESC + : \Szurubooru\SearchServices\Filters\IFilter::ORDER_ASC; $orderColumn = $this->getOrderColumn($orderToken); if ($orderColumn === null) @@ -58,7 +64,7 @@ abstract class AbstractSearchParser { $searchTokens = []; - foreach (array_filter(preg_split('/\s+/', $query)) as $tokenText) + foreach (array_filter(preg_split('/\s+/', trim($query))) as $tokenText) { $negated = false; if (substr($tokenText, 0, 1) === '-') diff --git a/src/SearchServices/Parsers/PostSearchParser.php b/src/SearchServices/Parsers/PostSearchParser.php index bae243cb..23dc6a22 100644 --- a/src/SearchServices/Parsers/PostSearchParser.php +++ b/src/SearchServices/Parsers/PostSearchParser.php @@ -5,7 +5,7 @@ class PostSearchParser extends AbstractSearchParser { protected function createFilter() { - return new \Szurubooru\SearchServices\PostSearchFilter; + return new \Szurubooru\SearchServices\Filters\PostFilter; } protected function decorateFilterFromToken($filter, $token) diff --git a/src/SearchServices/Parsers/UserSearchParser.php b/src/SearchServices/Parsers/UserSearchParser.php index b2cbe1b0..e42d7e14 100644 --- a/src/SearchServices/Parsers/UserSearchParser.php +++ b/src/SearchServices/Parsers/UserSearchParser.php @@ -5,7 +5,7 @@ class UserSearchParser extends AbstractSearchParser { protected function createFilter() { - return new \Szurubooru\SearchServices\UserSearchFilter; + return new \Szurubooru\SearchServices\Filters\UserFilter; } protected function decorateFilterFromToken($filter, $token) @@ -21,10 +21,10 @@ class UserSearchParser extends AbstractSearchParser protected function getOrderColumn($token) { if ($token === 'name') - return \Szurubooru\SearchServices\UserSearchFilter::ORDER_NAME; + return \Szurubooru\SearchServices\Filters\UserFilter::ORDER_NAME; if (in_array($token, ['registrationDate', 'registrationTime', 'registered', 'joinDate', 'joinTime', 'joined'])) - return \Szurubooru\SearchServices\UserSearchFilter::ORDER_REGISTRATION_TIME; + return \Szurubooru\SearchServices\Filters\UserFilter::ORDER_REGISTRATION_TIME; return null; } diff --git a/src/SearchServices/PostSearchFilter.php b/src/SearchServices/PostSearchFilter.php deleted file mode 100644 index 28e2304d..00000000 --- a/src/SearchServices/PostSearchFilter.php +++ /dev/null @@ -1,6 +0,0 @@ -negated; + } + + public function setNegated($negated) + { + $this->negated = $negated; + } + + public function getType() + { + return $this->type; + } + + public function setType($type) + { + $this->type = $type; + } + + public function getValue() + { + return $this->value; + } + + public function setValue($value) + { + $this->value = $value; + } +} diff --git a/src/SearchServices/PagedSearchResult.php b/src/SearchServices/Result.php similarity index 89% rename from src/SearchServices/PagedSearchResult.php rename to src/SearchServices/Result.php index 3265143a..6a9e6459 100644 --- a/src/SearchServices/PagedSearchResult.php +++ b/src/SearchServices/Result.php @@ -1,7 +1,7 @@ searchFilter = $searchFilter; } diff --git a/src/SearchServices/UserSearchFilter.php b/src/SearchServices/UserSearchFilter.php deleted file mode 100644 index af50755b..00000000 --- a/src/SearchServices/UserSearchFilter.php +++ /dev/null @@ -1,8 +0,0 @@ -transactionManager = $transactionManager; $this->postDao = $postDao; $this->globalParamDao = $globalParamDao; - $this->postSearchParser = $postSearchParser; $this->timeService = $timeService; $this->authService = $authService; $this->fileService = $fileService; @@ -64,13 +61,11 @@ class PostService return $this->transactionManager->rollback($transactionFunc); } - public function getFiltered(\Szurubooru\FormData\SearchFormData $formData) + public function getFiltered(\Szurubooru\SearchServices\Filters\PostFilter $filter) { - $transactionFunc = function() use ($formData) + $transactionFunc = function() use ($filter) { - $this->validator->validate($formData); - $searchFilter = $this->postSearchParser->createFilterFromFormData($formData); - return $this->postDao->findFilteredAndPaged($searchFilter, $formData->pageNumber, $this->config->posts->postsPerPage); + return $this->postDao->findFiltered($filter); }; return $this->transactionManager->rollback($transactionFunc); } diff --git a/src/Services/UserService.php b/src/Services/UserService.php index 3efe412e..34ad0fe5 100644 --- a/src/Services/UserService.php +++ b/src/Services/UserService.php @@ -7,7 +7,6 @@ class UserService private $validator; private $transactionManager; private $userDao; - private $userSearchParser; private $passwordService; private $emailService; private $fileService; @@ -20,7 +19,6 @@ class UserService \Szurubooru\Validator $validator, \Szurubooru\Dao\TransactionManager $transactionManager, \Szurubooru\Dao\UserDao $userDao, - \Szurubooru\SearchServices\Parsers\UserSearchParser $userSearchParser, \Szurubooru\Services\PasswordService $passwordService, \Szurubooru\Services\EmailService $emailService, \Szurubooru\Services\FileService $fileService, @@ -32,7 +30,6 @@ class UserService $this->validator = $validator; $this->transactionManager = $transactionManager; $this->userDao = $userDao; - $this->userSearchParser = $userSearchParser; $this->passwordService = $passwordService; $this->emailService = $emailService; $this->fileService = $fileService; @@ -82,13 +79,11 @@ class UserService return $this->transactionManager->rollback($transactionFunc); } - public function getFiltered(\Szurubooru\FormData\SearchFormData $formData) + public function getFiltered(\Szurubooru\SearchServices\Filters\UserFilter $filter) { - $transactionFunc = function() use ($formData) + $transactionFunc = function() use ($filter) { - $this->validator->validate($formData); - $searchFilter = $this->userSearchParser->createFilterFromFormData($formData); - return $this->userDao->findFilteredAndPaged($searchFilter, $formData->pageNumber, $this->config->users->usersPerPage); + return $this->userDao->findFiltered($filter); }; return $this->transactionManager->rollback($transactionFunc); } diff --git a/tests/Dao/UserDaoFilterTest.php b/tests/Dao/UserDaoFilterTest.php index f0846b27..3d703398 100644 --- a/tests/Dao/UserDaoFilterTest.php +++ b/tests/Dao/UserDaoFilterTest.php @@ -27,9 +27,11 @@ class UserDaoFilterTest extends \Szurubooru\Tests\AbstractDatabaseTestCase public function testNothing() { - $searchFilter = new \Szurubooru\SearchServices\UserSearchFilter(); + $searchFilter = new \Szurubooru\SearchServices\Filters\UserFilter(); + $searchFilter->setPageNumber(1); + $searchFilter->setPageSize(2); $userDao = $this->getUserDao(); - $result = $userDao->findFilteredAndPaged($searchFilter, 1, 2); + $result = $userDao->findFiltered($searchFilter); $this->assertEmpty($result->getEntities()); $this->assertEquals(0, $result->getTotalRecords()); $this->assertEquals(1, $result->getPageNumber()); @@ -51,12 +53,14 @@ class UserDaoFilterTest extends \Szurubooru\Tests\AbstractDatabaseTestCase $expectedUsers[] = $user; } - $searchFilter = new \Szurubooru\SearchServices\UserSearchFilter(); + $searchFilter = new \Szurubooru\SearchServices\Filters\UserFilter(); $searchFilter->setOrder([ - \Szurubooru\SearchServices\UserSearchFilter::ORDER_NAME => - \Szurubooru\SearchServices\UserSearchFilter::ORDER_DESC]); + \Szurubooru\SearchServices\Filters\UserFilter::ORDER_NAME => + \Szurubooru\SearchServices\Filters\UserFilter::ORDER_DESC]); + $searchFilter->setPageNumber($pageNumber); + $searchFilter->setPageSize($pageSize); - $result = $userDao->findFilteredAndPaged($searchFilter, $pageNumber, $pageSize); + $result = $userDao->findFiltered($searchFilter); $this->assertEquals(count($allUserNames), $result->getTotalRecords()); $this->assertEquals($pageNumber, $result->getPageNumber()); $this->assertEquals($pageSize, $result->getPageSize()); @@ -73,8 +77,8 @@ class UserDaoFilterTest extends \Szurubooru\Tests\AbstractDatabaseTestCase { list ($user1, $user2) = $this->prepareUsers(); $this->doTestSorting( - \Szurubooru\SearchServices\UserSearchFilter::ORDER_NAME, - \Szurubooru\SearchServices\UserSearchFilter::ORDER_ASC, + \Szurubooru\SearchServices\Filters\UserFilter::ORDER_NAME, + \Szurubooru\SearchServices\Filters\UserFilter::ORDER_ASC, [$user1, $user2]); } @@ -82,8 +86,8 @@ class UserDaoFilterTest extends \Szurubooru\Tests\AbstractDatabaseTestCase { list ($user1, $user2) = $this->prepareUsers(); $this->doTestSorting( - \Szurubooru\SearchServices\UserSearchFilter::ORDER_NAME, - \Szurubooru\SearchServices\UserSearchFilter::ORDER_DESC, + \Szurubooru\SearchServices\Filters\UserFilter::ORDER_NAME, + \Szurubooru\SearchServices\Filters\UserFilter::ORDER_DESC, [$user2, $user1]); } @@ -91,8 +95,8 @@ class UserDaoFilterTest extends \Szurubooru\Tests\AbstractDatabaseTestCase { list ($user1, $user2) = $this->prepareUsers(); $this->doTestSorting( - \Szurubooru\SearchServices\UserSearchFilter::ORDER_REGISTRATION_TIME, - \Szurubooru\SearchServices\UserSearchFilter::ORDER_ASC, + \Szurubooru\SearchServices\Filters\UserFilter::ORDER_REGISTRATION_TIME, + \Szurubooru\SearchServices\Filters\UserFilter::ORDER_ASC, [$user2, $user1]); } @@ -100,8 +104,8 @@ class UserDaoFilterTest extends \Szurubooru\Tests\AbstractDatabaseTestCase { list ($user1, $user2) = $this->prepareUsers(); $this->doTestSorting( - \Szurubooru\SearchServices\UserSearchFilter::ORDER_REGISTRATION_TIME, - \Szurubooru\SearchServices\UserSearchFilter::ORDER_DESC, + \Szurubooru\SearchServices\Filters\UserFilter::ORDER_REGISTRATION_TIME, + \Szurubooru\SearchServices\Filters\UserFilter::ORDER_DESC, [$user1, $user2]); } @@ -121,16 +125,17 @@ class UserDaoFilterTest extends \Szurubooru\Tests\AbstractDatabaseTestCase private function doTestSorting($order, $orderDirection, $expectedUsers) { $userDao = $this->getUserDao(); - $searchFilter = new \Szurubooru\SearchServices\UserSearchFilter(); + $searchFilter = new \Szurubooru\SearchServices\Filters\UserFilter(); if ($order !== null) $searchFilter->setOrder([$order => $orderDirection]); - $result = $userDao->findFilteredAndPaged($searchFilter, 1, 10); - $this->assertInstanceOf(\Szurubooru\SearchServices\PagedSearchResult::class, $result); + $result = $userDao->findFiltered($searchFilter, 1, 10); + $this->assertInstanceOf(\Szurubooru\SearchServices\Result::class, $result); $this->assertEquals($searchFilter, $result->getSearchFilter()); $this->assertEntitiesEqual(array_values($expectedUsers), array_values($result->getEntities())); $this->assertEquals(count($expectedUsers), $result->getTotalRecords()); - $this->assertEquals(1, $result->getPageNumber()); + $this->assertNull($result->getPageNumber()); + $this->assertNull($result->getPageSize()); } private function getUserDao() diff --git a/tests/Services/PostServiceTest.php b/tests/Services/PostServiceTest.php index 827ec3fe..2251b1c7 100644 --- a/tests/Services/PostServiceTest.php +++ b/tests/Services/PostServiceTest.php @@ -8,7 +8,6 @@ class PostServiceTest extends \Szurubooru\Tests\AbstractTestCase private $transactionManagerMock; private $postDaoMock; private $globalParamDaoMock; - private $postSearchParserMock; private $authServiceMock; private $timeServiceMock; private $fileServiceMock; @@ -21,7 +20,6 @@ class PostServiceTest extends \Szurubooru\Tests\AbstractTestCase $this->transactionManagerMock = $this->mockTransactionManager(); $this->postDaoMock = $this->mock(\Szurubooru\Dao\PostDao::class); $this->globalParamDaoMock = $this->mock(\Szurubooru\Dao\GlobalParamDao::class); - $this->postSearchParserMock = $this->mock(\Szurubooru\SearchServices\Parsers\PostSearchParser::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); @@ -181,7 +179,6 @@ class PostServiceTest extends \Szurubooru\Tests\AbstractTestCase $this->transactionManagerMock, $this->postDaoMock, $this->globalParamDaoMock, - $this->postSearchParserMock, $this->authServiceMock, $this->timeServiceMock, $this->fileServiceMock, diff --git a/tests/Services/UserServiceTest.php b/tests/Services/UserServiceTest.php index 425dc144..4fbb26b0 100644 --- a/tests/Services/UserServiceTest.php +++ b/tests/Services/UserServiceTest.php @@ -7,7 +7,6 @@ final class UserServiceTest extends \Szurubooru\Tests\AbstractTestCase private $validatorMock; private $transactionManagerMock; private $userDaoMock; - private $userSearchParserMock; private $passwordServiceMock; private $emailServiceMock; private $fileServiceMock; @@ -22,7 +21,6 @@ final class UserServiceTest extends \Szurubooru\Tests\AbstractTestCase $this->transactionManagerMock = $this->mockTransactionManager(); $this->validatorMock = $this->mock(\Szurubooru\Validator::class); $this->userDaoMock = $this->mock(\Szurubooru\Dao\UserDao::class); - $this->userSearchParserMock = $this->mock(\Szurubooru\SearchServices\Parsers\UserSearchParser::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); @@ -67,25 +65,6 @@ final class UserServiceTest extends \Szurubooru\Tests\AbstractTestCase $userService->getById('godzilla'); } - public function testGettingFilteredUsers() - { - $mockUser = new \Szurubooru\Entities\User; - $mockUser->setName('user'); - $expected = [$mockUser]; - $this->userSearchParserMock->method('createFilterFromFormData')->willReturn(new \Szurubooru\SearchServices\UserSearchFilter()); - $this->userDaoMock->method('findFilteredAndPaged')->willReturn($expected); - - $this->configMock->set('users/usersPerPage', 1); - $searchFormData = new \Szurubooru\FormData\SearchFormData; - $searchFormData->query = ''; - $searchFormData->order = 'joined'; - $searchFormData->page = 2; - - $userService = $this->getUserService(); - $actual = $userService->getFiltered($searchFormData); - $this->assertEquals($expected, $actual); - } - public function testValidRegistrationWithoutMailActivation() { $formData = new \Szurubooru\FormData\RegistrationFormData; @@ -293,7 +272,6 @@ final class UserServiceTest extends \Szurubooru\Tests\AbstractTestCase $this->validatorMock, $this->transactionManagerMock, $this->userDaoMock, - $this->userSearchParserMock, $this->passwordServiceMock, $this->emailServiceMock, $this->fileServiceMock,