Skip to content

Commit 9e36926

Browse files
author
Dmytro Aponasenko
committed
Merge branch 'MTA-2484' of https://github.corp.ebay.com/magento-qmt/magento2ce into develop
2 parents eae6db9 + 07264cc commit 9e36926

File tree

6 files changed

+184
-10
lines changed

6 files changed

+184
-10
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Constraint;
8+
9+
use Magento\Catalog\Test\Fixture\Category;
10+
use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
11+
use Magento\Mtf\Client\BrowserInterface;
12+
use Magento\Mtf\Constraint\AbstractConstraint;
13+
14+
/**
15+
* Assert that displayed breadcrumbs on category page equals to passed from fixture.
16+
*/
17+
class AssertCategoryBreadcrumbs extends AbstractConstraint
18+
{
19+
/**
20+
* Name of home page.
21+
*/
22+
const HOME_PAGE = 'Home';
23+
24+
/**
25+
* Browser instance.
26+
*
27+
* @var BrowserInterface
28+
*/
29+
protected $browser;
30+
31+
/**
32+
* Assert that displayed breadcrumbs on category page equals to passed from fixture.
33+
*
34+
* @param BrowserInterface $browser
35+
* @param Category $category
36+
* @param CatalogCategoryView $catalogCategoryView
37+
* @return void
38+
*/
39+
public function processAssert(
40+
BrowserInterface $browser,
41+
Category $category,
42+
CatalogCategoryView $catalogCategoryView
43+
) {
44+
$this->browser = $browser;
45+
$this->openCategory($category);
46+
47+
$breadcrumbs = $this->getBreadcrumbs($category);
48+
$pageBreadcrumbs = $catalogCategoryView->getBreadcrumbs()->getText();
49+
\PHPUnit_Framework_Assert::assertEquals(
50+
$breadcrumbs,
51+
$pageBreadcrumbs,
52+
'Wrong breadcrumbs of category page.'
53+
. "\nExpected: " . $breadcrumbs
54+
. "\nActual: " . $pageBreadcrumbs
55+
);
56+
}
57+
58+
/**
59+
* Open category.
60+
*
61+
* @param Category $category
62+
* @return void
63+
*/
64+
protected function openCategory(Category $category)
65+
{
66+
$categoryUrlKey = [];
67+
68+
while ($category) {
69+
$categoryUrlKey[] = $category->hasData('url_key')
70+
? strtolower($category->getUrlKey())
71+
: trim(strtolower(preg_replace('#[^0-9a-z%]+#i', '-', $category->getName())), '-');
72+
73+
$category = $category->getDataFieldConfig('parent_id')['source']->getParentCategory();
74+
if ($category !== null && 1 == $category->getParentId()) {
75+
$category = null;
76+
}
77+
}
78+
$categoryUrlKey = $_ENV['app_frontend_url'] . implode('/', array_reverse($categoryUrlKey)) . '.html';
79+
80+
$this->browser->open($categoryUrlKey);
81+
}
82+
83+
/**
84+
* Prepare and return category breadcrumbs.
85+
*
86+
* @param Category $category
87+
* @return string
88+
*/
89+
protected function getBreadcrumbs(Category $category)
90+
{
91+
$breadcrumbs = [];
92+
93+
while ($category) {
94+
$breadcrumbs[] = $category->getName();
95+
96+
$category = $category->getDataFieldConfig('parent_id')['source']->getParentCategory();
97+
if ($category !== null && 1 == $category->getParentId()) {
98+
$category = null;
99+
}
100+
}
101+
$breadcrumbs[] = self::HOME_PAGE;
102+
103+
return implode(' ', array_reverse($breadcrumbs));
104+
}
105+
106+
/**
107+
* Returns a string representation of the object.
108+
*
109+
* @return string
110+
*/
111+
public function toString()
112+
{
113+
return 'Breadcrumbs on category page equals to passed from fixture.';
114+
}
115+
}

dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryPage.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
class AssertCategoryPage extends AbstractConstraint
2020
{
2121
/**
22-
* CMS Block display mode
22+
* CMS Block display mode.
2323
*
2424
* @var array
2525
*/
@@ -29,14 +29,14 @@ class AssertCategoryPage extends AbstractConstraint
2929
];
3030

3131
/**
32-
* Category view page
32+
* Category view page.
3333
*
3434
* @var CatalogCategoryView
3535
*/
3636
protected $categoryViewPage;
3737

3838
/**
39-
* Browser instance
39+
* Browser instance.
4040
*
4141
* @var BrowserInterface
4242
*/
@@ -68,6 +68,8 @@ public function processAssert(
6868
}
6969

