Skip to content

Commit 6e4b7ac

Browse files
MTO-136: [Test] Captcha on Contact Us form
- Defects fixed
1 parent 4d40985 commit 6e4b7ac

File tree

9 files changed

+133
-10
lines changed

9 files changed

+133
-10
lines changed

dev/tests/functional/tests/app/Magento/Captcha/Test/Block/Form/ContactUsFormWithCaptcha.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
use Magento\Mtf\Block\Form;
1010
use Magento\Mtf\Client\Locator;
11+
use Magento\Mtf\Fixture\FixtureInterface;
12+
use Magento\Mtf\Client\Element\SimpleElement;
1113

1214
/**
1315
* Form for "Contact Us" page with captcha.
@@ -74,4 +76,22 @@ public function sendComment()
7476
{
7577
$this->_rootElement->find($this->submit, Locator::SELECTOR_CSS)->click();
7678
}
79+
80+
/**
81+
* Fill the contact us form.
82+
*
83+
* @param FixtureInterface $fixture
84+
* @param SimpleElement|null $element
85+
* @return $this
86+
*/
87+
public function fill(FixtureInterface $fixture, SimpleElement $element = null)
88+
{
89+
$data = $fixture->getData();
90+
$data['firstname'] = $data['customer']['firstname'];
91+
$data['email'] = $data['customer']['email'];
92+
unset($data['customer']);
93+
$this->_fill($this->dataMapping($data), $element);
94+
95+
return $this;
96+
}
7797
}

dev/tests/functional/tests/app/Magento/Captcha/Test/Repository/Customer.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
<repository class="Magento\Customer\Test\Repository\Customer">
1010
<dataset name="contact_us_form_with_captcha">
1111
<field name="firstname" xsi:type="string">John</field>
12+
<field name="lastname" xsi:type="string">Doe</field>
1213
<field name="email" xsi:type="string">JohnDoe_%isolation%@example.com</field>
13-
<field name="comment" xsi:type="string">Some comment</field>
14-
<field name="captcha" xsi:type="string">111</field>
14+
<field name="password" xsi:type="string">123123^q</field>
15+
<field name="password_confirmation" xsi:type="string">123123^q</field>
1516
</dataset>
1617
</repository>
1718
</config>

dev/tests/functional/tests/app/Magento/Captcha/Test/TestCase/CaptchaOnContactUsTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use Magento\Mtf\TestCase\Injectable;
1010
use Magento\Mtf\TestStep\TestStepFactory;
1111
use Magento\Captcha\Test\Constraint\AssertCaptchaFieldOnContactUsForm;
12-
use Magento\Customer\Test\Fixture\Customer;
1312
use Magento\Contact\Test\Page\ContactIndex;
13+
use Magento\Contact\Test\Fixture\Comment;
1414

