diff --git a/README.md b/README.md index 0cfae9f5..fa9dd682 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,39 @@ DocuWare REST API. It is used to query the most common endpoints. [DocuWare REST API](https://developer.docuware.com/rest/index.html). See the documentation if you need further functionality. ⚠️ +## Table of Contents + + + * [Table of Contents](#table-of-contents) + * [💡 What is DocuWare?](#-what-is-docuware) + * [🛠 Requirements](#-requirements) + * [SOmething else](#something-else) + * [> = v4.0 (alpha)](#---v40-alpha) + * [> = v3.0](#---v30) + * [> = v2.0](#---v20) + * [> = v1.2](#---v12) + * [< v1.2](#-v12) + * [⚙️ Installation](#-installation) + * [🏗 Usage](#-usage) + * [Pagination](#pagination) + * [🔍 Search usage](#-search-usage) + * [🖼 Make encrypted URL](#-make-encrypted-url) + * [🏋️ Document Index Fields DTO showcase](#-document-index-fields-dto-showcase) + * [🏋️ DTO showcase](#-dto-showcase) + * [🔐 Authentication](#-authentication) + * [Manual authentication](#manual-authentication) + * [📦 Caching requests](#-caching-requests) + * [💥 Exceptions explained](#-exceptions-explained) + * [✨ Events](#-events) + * [🔧 Configuration file](#-configuration-file) + * [🚧 Testing](#-testing) + * [📝 Changelog](#-changelog) + * [✏️ Contributing](#-contributing) + * [🧑‍💻 Security Vulnerabilities](#-security-vulnerabilities) + * [🙏 Credits](#-credits) + * [🎭 License](#-license) + + ## 💡 What is DocuWare? DocuWare provides cloud document management and workflow automation software @@ -243,6 +276,61 @@ $document = $connector->send(new PostDocumentRequest( $connector->send(new DeleteDocumentRequest($fileCabinetId, $document->id))->dto(); ``` +## Pagination + +Requests that support pagination: + +| Requests | +|-------------------------| +| GetDialogsRequest | +| GetDocumentsRequest | +| GetFieldsRequest | +| GetFileCabinetsRequest | +| GetOrganizationsRequest | +| GetSearchRequest | +| GetSectionsRequest | + + +```php + $paginator = $connector->paginate(new GetDocumentsRequest( + config('laravel-docuware.tests.file_cabinet_id') + )); + + // You can set the per page limit + $paginator->setPerPageLimit(2); + + + + // You can set the start page and how many pages you want to get + + $paginator->setStartPage(3); + $paginator->setMaxPages(3); // Should be equal or more than the start page + + // OR + + $paginator->getSinglePage(3); + + + + // Get the data from the paginator + + $data = collect(); + + foreach ($paginator->collect() as $collection) { + $data->push($collection); + } + + // OR + + foreach ($paginator as $response) { + $data->push($response->dto()); + } + + + + $data->flatten() +``` + ## 🔍 Search usage ```php @@ -600,27 +688,6 @@ CodebarAg\DocuWare\DTO\TableRow { } ``` -```php -CodebarAg\DocuWare\DTO\DocumentPaginator - +total: 39 // integer - +per_page: 10 // integer - +current_page: 9 // integer - +last_page: 15 // integer - +from: 1 // integer - +to: 10 // integer - +documents: Illuminate\Support\Collection { // Collection|Document[] - #items: array:2 [ - 0 => CodebarAg\DocuWare\DTO\Document // Document - 1 => CodebarAg\DocuWare\DTO\Document // Document - ] - } - +error: CodebarAg\DocuWare\DTO\ErrorBag { // ErrorBag|null - +code: 422 // int - +message: "'000' is not valid cabinet id" // string - } -} -``` - ## 🔐 Authentication You only need to provide correct credentials. Everything else is automatically diff --git a/composer.json b/composer.json index b6f3bdf8..8c742da8 100644 --- a/composer.json +++ b/composer.json @@ -29,8 +29,9 @@ "illuminate/contracts": "^9.0|^10.0", "nesbot/carbon": "^2.64.0", "saloonphp/cache-plugin": "^3.0", - "saloonphp/saloon": "^3.0", "saloonphp/laravel-plugin": "^3.0", + "saloonphp/pagination-plugin": "^2.1", + "saloonphp/saloon": "^3.0", "spatie/laravel-package-tools": "^1.14.0" }, "require-dev": { diff --git a/src/Connectors/DocuWareDynamicConnector.php b/src/Connectors/DocuWareDynamicConnector.php index f8eca50c..bb367a42 100644 --- a/src/Connectors/DocuWareDynamicConnector.php +++ b/src/Connectors/DocuWareDynamicConnector.php @@ -6,8 +6,11 @@ use CodebarAg\DocuWare\Support\Auth; use GuzzleHttp\Cookie\CookieJar; use Saloon\Http\Connector; +use Saloon\Http\Request; +use Saloon\PaginationPlugin\Contracts\HasPagination; +use Saloon\PaginationPlugin\OffsetPaginator; -class DocuWareDynamicConnector extends Connector +class DocuWareDynamicConnector extends Connector implements HasPagination { public Config $configuration; @@ -55,4 +58,9 @@ public function getConfiguration(): Config { return $this->configuration; } + + public function paginate(Request $request): OffsetPaginator + { + return new DocuWareOffsetPaginator(connector: $this, request: $request); + } } diff --git a/src/Connectors/DocuWareOffsetPaginator.php b/src/Connectors/DocuWareOffsetPaginator.php new file mode 100644 index 00000000..2eef18e1 --- /dev/null +++ b/src/Connectors/DocuWareOffsetPaginator.php @@ -0,0 +1,50 @@ +setStartPage($page)->setMaxPages($page); + } + + protected function isLastPage(Response $response): bool + { + $count = Arr::get($response->json(), 'Count'); + + return $this->getOffset() >= (int) Arr::get($count, 'Value'); + } + + protected function getTotalPages(Response $response): int + { + $count = Arr::get($response->json(), 'Count'); + + return (int) ceil((Arr::get($count, 'Value') / $this->perPageLimit)); + } + + protected function getPageItems(Response $response, Request $request): array + { + return [ + $response->dto(), + ]; + } + + protected function applyPagination(Request $request): Request + { + $request->query()->merge([ + 'count' => $this->perPageLimit, + 'start' => $this->getOffset(), + ]); + + return $request; + } +} diff --git a/src/Connectors/DocuWareStaticConnector.php b/src/Connectors/DocuWareStaticConnector.php index e18ff25d..4dde57b7 100644 --- a/src/Connectors/DocuWareStaticConnector.php +++ b/src/Connectors/DocuWareStaticConnector.php @@ -7,8 +7,11 @@ use CodebarAg\DocuWare\Support\EnsureValidCredentials; use GuzzleHttp\Cookie\CookieJar; use Saloon\Http\Connector; +use Saloon\Http\Request; +use Saloon\PaginationPlugin\Contracts\HasPagination; +use Saloon\PaginationPlugin\OffsetPaginator; -class DocuWareStaticConnector extends Connector +class DocuWareStaticConnector extends Connector implements HasPagination { public CookieJar $cookieJar; @@ -47,4 +50,9 @@ public function getCoookieJar(): CookieJar { return $this->cookieJar; } + + public function paginate(Request $request): OffsetPaginator + { + return new DocuWareOffsetPaginator(connector: $this, request: $request); + } } diff --git a/src/DocuWareSearchRequestBuilder.php b/src/DocuWareSearchRequestBuilder.php index a347c1c7..81d0b49a 100644 --- a/src/DocuWareSearchRequestBuilder.php +++ b/src/DocuWareSearchRequestBuilder.php @@ -17,10 +17,6 @@ class DocuWareSearchRequestBuilder protected array $additionalFileCabinetIds = []; - protected int $page = 1; - - protected int $perPage = 50; - protected ?string $searchTerm = null; protected string $orderField = 'DWSTOREDATETIME'; @@ -54,28 +50,6 @@ public function dialog(string $dialogId): self return $this; } - public function page(?int $page): self - { - if (is_null($page)) { - $this->page = 1; - } else { - $this->page = $page; - } - - return $this; - } - - public function perPage(?int $perPage): self - { - if (is_null($perPage)) { - $this->perPage = 50; - } else { - $this->perPage = $perPage; - } - - return $this; - } - public function fulltext(?string $searchTerm): self { $this->searchTerm = $searchTerm; @@ -174,8 +148,6 @@ public function get(): GetSearchRequest fileCabinetId: $this->fileCabinetId, dialogId: $this->dialogId, additionalFileCabinetIds: $this->additionalFileCabinetIds, - page: $this->page, - perPage: $this->perPage, searchTerm: $this->searchTerm, orderField: $this->orderField, orderDirection: $this->orderDirection, @@ -189,16 +161,6 @@ protected function guard(): void is_null($this->fileCabinetId), UnableToSearch::cabinetNotSet(), ); - - throw_if( - $this->page <= 0, - UnableToSearch::invalidPageNumber($this->page), - ); - - throw_if( - $this->perPage <= 0, - UnableToSearch::invalidPerPageNumber($this->perPage), - ); } private function checkDateFilterRangeDivergence(): void diff --git a/src/Requests/Dialogs/GetDialogsRequest.php b/src/Requests/Dialogs/GetDialogsRequest.php index e8731fb1..fe0c2d6d 100644 --- a/src/Requests/Dialogs/GetDialogsRequest.php +++ b/src/Requests/Dialogs/GetDialogsRequest.php @@ -10,8 +10,9 @@ use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; +use Saloon\PaginationPlugin\Contracts\Paginatable; -class GetDialogsRequest extends Request implements Cacheable +class GetDialogsRequest extends Request implements Cacheable, Paginatable { use HasCaching; diff --git a/src/Requests/Document/GetDocumentsRequest.php b/src/Requests/Document/GetDocumentsRequest.php index 2a41c05a..30be4cff 100644 --- a/src/Requests/Document/GetDocumentsRequest.php +++ b/src/Requests/Document/GetDocumentsRequest.php @@ -11,8 +11,9 @@ use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; +use Saloon\PaginationPlugin\Contracts\Paginatable; -class GetDocumentsRequest extends Request implements Cacheable +class GetDocumentsRequest extends Request implements Cacheable, Paginatable { use HasCaching; diff --git a/src/Requests/Fields/GetFieldsRequest.php b/src/Requests/Fields/GetFieldsRequest.php index 3361f532..13702d7e 100644 --- a/src/Requests/Fields/GetFieldsRequest.php +++ b/src/Requests/Fields/GetFieldsRequest.php @@ -12,8 +12,9 @@ use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; +use Saloon\PaginationPlugin\Contracts\Paginatable; -class GetFieldsRequest extends Request implements Cacheable +class GetFieldsRequest extends Request implements Cacheable, Paginatable { use HasCaching; diff --git a/src/Requests/FileCabinets/GetFileCabinetsRequest.php b/src/Requests/FileCabinets/GetFileCabinetsRequest.php index 3fbef5af..a5772781 100644 --- a/src/Requests/FileCabinets/GetFileCabinetsRequest.php +++ b/src/Requests/FileCabinets/GetFileCabinetsRequest.php @@ -12,8 +12,9 @@ use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; +use Saloon\PaginationPlugin\Contracts\Paginatable; -class GetFileCabinetsRequest extends Request implements Cacheable +class GetFileCabinetsRequest extends Request implements Cacheable, Paginatable { use HasCaching; diff --git a/src/Requests/Organization/GetOrganizationsRequest.php b/src/Requests/Organization/GetOrganizationsRequest.php index 21872337..7d8c81f1 100644 --- a/src/Requests/Organization/GetOrganizationsRequest.php +++ b/src/Requests/Organization/GetOrganizationsRequest.php @@ -12,8 +12,9 @@ use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; +use Saloon\PaginationPlugin\Contracts\Paginatable; -class GetOrganizationsRequest extends Request implements Cacheable +class GetOrganizationsRequest extends Request implements Cacheable, Paginatable { use HasCaching; diff --git a/src/Requests/Search/GetSearchRequest.php b/src/Requests/Search/GetSearchRequest.php index a06800e9..20d9480b 100644 --- a/src/Requests/Search/GetSearchRequest.php +++ b/src/Requests/Search/GetSearchRequest.php @@ -2,8 +2,9 @@ namespace CodebarAg\DocuWare\Requests\Search; -use CodebarAg\DocuWare\DTO\DocumentPaginator; -use CodebarAg\DocuWare\Responses\Search\GetSearchResponse; +use CodebarAg\DocuWare\DTO\Document; +use Illuminate\Support\Arr; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; use Saloon\CachePlugin\Contracts\Cacheable; use Saloon\CachePlugin\Drivers\LaravelCacheDriver; @@ -12,9 +13,10 @@ use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; +use Saloon\PaginationPlugin\Contracts\Paginatable; use Saloon\Traits\Body\HasJsonBody; -class GetSearchRequest extends Request implements Cacheable, HasBody +class GetSearchRequest extends Request implements Cacheable, HasBody, Paginatable { use HasCaching; use HasJsonBody; @@ -25,8 +27,6 @@ public function __construct( protected readonly ?string $fileCabinetId, protected readonly ?string $dialogId = null, protected readonly array $additionalFileCabinetIds = [], - protected readonly int $page = 1, - protected readonly int $perPage = 50, protected readonly ?string $searchTerm = null, protected readonly string $orderField = 'DWSTOREDATETIME', protected readonly string $orderDirection = 'asc', @@ -63,8 +63,6 @@ public function defaultQuery(): array public function defaultBody(): array { return [ - 'Count' => $this->perPage, - 'Start' => ($this->page - 1) * $this->perPage, 'Condition' => $this->condition, 'AdditionalCabinets' => $this->additionalFileCabinetIds, 'SortOrder' => [ @@ -80,8 +78,10 @@ public function defaultBody(): array ]; } - public function createDtoFromResponse(Response $response): DocumentPaginator + public function createDtoFromResponse(Response $response): Collection { - return GetSearchResponse::fromResponse($response, $this->page, $this->perPage); + return collect(Arr::get($response->json(), 'Items'))->map(function (array $document) { + return Document::fromJson($document); + }); } } diff --git a/src/Requests/Sections/GetSectionsRequest.php b/src/Requests/Sections/GetSectionsRequest.php index 7609933e..257e3ce1 100644 --- a/src/Requests/Sections/GetSectionsRequest.php +++ b/src/Requests/Sections/GetSectionsRequest.php @@ -12,8 +12,9 @@ use Saloon\Enums\Method; use Saloon\Http\Request; use Saloon\Http\Response; +use Saloon\PaginationPlugin\Contracts\Paginatable; -class GetSectionsRequest extends Request implements Cacheable +class GetSectionsRequest extends Request implements Cacheable, Paginatable { use HasCaching; diff --git a/tests/Feature/Requests/Document/GetDocumentsRequestTest.php b/tests/Feature/Requests/Document/GetDocumentsRequestTest.php index b68acd95..dc5cde8c 100644 --- a/tests/Feature/Requests/Document/GetDocumentsRequestTest.php +++ b/tests/Feature/Requests/Document/GetDocumentsRequestTest.php @@ -25,3 +25,35 @@ Event::assertDispatched(DocuWareResponseLog::class); }); + +it('can get all documents paginated', function () { + Event::fake(); + + for ($i = 0; $i < 4; $i++) { + $this->connector->send(new PostDocumentRequest( + config('laravel-docuware.tests.file_cabinet_id'), + '::fake-file-content::', + 'example.txt' + ))->dto(); + } + + $request = new GetDocumentsRequest( + config('laravel-docuware.tests.file_cabinet_id') + ); + + $paginator = $this->connector->paginate($request); + + $paginator->setPerPageLimit(2); + + $documents = collect(); + + foreach ($paginator as $response) { + $this->assertCount(2, $response->dto()); + + $documents->push($response->dto()); + } + + $this->assertCount(4, $documents->flatten()); + + Event::assertDispatched(DocuWareResponseLog::class); +}); diff --git a/tests/Feature/Requests/Search/GetSearchRequestTest.php b/tests/Feature/Requests/Search/GetSearchRequestTest.php index 44229edd..f277ae4a 100644 --- a/tests/Feature/Requests/Search/GetSearchRequestTest.php +++ b/tests/Feature/Requests/Search/GetSearchRequestTest.php @@ -3,7 +3,6 @@ use Carbon\Carbon; use CodebarAg\DocuWare\DocuWare; use CodebarAg\DocuWare\DTO\DocumentIndex\IndexTextDTO; -use CodebarAg\DocuWare\DTO\DocumentPaginator; use CodebarAg\DocuWare\Events\DocuWareResponseLog; use CodebarAg\DocuWare\Exceptions\UnableToSearch; use CodebarAg\DocuWare\Requests\Document\PostDocumentRequest; @@ -19,8 +18,6 @@ ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) - ->page(1) - ->perPage(5) ->fulltext('test') ->filterDate('DWSTOREDATETIME', '>=', Carbon::create(2021)) ->filterDate('DWSTOREDATETIME', '<', now()) @@ -28,10 +25,21 @@ ->orderBy('DWSTOREDATETIME', 'desc') ->get(); - $paginator = $this->connector->send($paginatorRequest)->dto(); + $paginator = $this->connector->paginate($paginatorRequest); - $this->assertInstanceOf(DocumentPaginator::class, $paginator); - Event::assertDispatched(DocuWareResponseLog::class); + $paginator->setPerPageLimit(5) + ->setStartPage(1) + ->setMaxPages(1); + + $documents = collect(); + + foreach ($paginator as $response) { + $this->assertCount(0, $response->dto()); + + $documents->push($response->dto()); + } + + $this->assertCount(0, $documents->flatten()); })->group('search'); it('can\'t search documents by more than two dates', function () { @@ -46,8 +54,6 @@ ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) - ->page(1) - ->perPage(5) ->fulltext('test') ->filterDate('DWSTOREDATETIME', '>=', Carbon::create(2020)) ->filterDate('DWSTOREDATETIME', '>=', Carbon::create(2021)) @@ -56,7 +62,21 @@ ->orderBy('DWSTOREDATETIME', 'desc') ->get(); - $this->connector->send($request)->dto(); + $paginator = $this->connector->paginate($request); + + $paginator->setPerPageLimit(5) + ->setStartPage(1) + ->setMaxPages(1); + + $documents = collect(); + + foreach ($paginator as $response) { + $this->assertCount(2, $response->dto()); + + $documents->push($response->dto()); + } + + $this->assertCount(4, $documents->flatten()); })->group('search'); it('can override search documents dates filter by using same operator', function () { @@ -69,8 +89,6 @@ ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) - ->page(1) - ->perPage(5) ->fulltext('test') ->filterDate('DWSTOREDATETIME', '<=', Carbon::create(2022)) ->filterDate('DWSTOREDATETIME', '>=', Carbon::create(2020)) @@ -79,10 +97,21 @@ ->orderBy('DWSTOREDATETIME', 'desc') ->get(); - $paginator = $this->connector->send($paginatorRequest)->dto(); + $paginator = $this->connector->paginate($paginatorRequest); - $this->assertInstanceOf(DocumentPaginator::class, $paginator); - Event::assertDispatched(DocuWareResponseLog::class); + $paginator->setPerPageLimit(5) + ->setStartPage(1) + ->setMaxPages(1); + + $documents = collect(); + + foreach ($paginator as $response) { + $this->assertCount(0, $response->dto()); + + $documents->push($response->dto()); + } + + $this->assertCount(0, $documents->flatten()); })->group('search'); it('can override search documents dates filter by using equal operator', function () { @@ -95,8 +124,6 @@ ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) - ->page(1) - ->perPage(5) ->fulltext('test') ->filterDate('DWSTOREDATETIME', '>=', Carbon::create(2020)) ->filterDate('DWSTOREDATETIME', '=', Carbon::create(2021)) @@ -104,10 +131,21 @@ ->orderBy('DWSTOREDATETIME', 'desc') ->get(); - $paginator = $this->connector->send($paginatorRequest)->dto(); + $paginator = $this->connector->paginate($paginatorRequest); - $this->assertInstanceOf(DocumentPaginator::class, $paginator); - Event::assertDispatched(DocuWareResponseLog::class); + $paginator->setPerPageLimit(5) + ->setStartPage(1) + ->setMaxPages(1); + + $documents = collect(); + + foreach ($paginator as $response) { + $this->assertCount(0, $response->dto()); + + $documents->push($response->dto()); + } + + $this->assertCount(0, $documents->flatten()); })->group('search'); it('can\'t search documents by diverged date range', function () { @@ -122,8 +160,6 @@ ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) - ->page(1) - ->perPage(5) ->fulltext('test') ->filterDate('DWSTOREDATETIME', '<=', Carbon::create(2020)) ->filterDate('DWSTOREDATETIME', '>=', Carbon::create(2021)) @@ -131,7 +167,21 @@ ->orderBy('DWSTOREDATETIME', 'desc') ->get(); - $this->connector->send($request)->dto(); + $paginator = $this->connector->paginate($request); + + $paginator->setPerPageLimit(5) + ->setStartPage(1) + ->setMaxPages(1); + + $documents = collect(); + + foreach ($paginator as $response) { + $this->assertCount(2, $response->dto()); + + $documents->push($response->dto()); + } + + $this->assertCount(4, $documents->flatten()); })->group('search'); it('can search documents dates filter in future', function () { @@ -144,18 +194,27 @@ ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) - ->page(1) - ->perPage(5) ->fulltext('test') ->filterDate('DWSTOREDATETIME', '>', Carbon::create(2018)) ->filter('DOCUMENT_TYPE', 'Abrechnung') ->orderBy('DWSTOREDATETIME', 'desc') ->get(); - $paginator = $this->connector->send($paginatorRequest)->dto(); + $paginator = $this->connector->paginate($paginatorRequest); - $this->assertInstanceOf(DocumentPaginator::class, $paginator); - Event::assertDispatched(DocuWareResponseLog::class); + $paginator->setPerPageLimit(5) + ->setStartPage(1) + ->setMaxPages(1); + + $documents = collect(); + + foreach ($paginator as $response) { + $this->assertCount(0, $response->dto()); + + $documents->push($response->dto()); + } + + $this->assertCount(0, $documents->flatten()); })->group('search'); it('can search documents dates filter in past', function () { @@ -168,18 +227,27 @@ ->searchRequestBuilder() ->fileCabinet($fileCabinetId) ->dialog($dialogId) - ->page(1) - ->perPage(5) ->fulltext('test') ->filterDate('DWSTOREDATETIME', '<=', Carbon::create(2020)) ->filter('DOCUMENT_TYPE', 'Abrechnung') ->orderBy('DWSTOREDATETIME', 'desc') ->get(); - $paginator = $this->connector->send($paginatorRequest)->dto(); + $paginator = $this->connector->paginate($paginatorRequest); - $this->assertInstanceOf(DocumentPaginator::class, $paginator); - Event::assertDispatched(DocuWareResponseLog::class); + $paginator->setPerPageLimit(5) + ->setStartPage(1) + ->setMaxPages(1); + + $documents = collect(); + + foreach ($paginator as $response) { + $this->assertCount(0, $response->dto()); + + $documents->push($response->dto()); + } + + $this->assertCount(0, $documents->flatten()); })->group('search'); it('can search documents with null values', function () { @@ -192,17 +260,22 @@ $paginatorRequest = (new DocuWare()) ->searchRequestBuilder() ->fileCabinets($fileCabinetIds) - ->page(null) - ->perPage(null) ->fulltext(null) ->filter('DOCUMENT_TYPE', null) ->orderBy('DWSTOREDATETIME', null) ->get(); - $paginator = $this->connector->send($paginatorRequest)->dto(); + $paginator = $this->connector->paginate($paginatorRequest); - $this->assertInstanceOf(DocumentPaginator::class, $paginator); - Event::assertDispatched(DocuWareResponseLog::class); + $documents = collect(); + + foreach ($paginator as $response) { + $this->assertCount(0, $response->dto()); + + $documents->push($response->dto()); + } + + $this->assertCount(0, $documents->flatten()); })->group('search'); it('can search documents with multiple values', function () { @@ -246,15 +319,55 @@ $paginatorRequestBothDocuments = (new DocuWare()) ->searchRequestBuilder() ->fileCabinets([$fileCabinetId]) - ->page(null) - ->perPage(null) ->fulltext(null) ->filterIn('DOCUMENT_TYPE', ['Abrechnung', 'Rechnung']) ->get(); - $paginator = $this->connector->send($paginatorRequestBothDocuments)->dto(); + $paginator = $this->connector->paginate($paginatorRequestBothDocuments); + + $documents = collect(); + + foreach ($paginator as $response) { + $this->assertCount(2, $response->dto()); + + $documents->push($response->dto()); + } + + $this->assertCount(2, $documents->flatten()); + Event::assertDispatched(DocuWareResponseLog::class); +})->group('search'); + +it('can search and get paginated results', function () { + Event::fake(); + + $fileCabinetId = config('laravel-docuware.tests.file_cabinet_id'); + + for ($i = 0; $i < 4; $i++) { + $this->connector->send(new PostDocumentRequest( + config('laravel-docuware.tests.file_cabinet_id'), + '::fake-file-content::', + 'example.txt' + ))->dto(); + } + + $paginatorRequestBothDocuments = (new DocuWare()) + ->searchRequestBuilder() + ->fileCabinets([$fileCabinetId]) + ->fulltext(null) + ->get(); + + $paginator = $this->connector->paginate($paginatorRequestBothDocuments); + + $paginator->setPerPageLimit(2); + + $documents = collect(); + + foreach ($paginator as $response) { + $this->assertCount(2, $response->dto()); + + $documents->push($response->dto()); + } - $this->assertInstanceOf(DocumentPaginator::class, $paginator); - $this->assertCount(2, $paginator->documents); + $this->assertCount(4, $documents->flatten()); Event::assertDispatched(DocuWareResponseLog::class); })->group('search');