Skip to content

Commit 9ec1d8f

Browse files
committed
Merge pull request magento#6 from magento-qmt/develop
[Mavericks] Re-factor end-to-end search tests and fix symlinks while factory generation
2 parents ea7e61e + 9fa3655 commit 9ec1d8f

File tree

55 files changed

+1966
-275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1966
-275
lines changed

dev/tests/functional/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require": {
3-
"magento/mtf": "1.0.0-rc10",
3+
"magento/mtf": "1.0.0-rc11",
44
"php": ">=5.4.0",
55
"phpunit/phpunit": "4.1.0",
66
"phpunit/phpunit-selenium": ">=1.2",

dev/tests/functional/lib/Mtf/Util/Generate/Factory/AbstractFactory.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ protected function collectItems($type)
161161
} else {
162162
$dirIterator = new \RegexIterator(
163163
new \RecursiveIteratorIterator(
164-
new \RecursiveDirectoryIterator($filePath, \FilesystemIterator::SKIP_DOTS)
164+
new \RecursiveDirectoryIterator(
165+
$filePath,
166+
\FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS
167+
)
165168
),
166169
'/.php$/i'
167170
);
@@ -190,9 +193,10 @@ protected function _processItem(& $items, & $rewrites, $filename, $location, $pa
190193
{
191194
$filename = str_replace('\\', '/', $filename);
192195

193-
$classPath = str_replace(MTF_BP . '/' . $path . '/', '', $filename);
194-
$classPath = str_replace('.php', '', $classPath);
195-
$className = str_replace('/', '\\', $classPath);
196+
$posTestsPath = strpos($filename, $path);
197+
$posClassName = $posTestsPath + strlen($path);
198+
$classPath = str_replace('.php', '', $filename);
199+
$className = str_replace('/', '\\', substr($classPath, $posClassName));
196200

197201
$reflectionClass = new \ReflectionClass($className);
198202
if ($reflectionClass->isAbstract()) {

dev/tests/functional/phpunit.xml.dist

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
</arguments>
2626
</listener>
2727
<listener class="Mtf\System\Event\StateListener" />
28+
<listener class="Mtf\System\JUnit"/>
2829
</listeners>
2930

3031
<php>
@@ -38,6 +39,7 @@
3839
<env name="log_directory" value="var/log" />
3940
<env name="events_preset" value="base" />
4041
<env name="module_whitelist" value="Magento_Install" />
42+
<env name="report_file_name" value="test-cases-report.xml"/>
4143
</php>
4244

4345
</phpunit>

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Tree.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,11 @@ public function selectCategory(FixtureInterface $category, $fullPath = true)
121121
protected function prepareFullCategoryPath(CatalogCategory $category)
122122
{
123123
$path = [];
124-
$parentCategory = $category->getDataFieldConfig('parent_id')['source']->getParentCategory();
124+
$parentCategory = $category->hasData('parent_id')
125+
? $category->getDataFieldConfig('parent_id')['source']->getParentCategory()
126+
: null;
125127

126-
if ($parentCategory != null) {
128+
if ($parentCategory !== null) {
127129
$path = $this->prepareFullCategoryPath($parentCategory);
128130
}
129131
return array_filter(array_merge($path, [$category->getPath(), $category->getName()]));

dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogCategory/ParentId.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ParentId implements FixtureInterface
3838
public function __construct(FixtureFactory $fixtureFactory, array $params, $data = [])
3939
{
4040
$this->params = $params;
41-
if ($data['dataSet']) {
41+
if (isset($data['dataSet']) && $data['dataSet'] !== '-') {
4242
$this->parentCategory = $fixtureFactory->createByCode('catalogCategory', ['dataSet' => $data['dataSet']]);
4343
if (!$this->parentCategory->hasData('id')) {
4444
$this->parentCategory->persist();

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"addCategory";"category/data/parent_id/dataSet";"category/data/name";"category/data/url_key";"category/data/is_active";"category/data/description";"category/data/meta_title";"category/data/include_in_menu";"category/data/display_mode";"category/data/landing_page";"category/data/is_anchor";"category/data/available_product_listing_config";"category/data/available_sort_by/sort_0";"category/data/available_sort_by/sort_1";"category/data/available_sort_by/sort_2";"category/data/default_product_listing_config";"category/data/default_sort_by";"category/data/use_config_price_range";"category/data/layered_navigation_price_step";"category/data/category_products_data/preset";"category/data/category_products/dataSet";"constraint"
2-
"addRootCategory";"1";"RootCategory%isolation%";"RootCategory%isolation%";"Yes";"RootCategory Required ";"-";"-";"-";"-";"-";"No";"Position";"Name";"Price";"-";"-";"-";"-";"-";"-";"assertCategorySaveMessage, assertCategoryForm"
3-
"addRootCategory";"1";"RootCategory%isolation%";"RootCategory%isolation%";"Yes";"RootCategory All Fields ";"RootCategory Page Title";"Yes";"Static block and products";"Catalog Events Lister";"Yes";"No";"Position";"Name";"Price";"No";"Name";"No";"50";"-";"-";"assertCategorySaveMessage, assertCategoryForm"
2+
"addRootCategory";"-";"RootCategory%isolation%";"RootCategory%isolation%";"Yes";"RootCategory Required ";"-";"-";"-";"-";"-";"No";"Position";"Name";"Price";"-";"-";"-";"-";"-";"-";"assertCategorySaveMessage, assertCategoryForm"
3+
"addRootCategory";"-";"RootCategory%isolation%";"RootCategory%isolation%";"Yes";"RootCategory All Fields ";"RootCategory Page Title";"Yes";"Static block and products";"Catalog Events Lister";"Yes";"No";"Position";"Name";"Price";"No";"Name";"No";"50";"-";"-";"assertCategorySaveMessage, assertCategoryForm"
44
"addSubcategory";"default_category";"Subcategory%isolation%";"Subcategory%isolation%";"Yes";"Subcategory Required";"-";"-";"-";"-";"-";"Yes";"-";"-";"-";"-";"-";"-";"-";"-";"-";"assertCategorySaveMessage, assertCategoryForm, assertCategoryPage"
55
"addSubcategory";"default_category";"Subcategory%isolation%";"Subcategory%isolation%";"Yes";"Subcategory For Anchor Subcategory";"-";"Yes";"-";"-";"No";"Yes";"-";"-";"-";"Yes";"-";"Yes";"-";"default";"catalogProductSimple::default,catalogProductSimple::default";"assertCategorySaveMessage, assertCategoryForm, assertCategoryPage, assertCategoryForAssignedProducts"
66
"addSubcategory";"default_category";"Subcategory%isolation%";"Subcategory%isolation%";"Yes";"Anchor Subcategory All Fields";"Subcategory Page Title";"Yes";"Products only";"Catalog Events Lister";"Yes";"No";"Position";"Name";"Price";"No";"Price";"No";"50";"default";"catalogProductSimple::default,catalogProductSimple::default";"assertCategorySaveMessage, assertCategoryForm, assertCategoryPage, assertCategoryForAssignedProducts"

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

+12-20
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

+1-1
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 = [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
* @constructor
37+
* @param FixtureFactory $fixtureFactory
38+
* @param array $params
39+
* @param array $data
40+
*/
41+
public function __construct(FixtureFactory $fixtureFactory, array $params, array $data = [])
42+
{
43+
$this->params = $params;
44+
$explodeValue = explode('::', $data['value']);
45+
if (!empty($explodeValue) && count($explodeValue) > 1) {
46+
$fixtureCode = $explodeValue[0];
47+
$dataSet = isset($explodeValue[2]) ? $explodeValue[1] : '';
48+
$searchValue = isset($explodeValue[2]) ? $explodeValue[2] : $explodeValue[1];
49+
$this->product = $fixtureFactory->createByCode($fixtureCode, ['dataSet' => $dataSet]);
50+
if (!$this->product->hasData('id')) {
51+
$this->product->persist();
52+
}
53+
if ($this->product->hasData($searchValue)) {
54+
$getProperty = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $searchValue)));
55+
$this->data = $this->product->$getProperty();
56+
} else {
57+
$this->data = $searchValue;
58+
}
59+
} else {
60+
$this->data = strval($data['value']);
61+
}
62+
}
63+
64+
/**
65+
* Persist custom selections products.
66+
*
67+
* @return void
68+
*/
69+
public function persist()
70+
{
71+
//
72+
}
73+
74+
/**
75+
* Return prepared data.
76+
*
77+
* @param string|null $key
78+
* @return string
79+
*
80+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
81+
*/
82+
public function getData($key = null)
83+
{
84+
return $this->data;
85+
}
86+
87+
/**
88+
* Return data set configuration settings.
89+
*
90+
* @return array
91+
*/
92+
public function getDataConfig()
93+
{
94+
return $this->params;
95+
}
96+
97+
/**
98+
* Get product fixture to search.
99+
*
100+
* @return InjectableFixture
101+
*/
102+
public function getProduct()
103+
{
104+
return $this->product;
105+
}
106+
}

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

-75
This file was deleted.

0 commit comments

Comments
 (0)