7070
/**
71+
* Prepare comparison data.
72+
*
7173
* @param FixtureFactory $fixtureFactory
7274
* @param Category $category
7375
* @param Category $initialCategory
@@ -92,21 +94,30 @@ protected function prepareData(FixtureFactory $fixtureFactory, Category $categor
9294
}
9395

9496
/**
95-
* Get category url to open
97+
* Get category url to open.
9698
*
9799
* @param Category $category
98100
* @return string
99101
*/
100102
protected function getCategoryUrl(Category $category)
101103
{
102-
$categoryUrlKey = $category->hasData('url_key')
103-
? strtolower($category->getUrlKey())
104-
: trim(strtolower(preg_replace('#[^0-9a-z%]+#i', '-', $category->getName())), '-');
105-
return $_ENV['app_frontend_url'] . $categoryUrlKey . '.html';
104+
$categoryUrlKey = [];
105+
while ($category) {
106+
$categoryUrlKey[] = $category->hasData('url_key')
107+
? strtolower($category->getUrlKey())
108+
: trim(strtolower(preg_replace('#[^0-9a-z%]+#i', '-', $category->getName())), '-');
109+
110+
$category = $category->getDataFieldConfig('parent_id')['source']->getParentCategory();
111+
if (1 == $category->getParentId()) {
112+
$category = null;
113+
}
114+
}
115+
116+
return $_ENV['app_frontend_url'] . implode('/', array_reverse($categoryUrlKey)) . '.html';
106117
}
107118

108119
/**
109-
* Assert category general information
120+
* Assert category general information.
110121
*
111122
* @param Category $category
112123
* @param array $categoryData
@@ -147,7 +158,7 @@ protected function assertGeneralInformation(Category $category, array $categoryD
147158
}
148159

149160
/**
150-
* Assert category display settings
161+
* Assert category display settings.
151162
*
152163
* @param Category $category
153164
* @param array $categoryData

dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Category/CatalogCategoryView.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../vendor/magento/mtf/etc/pages.xsd">
99
<page name="CatalogCategoryView" area="Category" mca="catalog/category/view" module="Magento_Catalog">
1010
<block name="titleBlock" class="Magento\Theme\Test\Block\Html\Title" locator=".page-title-wrapper h1.page-title .base" strategy="css selector"/>
11+
<block name="breadcrumbs" class="Magento\Theme\Test\Block\Html\Breadcrumbs" locator=".breadcrumbs" strategy="css selector"/>
1112
<block name="widgetView" class="Magento\Widget\Test\Block\WidgetView" locator=".widget" strategy="css selector"/>
1213
<block name="viewBlock" class="Magento\Catalog\Test\Block\Category\View" locator="#maincontent" strategy="css selector"/>
1314
<block name="listProductBlock" class="Magento\Catalog\Test\Block\Product\ListProduct" locator=".products.wrapper.grid" strategy="css selector"/>

dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/Category.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,15 @@
6161
<field name="is_active" xsi:type="string">Yes</field>
6262
<field name="include_in_menu" xsi:type="string">Yes</field>
6363
</dataset>
64+
65+
<dataset name="two_nested_category">
66+
<field name="name" xsi:type="string">Category%isolation%</field>
67+
<field name="url_key" xsi:type="string">category-%isolation%</field>
68+
<field name="parent_id" xsi:type="array">
69+
<item name="dataset" xsi:type="string">default_subcategory</item>
70+
</field>
71+
<field name="is_active" xsi:type="string">Yes</field>
72+
<field name="include_in_menu" xsi:type="string">Yes</field>
73+
</dataset>
6474
</repository>
6575
</config>

dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/CreateCategoryEntityTest.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,17 @@
149149
<constraint name="Magento\Catalog\Test\Constraint\AssertCategorySaveMessage" />
150150
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryForAssignedProducts" />
151151
</variation>
152+
<variation name="CreateCategoryEntityTestVariation10">
153+
<data name="description" xsi:type="string">Create category with three nesting</data>
154+
<data name="addCategory" xsi:type="string">addSubcategory</data>
155+
<data name="category/data/parent_id/dataset" xsi:type="string">two_nested_category</data>
156+
<data name="category/data/name" xsi:type="string">Category%isolation%</data>
157+
<data name="category/data/url_key" xsi:type="string">Category%isolation%</data>
158+
<data name="category/data/is_active" xsi:type="string">Yes</data>
159+
<data name="category/data/description" xsi:type="string">Category Required</data>
160+
<data name="category/data/available_product_listing_config" xsi:type="string">Yes</data>
161+
<constraint name="Magento\Catalog\Test\Constraint\AssertCategorySaveMessage" />
162+
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryBreadcrumbs" />
163+
</variation>
152164
</testCase>
153165
</config>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Theme\Test\Block\Html;
8+
9+
use Magento\Mtf\Block\Block;
10+
11+
/**
12+
* Page breadcrumbs block.
13+
*/
14+
class Breadcrumbs extends Block
15+
{
16+
/**
17+
* Get breadcrumbs content of current page.
18+
*
19+
* @return string
20+
*/
21+
public function getText()
22+
{
23+
return $this->_rootElement->getText();
24+
}
25+
}

0 commit comments

Comments
 (0)