Skip to content

Commit 4abfeb5

Browse files
MTO-136: [Test] Captcha on Contact Us form
- Defects fixed.
1 parent 175cda5 commit 4abfeb5

File tree

6 files changed

+40
-54
lines changed

6 files changed

+40
-54
lines changed

dev/tests/functional/tests/app/Magento/Backend/Test/Block/Messages.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,6 @@ class Messages extends Block
5656
*/
5757
protected $warningMessage = '[data-ui-id$=message-warning]';
5858

59-
/**
60-
* Selector for "This is a required field." validation error message.
61-
*
62-
* @var string
63-
*/
64-
private $validationErrorMessage = '.mage-error';
65-
6659
/**
6760
* Wait for success message.
6861
*
@@ -73,16 +66,6 @@ public function waitSuccessMessage()
7366
return $this->waitForElementVisible($this->successMessage, Locator::SELECTOR_CSS);
7467
}
7568

76-
/**
77-
* Wait for error message.
78-
*
79-
* @return bool
80-
*/
81-
public function waitValidationErrorMessage()
82-
{
83-
return $this->waitForElementVisible($this->validationErrorMessage, Locator::SELECTOR_CSS);
84-
}
85-
8669
/**
8770
* Get all success messages which are present on the page.
8871
*

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/View/CustomOptions.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ public function getOptions(FixtureInterface $product)
170170
return ['custom_options' => $result];
171171
}
172172

173+
/**
174+
* Wait for error message.
175+
*
176+
* @return bool
177+
*/
178+
public function waitValidationErrorMessage()
179+
{
180+
return $this->waitForElementVisible($this->validationErrorMessage, Locator::SELECTOR_XPATH);
181+
}
182+
173183
/**
174184
* Get list custom options
175185
*

dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/MoveCategoryEntityTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ public function test(
118118
* Get moved category tree.
119119
*
120120
* @param Category $movedCategory
121-
* @param Category $childCategory
122121
* @param Category $parentCategory
122+
* @param Category $childCategory
123123
* @return Category
124124
*/
125125
public function getMovedCategoryTree(Category $movedCategory, Category $parentCategory, Category $childCategory)

dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/AddProductsToShoppingCartEntityTest.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ public function test(
159159
$products = $this->prepareProducts($productsData);
160160

161161
// Steps
162-
$this->addToCart($products);
163-
$this->waitAddToCartMessage($isValidationFailed);
162+
$this->addToCart($products, $isValidationFailed);
164163

165164
$cart['data']['items'] = ['products' => $products];
166165
return [
@@ -190,32 +189,18 @@ protected function prepareProducts(array $productList)
190189
* Add products to cart.
191190
*
192191
* @param array $products
192+
* @param bool $isValidationFailed
193193
* @return void
194194
*/
195-
protected function addToCart(array $products)
195+
protected function addToCart(array $products, $isValidationFailed)
196196
{
197197
$addToCartStep = $this->testStepFactory->create(
198198
\Magento\Checkout\Test\TestStep\AddProductsToTheCartStep::class,
199-
['products' => $products]
199+
['products' => $products, 'isValidationFailed' => $isValidationFailed]
200200
);
201201
$addToCartStep->run();
202202
}
203203

204-
/**
205-
* Wait message after add product to cart.
206-
*
207-
* @param bool $isValidationFailed
208-
* @return void
209-
*/
210-
private function waitAddToCartMessage($isValidationFailed)
211-
{
212-
if ($isValidationFailed) {
213-
$this->catalogProductView->getMessagesBlock()->waitValidationErrorMessage();
214-
} else {
215-
$this->catalogProductView->getMessagesBlock()->waitSuccessMessage();
216-
}
217-
}
218-
219204
/**
220205
* Clean data after running test.
221206
*

dev/tests/functional/tests/app/Magento/Checkout/Test/TestStep/AddProductsToTheCartStep.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,38 @@ class AddProductsToTheCartStep implements TestStepInterface
6767
*/
6868
private $loadingSelector = '.loading-mask';
6969

70+
/**
71+
* Flag for validation result after add product to cart.
72+
*
73+
* @var bool
74+
*/
75+
private $isValidationFailed;
76+
7077
/**
7178
* @param CatalogProductView $catalogProductView
7279
* @param CheckoutCart $checkoutCart
7380
* @param CmsIndex $cmsIndex
7481
* @param BrowserInterface $browser
7582
* @param FixtureFactory $fixtureFactory
7683
* @param array $products
84+
* @param bool $isValidationFailed
7785
*/
7886
public function __construct(
7987
CatalogProductView $catalogProductView,
8088
CheckoutCart $checkoutCart,
8189
CmsIndex $cmsIndex,
8290
BrowserInterface $browser,
8391
FixtureFactory $fixtureFactory,
84-
array $products
92+
array $products,
93+
$isValidationFailed = false
8594
) {
8695
$this->catalogProductView = $catalogProductView;
8796
$this->checkoutCart = $checkoutCart;
8897
$this->cmsIndex = $cmsIndex;
8998
$this->browser = $browser;
9099
$this->fixtureFactory = $fixtureFactory;
91100
$this->products = $products;
101+
$this->isValidationFailed = $isValidationFailed;
92102
}
93103

94104
/**
@@ -105,6 +115,12 @@ public function run()
105115
$this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
106116
$this->catalogProductView->getViewBlock()->waitForElementNotVisible($this->loadingSelector);
107117
$this->catalogProductView->getViewBlock()->addToCart($product);
118+
119+
if ($this->isValidationFailed) {
120+
$this->catalogProductView->getCustomOptionsBlock()->waitValidationErrorMessage();
121+
} else {
122+
$this->catalogProductView->getMessagesBlock()->waitSuccessMessage();
123+
}
108124
}
109125
$cart['data']['items'] = ['products' => $this->products];
110126
return ['cart' => $this->fixtureFactory->createByCode('cart', $cart)];

dev/tests/functional/tests/app/Magento/Contact/Test/Fixture/Comment/Customer.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use Magento\Mtf\Fixture\DataSource;
1010
use Magento\Mtf\Fixture\FixtureFactory;
11-
use Magento\Mtf\Fixture\FixtureInterface;
11+
use Magento\Customer\Test\Fixture\Customer as CustomerFixture;
1212

1313
/**
1414
* Customer comment on contact page.
@@ -18,7 +18,7 @@ class Customer extends DataSource
1818
/**
1919
* Customer Fixture.
2020
*
21-
* @var FixtureInterface
21+
* @var CustomerFixture
2222
*/
2323
private $customer;
2424

@@ -29,13 +29,6 @@ class Customer extends DataSource
2929
*/
3030
private $fixtureFactory;
3131

32-
/**
33-
* Rought fixture field data.
34-
*
35-
* @var array
36-
*/
37-
private $fixtureData = null;
38-
3932
/**
4033
* @param FixtureFactory $fixtureFactory
4134
* @param array $params
@@ -48,7 +41,6 @@ public function __construct(
4841
) {
4942
$this->fixtureFactory = $fixtureFactory;
5043
$this->params = $params;
51-
$this->fixtureData = $data;
5244
$this->data = $data;
5345
}
5446

@@ -61,12 +53,13 @@ public function __construct(
6153
*/
6254
public function getData($key = null)
6355
{
64-
if (empty($this->fixtureData)) {
56+
if (empty($this->data)) {
6557
throw new \Exception("Data must be set");
6658
}
6759

68-
if (isset($this->fixtureData['dataset']) && !$this->customer) {
69-
$customer = $this->fixtureFactory->createByCode('customer', $this->fixtureData);
60+
if (isset($this->data['dataset']) && !$this->customer) {
61+
/** @var CustomerFixture $customer */
62+
$customer = $this->fixtureFactory->createByCode('customer', $this->data);
7063

7164
if (!$customer->getId()) {
7265
$customer->persist();
@@ -76,9 +69,8 @@ public function getData($key = null)
7669
$this->data = [
7770
'firstname' => $customer->getFirstname(),
7871
'email' => $customer->getEmail(),
79-
'telephone' => $customer->getEmail()
72+
'telephone' => $customer->hasData('telephone') ? $customer->getData('telephone') : ''
8073
];
81-
8274
}
8375

8476
return parent::getData($key);
@@ -87,7 +79,7 @@ public function getData($key = null)
8779
/**
8880
* Return customer.
8981
*
90-
* @return FixtureInterface
82+
* @return CustomerFixture
9183
*/
9284
public function getCustomer()
9385
{

0 commit comments

Comments
 (0)