Skip to content

Commit

Permalink
#26986 API Functional Test to cover Pagination issue
Browse files Browse the repository at this point in the history
  • Loading branch information
lbajsarowicz committed Feb 23, 2020
1 parent 90a479f commit a6f76f3
Showing 1 changed file with 90 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@
namespace Magento\Catalog\Api;

use Magento\Authorization\Model\Role;
use Magento\Authorization\Model\Rules;
use Magento\Authorization\Model\RoleFactory;
use Magento\Authorization\Model\Rules;
use Magento\Authorization\Model\RulesFactory;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\CatalogInventory\Api\Data\StockItemInterface;
use Magento\Downloadable\Api\DomainManagerInterface;
use Magento\Downloadable\Model\Link;
use Magento\Integration\Api\AdminTokenServiceInterface;
use Magento\Store\Model\Store;
use Magento\Store\Model\Website;
use Magento\Store\Model\WebsiteRepository;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\WebapiAbstract;
use Magento\Framework\Api\ExtensibleDataInterface;
use Magento\Framework\Api\FilterBuilder;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Api\SortOrder;
use Magento\Framework\Api\SortOrderBuilder;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Webapi\Exception as HTTPExceptionCodes;
use Magento\Integration\Api\AdminTokenServiceInterface;
use Magento\Store\Model\Store;
use Magento\Store\Model\Website;
use Magento\Store\Model\WebsiteRepository;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\WebapiAbstract;

/**
* Test for \Magento\Catalog\Api\ProductRepositoryInterface
Expand Down Expand Up @@ -280,7 +280,7 @@ public function testCreateWithMultipleWebsites()
$websitesData = [
'website_ids' => [
1,
(int) $website->getId(),
(int)$website->getId(),
]
];
$productBuilder[ProductInterface::EXTENSION_ATTRIBUTES_KEY] = $websitesData;
Expand Down Expand Up @@ -1096,6 +1096,86 @@ public function testGetListWithFilteringByStoreDataProvider()
];
}

/**
* Test getList() method with pagination
*
* @param int $pageSize
* @param int $currentPage
* @param int $expectedCount
*
* @magentoAppIsolation enabled
* @magentoApiDataFixture Magento/Catalog/_files/products_for_search.php
* @dataProvider productPaginationDataProvider
*/
public function testGetListPagination(int $pageSize, int $currentPage, int $expectedCount)
{
$fixtureProducts = 5;

/** @var FilterBuilder $filterBuilder */
$filterBuilder = Bootstrap::getObjectManager()->create(FilterBuilder::class);

$categoryFilter = $filterBuilder->setField('category_id')
->setValue(333)
->create();

/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
$searchCriteriaBuilder = Bootstrap::getObjectManager()->create(SearchCriteriaBuilder::class);

$searchCriteriaBuilder->addFilters([$categoryFilter]);
$searchCriteriaBuilder->setPageSize($pageSize);
$searchCriteriaBuilder->setCurrentPage($currentPage);

$searchData = $searchCriteriaBuilder->create()->__toArray();
$requestData = ['searchCriteria' => $searchData];
$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($requestData),
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
],
'soap' => [
'service' => self::SERVICE_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_NAME . 'GetList',
],
];

$searchResult = $this->_webApiCall($serviceInfo, $requestData);

$this->assertEquals($fixtureProducts, $searchResult['total_count']);
$this->assertCount($expectedCount, $searchResult['items']);
}

/**
* Keep in mind: Fixture contains 5 products
*
* @return array
*/
public function productPaginationDataProvider()
{
return [
'expect-all-items' => [
'pageSize' => 10,
'currentPage' => 1,
'expectedCount' => 5
],
'expect-page=size-items' => [
'pageSize' => 2,
'currentPage' => 1,
'expectedCount' => 2
],
'expect-less-than-pagesize-elements' => [
'pageSize' => 3,
'currentPage' => 2,
'expectedCount' => 2
],
'expect-no-items' => [
'pageSize' => 100,
'currentPage' => 99,
'expectedCount' => 0
]
];
}

/**
* Test getList() method with multiple filter groups and sorting and pagination
*
Expand Down Expand Up @@ -1133,7 +1213,7 @@ public function testGetListWithMultipleFilterGroupsAndSortingAndPagination()
$sortOrder = $sortOrderBuilder->setField('meta_title')->setDirection(SortOrder::SORT_DESC)->create();

/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
$searchCriteriaBuilder = Bootstrap::getObjectManager()->create(SearchCriteriaBuilder::class);
$searchCriteriaBuilder = Bootstrap::getObjectManager()->create(SearchCriteriaBuilder::class);

$searchCriteriaBuilder->addFilters([$filter1, $filter2, $filter3, $filter4]);
$searchCriteriaBuilder->addFilters([$filter5]);
Expand Down Expand Up @@ -1728,8 +1808,8 @@ private function assertMultiselectValue($productSku, $multiselectAttributeCode,
* Test design settings authorization
*
* @magentoApiDataFixture Magento/User/_files/user_with_custom_role.php
* @throws \Throwable
* @return void
* @throws \Throwable
*/
public function testSaveDesign(): void
{
Expand Down

0 comments on commit a6f76f3

Please sign in to comment.