1515
/**
1616
* Preconditions:
@@ -74,12 +74,12 @@ public function __inject(
7474
/**
7575
* Test creation for send comment using the contact us form with captcha.
7676
*
77-
* @param Customer $customer
77+
* @param Comment $comment
7878
* @param null|string $configData
7979
* @return void
8080
*/
8181
public function test(
82-
Customer $customer,
82+
Comment $comment,
8383
$configData
8484
) {
8585
$this->configData = $configData;
@@ -92,7 +92,7 @@ public function test(
9292

9393
$this->contactIndex->open();
9494
$this->assertCaptcha->processAssertRegisterForm($this->contactIndex);
95-
$this->contactIndex->getFormWithCaptcha()->fill($customer);
95+
$this->contactIndex->getFormWithCaptcha()->fill($comment);
9696
$this->contactIndex->getFormWithCaptcha()->reloadCaptcha();
9797
$this->contactIndex->getFormWithCaptcha()->sendComment();
9898
}

dev/tests/functional/tests/app/Magento/Captcha/Test/TestCase/CaptchaOnContactUsTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
99
<testCase name="Magento\Captcha\Test\TestCase\CaptchaOnContactUsTest" summary="Check CAPTCHA on Contact Us Page" ticketId="MAGETWO-43609">
1010
<variation name="CaptchaOnContactUsTestVariation1">
11-
<data name="customer/dataset" xsi:type="string">contact_us_form_with_captcha</data>
11+
<data name="comment/dataset" xsi:type="string">comment_with_captcha</data>
1212
<data name="configData" xsi:type="string">captcha_storefront_contact_us</data>
1313
<constraint name="Magento\Contact\Test\Constraint\AssertContactUsSuccessMessage"/>
1414
</variation>

dev/tests/functional/tests/app/Magento/Contact/Test/Block/Form/Messages.php renamed to dev/tests/functional/tests/app/Magento/Contact/Test/Block/Messages.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
namespace Magento\Contact\Test\Block\Form;
7+
namespace Magento\Contact\Test\Block;
88

99
use Magento\Mtf\Block\Block;
1010

dev/tests/functional/tests/app/Magento/Contact/Test/Fixture/Customer.xml renamed to dev/tests/functional/tests/app/Magento/Contact/Test/Fixture/Comment.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/fixture.xsd">
9-
<fixture name="customer">
9+
<fixture name="comment"
10+
module="Magento_Contact"
11+
repository_class="Magento\Contact\Test\Repository\Comment"
12+
class="Magento\Contact\Test\Fixture\Comment">
1013
<field name="comment" is_required="0" />
14+
<field name="captcha" is_required="0" />
15+
<field name="customer" is_required="0" source="Magento\Contact\Test\Fixture\Comment\Customer"/>
1116
</fixture>
1217
</config>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Contact\Test\Fixture\Comment;
8+
9+
use Magento\Mtf\Fixture\DataSource;
10+
use Magento\Mtf\Fixture\FixtureFactory;
11+
12+
/**
13+
* Source for attribute field.
14+
*/
15+
class Customer extends DataSource
16+
{
17+
/**
18+
* Customer Fixtures.
19+
*
20+
* @var array
21+
*/
22+
private $customer;
23+
24+
/**
25+
* Fixture Factory instance.
26+
*
27+
* @var FixtureFactory
28+
*/
29+
private $fixtureFactory;
30+
31+
/**
32+
* Rought fixture field data.
33+
*
34+
* @var array
35+
*/
36+
private $fixtureData = null;
37+
38+
/**
39+
* @constructor
40+
* @param FixtureFactory $fixtureFactory
41+
* @param array $params
42+
* @param array|int $data
43+
*/
44+
public function __construct(
45+
FixtureFactory $fixtureFactory,
46+
array $params,
47+
$data = []
48+
) {
49+
$this->fixtureFactory = $fixtureFactory;
50+
$this->params = $params;
51+
$this->fixtureData = $data;
52+
}
53+
54+
/**
55+
* Return prepared data set.
56+
*
57+
* @param string $key [optional]
58+
* @return mixed
59+
* @throws \Exception
60+
*/
61+
public function getData($key = null)
62+
{
63+
if (empty($this->fixtureData)) {
64+
throw new \Exception("Data must be set");
65+
}
66+
67+
if (isset($this->fixtureData['dataset'])) {
68+
$customer = $this->fixtureFactory->createByCode('customer', $this->fixtureData);
69+
/** @var Customer $customer */
70+
if (!$customer->getId()) {
71+
$customer->persist();
72+
}
73+
$this->customer = $customer;
74+
}
75+
$this->data = $customer->getData();
76+
77+
return parent::getData($key);
78+
}
79+
}

dev/tests/functional/tests/app/Magento/Contact/Test/Page/ContactIndex.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/pages.xsd">
99
<page name="ContactIndex" mca="contact/index/index" module="Magento_Contact">
10-
<block name="messagesBlock" class="Magento\Contact\Test\Block\Form\Messages" locator=".messages" strategy="css selector"/>
10+
<block name="messagesBlock" class="Magento\Contact\Test\Block\Messages" locator=".messages" strategy="css selector"/>
1111
</page>
1212
</config>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" ?>
2+
<!--
3+
/**
4+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/Magento/Mtf/Repository/etc/repository.xsd">
9+
<repository class="Magento\Contact\Test\Repository\Comment">
10+
<dataset name="comment_with_captcha">
11+
<field name="comment" xsi:type="string">some comment</field>
12+
<field name="captcha" xsi:type="string">111</field>
13+
<field name="customer" xsi:type="array">
14+
<item name="dataset" xsi:type="string">contact_us_form_with_captcha</item>
15+
</field>
16+
</dataset>
17+
</repository>
18+
</config>

0 commit comments

Comments
 (0)