Skip to content

Commit fcf4f81

Browse files
author
Dmytro Aponasenko
committed
MTA-1413: Sync qmt repository with mainline - Sprint 4
1 parent 6689b6a commit fcf4f81

File tree

5 files changed

+80
-19
lines changed

5 files changed

+80
-19
lines changed

dev/tests/functional/bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
session_start();
88
defined('MTF_BOOT_FILE') || define('MTF_BOOT_FILE', __FILE__);
9+
defined('MTF_BP') || define('MTF_BP', str_replace('\\', '/', (__DIR__)));
910
require_once __DIR__ . '/../../../app/bootstrap.php';
1011
restore_error_handler();
1112
require_once __DIR__ . '/vendor/autoload.php';

dev/tests/functional/lib/Mtf/Client/Driver/Selenium/Element/SuggestElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function setValue($value)
5959
$this->_eventManager->dispatchEvent(['set_value'], [__METHOD__, $this->getAbsoluteSelector()]);
6060

6161
$this->clear();
62-
foreach(str_split($value) as $symbol) {
62+
foreach (str_split($value) as $symbol) {
6363
$this->find($this->suggest)->click();
6464
$this->_driver->keys($symbol);
6565
$this->waitResult();

dev/tests/functional/lib/Mtf/ObjectManagerFactory.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ class ObjectManagerFactory
4242
*/
4343
public function create(array $sharedInstances = [])
4444
{
45-
if (!defined('MTF_BP')) {
46-
$basePath = str_replace('\\', '/', dirname(dirname(__DIR__)));
47-
define('MTF_BP', $basePath);
48-
}
4945
if (!defined('MTF_TESTS_PATH')) {
5046
define('MTF_TESTS_PATH', MTF_BP . '/tests/app/');
5147
}

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

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,30 @@ class AssertCategoryPage extends AbstractConstraint
2222
const SEVERITY = 'low';
2323
/* end tags */
2424

25+
/**
26+
* CMS Block display mode
27+
*
28+
* @var array
29+
*/
2530
protected $visibleCmsBlockMode = [
2631
'Static block only',
2732
'Static block and products'
2833
];
2934

35+
/**
36+
* Category view page
37+
*
38+
* @var CatalogCategoryView
39+
*/
40+
protected $categoryViewPage;
41+
42+
/**
43+
* Browser instance
44+
*
45+
* @var Browser
46+
*/
47+
protected $browser;
48+
3049
/**
3150
* Assert that displayed category data on category page equals to passed from fixture.
3251
*
@@ -44,6 +63,22 @@ public function processAssert(
4463
CatalogCategoryView $categoryView,
4564
Browser $browser
4665
) {
66+
$this->browser = $browser;
67+
$this->categoryViewPage = $categoryView;
68+
$categoryData = $this->prepareData($fixtureFactory, $category, $initialCategory);
69+
$this->browser->open($this->getCategoryUrl($category));
70+
$this->assertGeneralInformation($category, $categoryData);
71+
$this->assertDisplaySetting($category, $categoryData);
72+
}
73+
74+
/**
75+
* @param FixtureFactory $fixtureFactory
76+
* @param Category $category
77+
* @param Category $initialCategory
78+
* @return array
79+
*/
80+
protected function prepareData(FixtureFactory $fixtureFactory, Category $category, Category $initialCategory)
81+
{
4782
$product = $fixtureFactory->createByCode(
4883
'catalogProductSimple',
4984
[
@@ -55,25 +90,45 @@ public function processAssert(
5590
]
5691
]
5792
);
58-
$categoryData = array_merge($initialCategory->getData(), $category->getData());
93+
$product->persist();
94+
95+
return array_merge($initialCategory->getData(), $category->getData());
96+
}
97+
98+
/**
99+
* Get category url to open
100+
*
101+
* @param Category $category
102+
* @return string
103+
*/
104+
protected function getCategoryUrl(Category $category)
105+
{
59106
$categoryUrlKey = $category->hasData('url_key')
60107
? strtolower($category->getUrlKey())
61108
: trim(strtolower(preg_replace('#[^0-9a-z%]+#i', '-', $category->getName())), '-');
62-
$categoryUrl = $_ENV['app_frontend_url'] . $categoryUrlKey . '.html';
63-
64-
$product->persist();
65-
$browser->open($categoryUrl);
109+
return $_ENV['app_frontend_url'] . $categoryUrlKey . '.html';
110+
}
66111

112+
/**
113+
* Assert category general information
114+
*
115+
* @param Category $category
116+
* @param array $categoryData
117+
* @return void
118+
*/
119+
protected function assertGeneralInformation(Category $category, array $categoryData)
120+
{
121+
$categoryUrl = $this->getCategoryUrl($category);
67122
\PHPUnit_Framework_Assert::assertEquals(
68123
$categoryUrl,
69-
$browser->getUrl(),
124+
$this->browser->getUrl(),
70125
'Wrong page URL.'
71126
. "\nExpected: " . $categoryUrl
72-
. "\nActual: " . $browser->getUrl()
127+
. "\nActual: " . $this->browser->getUrl()
73128
);
74129

75130
if (isset($categoryData['name'])) {
76-
$title = $categoryView->getTitleBlock()->getTitle();
131+
$title = $this->categoryViewPage->getTitleBlock()->getTitle();
77132
\PHPUnit_Framework_Assert::assertEquals(
78133
$categoryData['name'],
79134
$title,
@@ -84,7 +139,7 @@ public function processAssert(
84139
}
85140

86141
if (isset($categoryData['description'])) {
87-
$description = $categoryView->getViewBlock()->getDescription();
142+
$description = $this->categoryViewPage->getViewBlock()->getDescription();
88143
\PHPUnit_Framework_Assert::assertEquals(
89144
$categoryData['description'],
90145
$description,
@@ -93,7 +148,17 @@ public function processAssert(
93148
. "\nActual: " . $description
94149
);
95150
}
151+
}
96152

153+
/**
154+
* Assert category display settings
155+
*
156+
* @param Category $category
157+
* @param array $categoryData
158+
* @return void
159+
*/
160+
protected function assertDisplaySetting(Category $category, array $categoryData)
161+
{
97162
if (
98163
isset($categoryData['landing_page'])
99164
&& isset($categoryData['display_mode'])
@@ -102,7 +167,7 @@ public function processAssert(
102167
/** @var LandingPage $sourceLandingPage */
103168
$sourceLandingPage = $category->getDataFieldConfig('landing_page')['source'];
104169
$fixtureContent = $sourceLandingPage->getCmsBlock()->getContent();
105-
$pageContent = $categoryView->getViewBlock()->getContent();
170+
$pageContent = $this->categoryViewPage->getViewBlock()->getContent();
106171

107172
\PHPUnit_Framework_Assert::assertEquals(
108173
$fixtureContent,
@@ -112,10 +177,9 @@ public function processAssert(
112177
. "\nActual: " . $pageContent
113178
);
114179
}
115-
116180
if (isset($categoryData['default_sort_by'])) {
117181
$sortBy = strtolower($categoryData['default_sort_by']);
118-
$sortType = $categoryView->getTopToolbar()->getSelectSortType();
182+
$sortType = $this->categoryViewPage->getTopToolbar()->getSelectSortType();
119183
\PHPUnit_Framework_Assert::assertEquals(
120184
$sortBy,
121185
$sortType,
@@ -134,7 +198,7 @@ function (&$value) {
134198
);
135199
if ($availableSortType) {
136200
$availableSortType = array_values($availableSortType);
137-
$availableSortTypeOnPage = $categoryView->getTopToolbar()->getSortType();
201+
$availableSortTypeOnPage = $this->categoryViewPage->getTopToolbar()->getSortType();
138202
\PHPUnit_Framework_Assert::assertEquals(
139203
$availableSortType,
140204
$availableSortTypeOnPage,

dev/tests/functional/testsuites/Mtf/TestSuite/InjectableTests.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private function initObjectManager()
9797
? $_ENV['testsuite_rule']
9898
: 'basic';
9999
$confFilePath = realpath(
100-
__DIR__ . '/../../../testsuites/' . $_ENV['testsuite_rule_path'] . '/' . $configurationFileName . '.xml'
100+
MTF_BP . '/testsuites/' . $_ENV['testsuite_rule_path'] . '/' . $configurationFileName . '.xml'
101101
);
102102
/** @var \Mtf\TestRunner\Configuration $testRunnerConfiguration */
103103
$testRunnerConfiguration = $objectManagerFactory->getObjectManager()->get('\Mtf\TestRunner\Configuration');

0 commit comments

Comments
 (0)