Skip to content

Commit 60be08a

Browse files
author
Dmytro Aponasenko
committed
MTA-589: Re-factor Test for Quick Search
1 parent d2391f5 commit 60be08a

File tree

13 files changed

+257
-102
lines changed

13 files changed

+257
-102
lines changed

dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Constraint/AssertCatalogSearchResult.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
namespace Magento\CatalogSearch\Test\Constraint;
77

8+
use Magento\CatalogSearch\Test\Fixture\CatalogSearchQuery;
89
use Magento\CatalogSearch\Test\Page\AdvancedResult;
910
use Mtf\Constraint\AbstractConstraint;
1011

1112
/**
12-
* Class AssertCatalogSearchResult
13+
* Assert search results.
1314
*/
1415
class AssertCatalogSearchResult extends AbstractConstraint
1516
{
@@ -18,40 +19,31 @@ class AssertCatalogSearchResult extends AbstractConstraint
1819
/* end tags */
1920

2021
/**
21-
* Assert that result page contains all products, according to search request, from fixture
22+
* Assert that result page contains product, according to search request from fixture.
2223
*
23-
* @param array $products
24+
* @param CatalogSearchQuery $catalogSearch
2425
* @param AdvancedResult $resultPage
2526
* @return void
2627
*/
27-
public function processAssert(array $products, AdvancedResult $resultPage)
28+
public function processAssert(CatalogSearchQuery $catalogSearch, AdvancedResult $resultPage)
2829
{
29-
$errors = [];
30-
foreach ($products as $product) {
31-
$name = $product->getName();
30+
$product = $catalogSearch->getDataFieldConfig('query_text')['source']->getProduct();
31+
$name = $product->getName();
32+
$isProductVisible = $resultPage->getListProductBlock()->isProductVisible($name);
33+
while (!$isProductVisible && $resultPage->getBottomToolbar()->nextPage()) {
3234
$isProductVisible = $resultPage->getListProductBlock()->isProductVisible($name);
33-
while (!$isProductVisible && $resultPage->getBottomToolbar()->nextPage()) {
34-
$isProductVisible = $resultPage->getListProductBlock()->isProductVisible($name);
35-
}
36-
37-
if ($isProductVisible === false) {
38-
$errors[] = '- ' . $name;
39-
}
4035
}
4136

42-
\PHPUnit_Framework_Assert::assertTrue(
43-
empty($errors),
44-
'Were not found the following products:' . implode("\n", $errors)
45-
);
37+
\PHPUnit_Framework_Assert::assertTrue($isProductVisible, "A product with name '$name' was not found.");
4638
}
4739

4840
/**
49-
* Returns a string representation of the object
41+
* Returns a string representation of the object.
5042
*
5143
* @return string
5244
*/
5345
public function toString()
5446
{
55-
return 'All products have been successfully found.';
47+
return 'Searched product has been successfully found.';
5648
}
5749
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
4+
*/
5+
6+
namespace Magento\CatalogSearch\Test\Constraint;
7+
8+
use Mtf\Constraint\AbstractConstraint;
9+
use Magento\CatalogSearch\Test\Page\AdvancedResult;
10+
use Magento\Catalog\Test\Page\Product\CatalogProductView;
11+
use Magento\CatalogSearch\Test\Fixture\CatalogSearchQuery;
12+
13+
/**
14+
* Assert product can be opened from search results page.
15+
*/
16+
class AssertProductCanBeOpenedFromSearchResult extends AbstractConstraint
17+
{
18+
/* tags */
19+
const SEVERITY = 'high';
20+
/* end tags */
21+
22+
/**
23+
* Assert product can be opened from search results page.
24+
*
25+
* @param CatalogSearchQuery $catalogSearch
26+
* @param AdvancedResult $resultPage
27+
* @param CatalogProductView $catalogProductViewPage
28+
* @return void
29+
*/
30+
public function processAssert(
31+
CatalogSearchQuery $catalogSearch,
32+
AdvancedResult $resultPage,
33+
CatalogProductView $catalogProductViewPage
34+
) {
35+
$product = $catalogSearch->getDataFieldConfig('query_text')['source']->getProduct();
36+
$productName = $product->getName();
37+
$isProductVisible = $resultPage->getListProductBlock()->isProductVisible($productName);
38+
while (!$isProductVisible && $resultPage->getBottomToolbar()->nextPage()) {
39+
$isProductVisible = $resultPage->getListProductBlock()->isProductVisible($productName);
40+
}
41+
\PHPUnit_Framework_Assert::assertTrue($isProductVisible, "A product with name $productName was not found.");
42+
43+
$resultPage->getListProductBlock()->openProductViewPage($productName);
44+
\PHPUnit_Framework_Assert::assertEquals(
45+
$productName,
46+
$catalogProductViewPage->getViewBlock()->getProductName(),
47+
'Wrong product page has been opened.'
48+
);
49+
}
50+
51+
/**
52+
* Returns a string representation of the object.
53+
*
54+
* @return string
55+
*/
56+
public function toString()
57+
{
58+
return 'Product can be opened from search results page.';
59+
}
60+
}

dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Fixture/CatalogSearchQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class CatalogSearchQuery extends InjectableFixture
4242
'is_required' => '',
4343
'default_value' => '',
4444
'input' => '',
45-
'source' => 'Magento\CatalogSearch\Test\Fixture\CatalogSearchQuery\SearchData',
45+
'source' => 'Magento\CatalogSearch\Test\Fixture\CatalogSearchQuery\QueryText',
4646
];
4747

4848
protected $num_results = [
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
4+
*/
5+
6+
namespace Magento\CatalogSearch\Test\Fixture\CatalogSearchQuery;
7+
8+
use Mtf\Fixture\FixtureFactory;
9+
use Mtf\Fixture\FixtureInterface;
10+
use Mtf\Fixture\InjectableFixture;
11+
12+
/**
13+
* Data to search for.
14+
* Possible templates:
15+
* - {value}
16+
* - {product}::{product_property_to_search}
17+
* - {product}::{product_dataSet}::{product_property_to_search}
18+
*/
19+
class QueryText implements FixtureInterface
20+
{
21+
/**
22+
* Entity to search.
23+
*
24+
* @var InjectableFixture
25+
*/
26+
protected $product;
27+
28+
/**
29+
* Resource data.
30+
*
31+
* @var string
32+
*/
33+
protected $data;
34+
35+
/**
36+
* @param FixtureFactory $fixtureFactory
37+
* @param array $params
38+
* @param array $data
39+
*/
40+
public function __construct(FixtureFactory $fixtureFactory, array $params, array $data = [])
41+
{
42+
$this->params = $params;
43+
$explodeValue = explode('::', $data['value']);
44+
if (!empty($explodeValue) && count($explodeValue) > 1) {
45+
$fixtureCode = $explodeValue[0];
46+
$dataSet = isset($explodeValue[2]) ? $explodeValue[1] : '';
47+
$searchValue = isset($explodeValue[2]) ? $explodeValue[2] : $explodeValue[1];
48+
$this->product = $fixtureFactory->createByCode($fixtureCode, ['dataSet' => $dataSet]);
49+
if (!$this->product->hasData('id')) {
50+
$this->product->persist();
51+
}
52+
if ($this->product->hasData($searchValue)) {
53+
$getProperty = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $searchValue)));
54+
$this->data = $this->product->$getProperty();
55+
} else {
56+
$this->data = $searchValue;
57+
}
58+
} else {
59+
$this->data = strval($data['value']);
60+
}
61+
}
62+
63+
/**
64+
* Persist custom selections products.
65+
*
66+
* @return void
67+
*/
68+
public function persist()
69+
{
70+
//
71+
}
72+
73+
/**
74+
* Return prepared data.
75+
*
76+
* @param string|null $key
77+
* @return string
78+
*
79+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
80+
*/
81+
public function getData($key = null)
82+
{
83+
return $this->data;
84+
}
85+
86+
/**
87+
* Return data set configuration settings.
88+
*
89+
* @return array
90+
*/
91+
public function getDataConfig()
92+
{
93+
return $this->params;
94+
}
95+
96+
/**
97+
* Get product fixture to search.
98+
*
99+
* @return InjectableFixture
100+
*/
101+
public function getProduct()
102+
{
103+
return $this->product;
104+
}
105+
}

dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Fixture/CatalogSearchQuery/SearchData.php

Lines changed: 0 additions & 75 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
4+
*/
5+
6+
namespace Magento\CatalogSearch\Test\TestCase;
7+
8+
use Magento\CatalogSearch\Test\Fixture\CatalogSearchQuery;
9+
use Magento\Cms\Test\Page\CmsIndex;
10+
use Mtf\TestCase\Injectable;
11+
12+
/**
13+
* Preconditions:
14+
* 1. All product types are created.
15+
*
16+
* Steps:
17+
* 1. Navigate to frontend on index page.
18+
* 2. Input test data into "search field" and press Enter key.
19+
* 3. Perform all assertions.
20+
*
21+
* @group Search_Frontend_(MX)
22+
* @ZephyrId MAGETWO-25095
23+
*/
24+
class SearchEntityResultsTest extends Injectable
25+
{
26+
/**
27+
* CMS index page.
28+
*
29+
* @var CmsIndex
30+
*/
31+
protected $cmsIndex;
32+
33+
/**
34+
* Inject data.
35+
*
36+
* @param CmsIndex $cmsIndex
37+
* @return void
38+
*/
39+
public function __inject(CmsIndex $cmsIndex)
40+
{
41+
$this->cmsIndex = $cmsIndex;
42+
}
43+
44+
/**
45+
* Run searching result test.
46+
*
47+
* @param CatalogSearchQuery $catalogSearch
48+
* @return void
49+
*/
50+
public function test(CatalogSearchQuery $catalogSearch)
51+
{
52+
$this->cmsIndex->open();
53+
$this->cmsIndex->getSearchBlock()->search($catalogSearch->getQueryText());
54+
}
55+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"description";"catalogSearch/data/query_text/value";"constraint";"tag"
2+
"MAGETWO-12420: Use Quick Search to Find the Product";"catalogProductSimple::default::sku";"","bamboo_plan:BAT"
3+
"Search simple product";"catalogProductSimple::default::simple";"assertCatalogSearchResult";""
4+
"Search virtual product";"catalogProductVirtual::default::virtual";"assertCatalogSearchResult";""
5+
"Search configurable product";"configurableProductInjectable::default::configurable";"assertCatalogSearchResult";""
6+
"Search downloadable product";"downloadableProductInjectable::default::downloadable";"assertCatalogSearchResult";""
7+
"Search grouped product";"groupedProductInjectable::default::grouped";"assertCatalogSearchResult";""
8+
"Search bundle dynamic product";"bundleProduct::bundle_dynamic_product::bundle";"assertCatalogSearchResult";""
9+
"Search fixed product";"bundleProduct::bundle_fixed_product::bundle";"assertCatalogSearchResult";""
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"catalogSearch/data/query_text/value";"catalogSearch/data/num_results";"constraint"
2-
"catalogProductSimple::getName";"-";"assertSuggestSearchingResult"
3-
"catalogProductSimple::getSku";"1";"assertSuggestSearchingResult"
2+
"catalogProductSimple::name";"-";"assertSuggestSearchingResult"
3+
"catalogProductSimple::sku";"1";"assertSuggestSearchingResult"

0 commit comments

Comments
 (0)