Skip to content

Commit 7b5bb1f

Browse files
MTO-136: [Test] Captcha on Contact Us form
- Functional test implemented
1 parent b35e1d8 commit 7b5bb1f

File tree

12 files changed

+433
-0
lines changed

12 files changed

+433
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Captcha\Test\Block\Form;
8+
9+
use Magento\Mtf\Block\Form;
10+
use Magento\Mtf\Client\Locator;
11+
use Magento\Mtf\Client\ElementInterface;
12+
use Magento\Mtf\Fixture\FixtureInterface;
13+
14+
/**
15+
* Form for "Contact Us" page with captcha.
16+
*/
17+
class ContactUsFormWithCaptcha extends Form
18+
{
19+
/**
20+
* Submit form button.
21+
*
22+
* @var string
23+
*/
24+
private $submit = '.action.submit';
25+
26+
/**
27+
* Captcha image selector.
28+
*
29+
* @var string
30+
*/
31+
private $captchaImage = '.captcha-img';
32+
33+
/**
34+
* Captcha reload button selector.
35+
*
36+
* @var string
37+
*/
38+
private $captchaReload = '.captcha-reload';
39+
40+
/**
41+
* Get captcha element visibility.
42+
*
43+
* @return bool
44+
*/
45+
public function isVisibleCaptcha()
46+
{
47+
return $this->_rootElement->find($this->captchaImage, Locator::SELECTOR_CSS)->isVisible();
48+
}
49+
50+
/**
51+
* Get captcha reload button element visibility.
52+
*
53+
* @return bool
54+
*/
55+
public function isVisibleCaptchaReloadButton()
56+
{
57+
return $this->_rootElement->find($this->captchaReload, Locator::SELECTOR_CSS)->isVisible();
58+
}
59+
60+
/**
61+
* Click captcha reload button element.
62+
*
63+
* @return void
64+
*/
65+
public function reloadCaptcha()
66+
{
67+
$this->_rootElement->find($this->captchaReload, Locator::SELECTOR_CSS)->click();
68+
}
69+
70+
/**
71+
* Send comment.
72+
*
73+
* @param FixtureInterface $fixture
74+
* @return void
75+
*/
76+
public function sendComment(FixtureInterface $fixture)
77+
{
78+
$this->fill($fixture);
79+
$this->_rootElement->find($this->submit, Locator::SELECTOR_CSS)->click();
80+
}
81+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
<mapping strict="0">
9+
<fields>
10+
<firstname>
11+
<selector>input[name*=name]</selector>
12+
</firstname>
13+
<email />
14+
<telephone />
15+
<comment>
16+
<selector>#comment</selector>
17+
</comment>
18+
<captcha>
19+
<selector>[name='captcha[contact_us]']</selector>
20+
</captcha>
21+
</fields>
22+
</mapping>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Captcha\Test\Constraint;
8+
9+
use Magento\Captcha\Test\Page\ContactUs;
10+
use Magento\Mtf\Constraint\AbstractConstraint;
11+
12+
/**
13+
* Assert captcha on the Contact Us page.
14+
*/
15+
class AssertCaptchaFieldOnContactUsForm extends AbstractConstraint
16+
{
17+
/**
18+
* Assert captcha on the Contact Us page.
19+
*
20+
* @param ContactUs $contactUsPage
21+
* @return void
22+
*/
23+
public function processAssertRegisterForm(ContactUs $contactUsPage)
24+
{
25+
\PHPUnit_Framework_Assert::assertTrue(
26+
$contactUsPage->getFormWithCaptcha()->isVisibleCaptcha(),
27+
'Captcha image is not displayed on the Contact Us page.'
28+
);
29+
30+
\PHPUnit_Framework_Assert::assertTrue(
31+
$contactUsPage->getFormWithCaptcha()->isVisibleCaptchaReloadButton(),
32+
'Captcha reload button is not displayed on the Contact Us page.'
33+
);
34+
}
35+
36+
/**
37+
* Returns a string representation of the object.
38+
*
39+
* @return string
40+
*/
41+
public function toString()
42+
{
43+
return 'Captcha and reload button are present on the Contact Us page.';
44+
}
45+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/fixture.xsd">
99
<fixture name="customer">
1010
<field name="captcha" is_required="0" />
11+
<field name="comment" is_required="0" />
1112
</fixture>
1213
</config>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
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/etc/pages.xsd">
9+
<page name="ContactUs" mca="contact/index/index" module="Magento_Captcha">
10+
<block name="formWithCaptcha" class="Magento\Captcha\Test\Block\Form\ContactUsFormWithCaptcha" locator="#contact-form" strategy="css selector"/>
11+
</page>
12+
</config>

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,43 @@
4444
<item name="value" xsi:type="number">0</item>
4545
</field>
4646
</dataset>
47+
48+
<dataset name="captcha_storefront_contact_us">
49+
<field name="customer/captcha/enable" xsi:type="array">
50+
<item name="scope_id" xsi:type="number">0</item>
51+
<item name="label" xsi:type="string">Yes</item>
52+
<item name="value" xsi:type="number">1</item>
53+
</field>
54+
<field name="customer/captcha/forms" xsi:type="array">
55+
<item name="scope_id" xsi:type="number">0</item>
56+
<item name="label" xsi:type="string">Contact Us</item>
57+
<item name="value" xsi:type="string">contact_us</item>
58+
</field>
59+
<field name="customer/captcha/mode" xsi:type="array">
60+
<item name="scope_id" xsi:type="number">0</item>
61+
<item name="label" xsi:type="string">Always</item>
62+
<item name="value" xsi:type="string">always</item>
63+
</field>
64+
<field name="customer/captcha/length" xsi:type="array">
65+
<item name="scope" xsi:type="string">admin</item>
66+
<item name="scope_id" xsi:type="number">1</item>
67+
<item name="label" xsi:type="string"/>
68+
<item name="value" xsi:type="number">3</item>
69+
</field>
70+
<field name="customer/captcha/symbols" xsi:type="array">
71+
<item name="scope" xsi:type="string">admin</item>
72+
<item name="scope_id" xsi:type="number">1</item>
73+
<item name="label" xsi:type="string"/>
74+
<item name="value" xsi:type="number">1</item>
75+
</field>
76+
</dataset>
77+
<dataset name="captcha_storefront_contact_us_rollback">
78+
<field name="customer/captcha/enable" xsi:type="array">
79+
<item name="scope" xsi:type="string">default</item>
80+
<item name="scope_id" xsi:type="number">1</item>
81+
<item name="label" xsi:type="string">No</item>
82+
<item name="value" xsi:type="number">0</item>
83+
</field>
84+
</dataset>
4785
</repository>
4886
</config>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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\Customer\Test\Repository\Customer">
10+
<dataset name="contact_us_form_with_captcha">
11+
<field name="firstname" xsi:type="string">John</field>
12+
<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>
15+
</dataset>
16+
</repository>
17+
</config>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Captcha\Test\TestCase;
8+
9+
use Magento\Mtf\TestCase\Injectable;
10+
use Magento\Mtf\TestStep\TestStepFactory;
11+
use Magento\Captcha\Test\Constraint\AssertCaptchaFieldOnContactUsForm;
12+
use Magento\Customer\Test\Fixture\Customer;
13+
use Magento\Captcha\Test\Page\ContactUs;
14+
15+
/**
16+
* Preconditions:
17+
* 1. Enable CAPTCHA for customer.
18+
*
19+
* Test Flow:
20+
* 1. Open contact us page.
21+
* 2. Send comment using captcha.
22+
*
23+
* @group Captcha
24+
* @ZephyrId MAGETWO-43609
25+
*/
26+
class CaptchaOnContactUsTest extends Injectable
27+
{
28+
/**
29+
* Step factory.
30+
*
31+
* @var TestStepFactory
32+
*/
33+
private $stepFactory;
34+
35+
/**
36+
* Assert Captcha.
37+
*
38+
* @var AssertCaptchaFieldOnContactUsForm
39+
*/
40+
private $assertCaptcha;
41+
42+
/**
43+
* ContactUs page.
44+
*
45+
* @var ContactUs
46+
*/
47+
private $contactUs;
48+
49+
/**
50+
* Configuration setting.
51+
*
52+
* @var string
53+
*/
54+
private $configData;
55+
56+
/**
57+
* Injection data.
58+
*
59+
* @param TestStepFactory $stepFactory
60+
* @param AssertCaptchaFieldOnContactUsForm $assertCaptcha
61+
* @param ContactUs $contactUs
62+
* @return void
63+
*/
64+
public function __inject(
65+
TestStepFactory $stepFactory,
66+
AssertCaptchaFieldOnContactUsForm $assertCaptcha,
67+
ContactUs $contactUs
68+
) {
69+
$this->stepFactory = $stepFactory;
70+
$this->assertCaptcha = $assertCaptcha;
71+
$this->contactUs = $contactUs;
72+
}
73+
74+
/**
75+
* Test creation for send comment using the contact us form with captcha.
76+
*
77+
* @param Customer $customer
78+
* @param null|string $configData
79+
* @return void
80+
*/
81+
public function test(
82+
Customer $customer,
83+
$configData
84+
) {
85+
$this->configData = $configData;
86+
87+
// Preconditions
88+
$this->stepFactory->create(
89+
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
90+
['configData' => $this->configData]
91+
)->run();
92+
93+
$this->contactUs->open();
94+
$this->assertCaptcha->processAssertRegisterForm($this->contactUs);
95+
$this->contactUs->getFormWithCaptcha()->reloadCaptcha();
96+
$this->contactUs->getFormWithCaptcha()->sendComment($customer);
97+
}
98+
99+
/**
100+
* Set default configuration.
101+
*
102+
* @return void
103+
*/
104+
public function tearDown()
105+
{
106+
$this->stepFactory->create(
107+
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
108+
['configData' => $this->configData, 'rollback' => true]
109+
)->run();
110+
}
111+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
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/etc/variations.xsd">
9+
<testCase name="Magento\Captcha\Test\TestCase\CaptchaOnContactUsTest" summary="Check CAPTCHA on Contact Us Page" ticketId="MAGETWO-43609">
10+
<variation name="CaptchaOnContactUsTestVariation1">
11+
<data name="customer/dataset" xsi:type="string">contact_us_form_with_captcha</data>
12+
<data name="configData" xsi:type="string">captcha_storefront_contact_us</data>
13+
<constraint name="Magento\Contact\Test\Constraint\AssertContactUsSuccessMessage"/>
14+
</variation>
15+
</testCase>
16+
</config>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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\Block\Form;
8+
9+
use Magento\Mtf\Block\Form;
10+
11+
/**
12+
* Message block on "Contact Us" page.
13+
*/
14+
class Messages extends Form
15+
{
16+
/**
17+
* Message selector.
18+
*
19+
* @var string
20+
*/
21+
private $message = '[data-bind*="message.text"]';
22+
23+
/**
24+
* Get message which is present on the "Contact Us" page.
25+
*
26+
* @return string
27+
*/
28+
public function getMessage()
29+
{
30+
$this->waitForElementVisible($this->message);
31+
32+
return $this->_rootElement->find($this->message)->getText();
33+
}
34+
}

0 commit comments

Comments
 (0)