Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertPaginationCorrectOnStoreFront.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
10 use Magento\Mtf\Client\BrowserInterface;
11 use Magento\Mtf\Constraint\AbstractConstraint;
13 
17 class AssertPaginationCorrectOnStoreFront extends AbstractConstraint
18 {
19  /* tags */
20  const SEVERITY = 'low';
21  /* end tags */
22 
32  public function processAssert(
33  BrowserInterface $browser,
34  Category $category,
35  CatalogCategoryView $catalogCategoryView,
36  $productsCount
37  ) {
38  $browser->open($_ENV['app_frontend_url'] . $category->getUrlKey() . '.html');
39  \PHPUnit\Framework\Assert::assertEquals(
40  true,
41  $catalogCategoryView->getBottomToolbar()->isVisible(),
42  'Pagination is not visible'
43  );
44  \PHPUnit\Framework\Assert::assertEquals(
45  $catalogCategoryView->getBottomToolbar()->getLimitedValueByIndex(0),
46  $catalogCategoryView->getListProductBlock()->getProductsCount(),
47  'Count of products on 1 page does not equivalent with declared in pagination (default value)'
48  );
49  $catalogCategoryView->getBottomToolbar()->nextPage();
50  \PHPUnit\Framework\Assert::assertEquals(
51  $this->calculateExpectedProductsCountOnPage(
52  $catalogCategoryView->getBottomToolbar()->getLimitedValueByIndex(0),
53  2,
54  $productsCount
55  ),
56  $catalogCategoryView->getListProductBlock()->getProductsCount(),
57  'Count of products on 2 page does not equivalent with declared in pagination (default value)'
58  );
59  $catalogCategoryView->getBottomToolbar()->firstPage();
60  $catalogCategoryView->getBottomToolbar()->setLimiterValueByIndex(1);
61  \PHPUnit\Framework\Assert::assertEquals(
62  $catalogCategoryView->getBottomToolbar()->getLimitedValueByIndex(1),
63  $catalogCategoryView->getListProductBlock()->getProductsCount(),
64  'Count of products on 1 page does not equivalent with declared in pagination(custom value)'
65  );
66  $catalogCategoryView->getBottomToolbar()->nextPage();
67  \PHPUnit\Framework\Assert::assertEquals(
68  $this->calculateExpectedProductsCountOnPage(
69  $catalogCategoryView->getBottomToolbar()->getLimitedValueByIndex(1),
70  2,
71  $productsCount
72  ),
73  $catalogCategoryView->getListProductBlock()->getProductsCount(),
74  'Count of products on 2 page does not equivalent with declared in pagination(custom value)'
75  );
76  }
77 
86  private function calculateExpectedProductsCountOnPage($productsPerPage, $numberOfPage, $totalProductsCount)
87  {
88  return min($productsPerPage, $totalProductsCount - $productsPerPage * ($numberOfPage - 1));
89  }
90 
96  public function toString()
97  {
98  return 'Pagination is correct on frontend.';
99  }
100 }
processAssert(BrowserInterface $browser, Category $category, CatalogCategoryView $catalogCategoryView, $productsCount)