|
8 | 8 | namespace Magento\Catalog\Api;
|
9 | 9 |
|
10 | 10 | use Magento\Authorization\Model\Role;
|
11 |
| -use Magento\Authorization\Model\Rules; |
12 | 11 | use Magento\Authorization\Model\RoleFactory;
|
| 12 | +use Magento\Authorization\Model\Rules; |
13 | 13 | use Magento\Authorization\Model\RulesFactory;
|
14 | 14 | use Magento\Catalog\Api\Data\ProductInterface;
|
15 | 15 | use Magento\CatalogInventory\Api\Data\StockItemInterface;
|
16 | 16 | use Magento\Downloadable\Api\DomainManagerInterface;
|
17 | 17 | use Magento\Downloadable\Model\Link;
|
18 |
| -use Magento\Integration\Api\AdminTokenServiceInterface; |
19 |
| -use Magento\Store\Model\Store; |
20 |
| -use Magento\Store\Model\Website; |
21 |
| -use Magento\Store\Model\WebsiteRepository; |
22 |
| -use Magento\TestFramework\Helper\Bootstrap; |
23 |
| -use Magento\TestFramework\TestCase\WebapiAbstract; |
24 | 18 | use Magento\Framework\Api\ExtensibleDataInterface;
|
25 | 19 | use Magento\Framework\Api\FilterBuilder;
|
26 | 20 | use Magento\Framework\Api\SearchCriteriaBuilder;
|
27 | 21 | use Magento\Framework\Api\SortOrder;
|
28 | 22 | use Magento\Framework\Api\SortOrderBuilder;
|
29 | 23 | use Magento\Framework\Exception\NoSuchEntityException;
|
30 | 24 | use Magento\Framework\Webapi\Exception as HTTPExceptionCodes;
|
| 25 | +use Magento\Integration\Api\AdminTokenServiceInterface; |
| 26 | +use Magento\Store\Model\Store; |
| 27 | +use Magento\Store\Model\Website; |
| 28 | +use Magento\Store\Model\WebsiteRepository; |
| 29 | +use Magento\TestFramework\Helper\Bootstrap; |
| 30 | +use Magento\TestFramework\TestCase\WebapiAbstract; |
31 | 31 |
|
32 | 32 | /**
|
33 | 33 | * Test for \Magento\Catalog\Api\ProductRepositoryInterface
|
@@ -280,7 +280,7 @@ public function testCreateWithMultipleWebsites()
|
280 | 280 | $websitesData = [
|
281 | 281 | 'website_ids' => [
|
282 | 282 | 1,
|
283 |
| - (int) $website->getId(), |
| 283 | + (int)$website->getId(), |
284 | 284 | ]
|
285 | 285 | ];
|
286 | 286 | $productBuilder[ProductInterface::EXTENSION_ATTRIBUTES_KEY] = $websitesData;
|
@@ -1096,6 +1096,86 @@ public function testGetListWithFilteringByStoreDataProvider()
|
1096 | 1096 | ];
|
1097 | 1097 | }
|
1098 | 1098 |
|
| 1099 | + /** |
| 1100 | + * Test getList() method with pagination |
| 1101 | + * |
| 1102 | + * @param int $pageSize |
| 1103 | + * @param int $currentPage |
| 1104 | + * @param int $expectedCount |
| 1105 | + * |
| 1106 | + * @magentoAppIsolation enabled |
| 1107 | + * @magentoApiDataFixture Magento/Catalog/_files/products_for_search.php |
| 1108 | + * @dataProvider productPaginationDataProvider |
| 1109 | + */ |
| 1110 | + public function testGetListPagination(int $pageSize, int $currentPage, int $expectedCount) |
| 1111 | + { |
| 1112 | + $fixtureProducts = 5; |
| 1113 | + |
| 1114 | + /** @var FilterBuilder $filterBuilder */ |
| 1115 | + $filterBuilder = Bootstrap::getObjectManager()->create(FilterBuilder::class); |
| 1116 | + |
| 1117 | + $categoryFilter = $filterBuilder->setField('category_id') |
| 1118 | + ->setValue(333) |
| 1119 | + ->create(); |
| 1120 | + |
| 1121 | + /** @var SearchCriteriaBuilder $searchCriteriaBuilder */ |
| 1122 | + $searchCriteriaBuilder = Bootstrap::getObjectManager()->create(SearchCriteriaBuilder::class); |
| 1123 | + |
| 1124 | + $searchCriteriaBuilder->addFilters([$categoryFilter]); |
| 1125 | + $searchCriteriaBuilder->setPageSize($pageSize); |
| 1126 | + $searchCriteriaBuilder->setCurrentPage($currentPage); |
| 1127 | + |
| 1128 | + $searchData = $searchCriteriaBuilder->create()->__toArray(); |
| 1129 | + $requestData = ['searchCriteria' => $searchData]; |
| 1130 | + $serviceInfo = [ |
| 1131 | + 'rest' => [ |
| 1132 | + 'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($requestData), |
| 1133 | + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, |
| 1134 | + ], |
| 1135 | + 'soap' => [ |
| 1136 | + 'service' => self::SERVICE_NAME, |
| 1137 | + 'serviceVersion' => self::SERVICE_VERSION, |
| 1138 | + 'operation' => self::SERVICE_NAME . 'GetList', |
| 1139 | + ], |
| 1140 | + ]; |
| 1141 | + |
| 1142 | + $searchResult = $this->_webApiCall($serviceInfo, $requestData); |
| 1143 | + |
| 1144 | + $this->assertEquals($fixtureProducts, $searchResult['total_count']); |
| 1145 | + $this->assertCount($expectedCount, $searchResult['items']); |
| 1146 | + } |
| 1147 | + |
| 1148 | + /** |
| 1149 | + * Keep in mind: Fixture contains 5 products |
| 1150 | + * |
| 1151 | + * @return array |
| 1152 | + */ |
| 1153 | + public function productPaginationDataProvider() |
| 1154 | + { |
| 1155 | + return [ |
| 1156 | + 'expect-all-items' => [ |
| 1157 | + 'pageSize' => 10, |
| 1158 | + 'currentPage' => 1, |
| 1159 | + 'expectedCount' => 5 |
| 1160 | + ], |
| 1161 | + 'expect-page=size-items' => [ |
| 1162 | + 'pageSize' => 2, |
| 1163 | + 'currentPage' => 1, |
| 1164 | + 'expectedCount' => 2 |
| 1165 | + ], |
| 1166 | + 'expect-less-than-pagesize-elements' => [ |
| 1167 | + 'pageSize' => 3, |
| 1168 | + 'currentPage' => 2, |
| 1169 | + 'expectedCount' => 2 |
| 1170 | + ], |
| 1171 | + 'expect-no-items' => [ |
| 1172 | + 'pageSize' => 100, |
| 1173 | + 'currentPage' => 99, |
| 1174 | + 'expectedCount' => 0 |
| 1175 | + ] |
| 1176 | + ]; |
| 1177 | + } |
| 1178 | + |
1099 | 1179 | /**
|
1100 | 1180 | * Test getList() method with multiple filter groups and sorting and pagination
|
1101 | 1181 | *
|
@@ -1133,7 +1213,7 @@ public function testGetListWithMultipleFilterGroupsAndSortingAndPagination()
|
1133 | 1213 | $sortOrder = $sortOrderBuilder->setField('meta_title')->setDirection(SortOrder::SORT_DESC)->create();
|
1134 | 1214 |
|
1135 | 1215 | /** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
1136 |
| - $searchCriteriaBuilder = Bootstrap::getObjectManager()->create(SearchCriteriaBuilder::class); |
| 1216 | + $searchCriteriaBuilder = Bootstrap::getObjectManager()->create(SearchCriteriaBuilder::class); |
1137 | 1217 |
|
1138 | 1218 | $searchCriteriaBuilder->addFilters([$filter1, $filter2, $filter3, $filter4]);
|
1139 | 1219 | $searchCriteriaBuilder->addFilters([$filter5]);
|
@@ -1728,8 +1808,8 @@ private function assertMultiselectValue($productSku, $multiselectAttributeCode,
|
1728 | 1808 | * Test design settings authorization
|
1729 | 1809 | *
|
1730 | 1810 | * @magentoApiDataFixture Magento/User/_files/user_with_custom_role.php
|
1731 |
| - * @throws \Throwable |
1732 | 1811 | * @return void
|
| 1812 | + * @throws \Throwable |
1733 | 1813 | */
|
1734 | 1814 | public function testSaveDesign(): void
|
1735 | 1815 | {
|
|
0 commit comments