Skip to content

Commit 92a2456

Browse files
MTO-102: [Test] Captcha on register customer
- Functional test implemented
1 parent 6e0a786 commit 92a2456

File tree

9 files changed

+360
-4
lines changed

9 files changed

+360
-4
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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\Client\Locator;
10+
use Magento\Customer\Test\Block\Form\Register;
11+
use Magento\Mtf\Client\ElementInterface;
12+
13+
/**
14+
* Form for storefront register customer with captcha.
15+
*/
16+
class RegisterFormWithCaptcha extends Register
17+
{
18+
/**
19+
* Captcha image selector.
20+
*
21+
* @var string
22+
*/
23+
private $captchaImage = '.captcha-img';
24+
25+
/**
26+
* Captcha reload button selector.
27+
*
28+
* @var string
29+
*/
30+
private $captchaReload = '.captcha-reload';
31+
32+
/**
33+
* Get captcha element visibility.
34+
*
35+
* @return bool
36+
*/
37+
public function isVisibleCaptcha()
38+
{
39+
return $this->_rootElement->find($this->captchaImage, Locator::SELECTOR_CSS)->isVisible();
40+
}
41+
42+
/**
43+
* Get captcha reload button element visibility.
44+
*
45+
* @return bool
46+
*/
47+
public function isVisibleCaptchaReloadButton()
48+
{
49+
return $this->_rootElement->find($this->captchaReload, Locator::SELECTOR_CSS)->isVisible();
50+
}
51+
52+
/**
53+
* Get captcha reload button element.
54+
*
55+
* @return ElementInterface
56+
*/
57+
public function getCaptchaReloadButton()
58+
{
59+
return $this->_rootElement->find($this->captchaReload, Locator::SELECTOR_CSS);
60+
}
61+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
<lastname />
12+
<email />
13+
<company />
14+
<telephone />
15+
<street>
16+
<selector>#street_1</selector>
17+
</street>
18+
<city />
19+
<region_id>
20+
<input>select</input>
21+
</region_id>
22+
<postcode />
23+
<country_id>
24+
<selector>#country</selector>
25+
<input>select</input>
26+
</country_id>
27+
<password />
28+
<confirmation />
29+
<is_subscribed>
30+
<input>checkbox</input>
31+
</is_subscribed>
32+
<password_confirmation>
33+
<selector>[name=password_confirmation]</selector>
34+
</password_confirmation>
35+
<captcha>
36+
<selector>[name='captcha[user_create]']</selector>
37+
</captcha>
38+
</fields>
39+
</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\Customer\Test\Page\CustomerAccountCreate;
10+
use Magento\Mtf\Constraint\AbstractConstraint;
11+
12+
/**
13+
* Assert captcha on storefront account register page.
14+
*/
15+
class AssertCaptchaFieldOnRegisterForm extends AbstractConstraint
16+
{
17+
/**
18+
* Assert captcha and reload button are visible on storefront account register page.
19+
*
20+
* @param CustomerAccountCreate $createAccountPage
21+
* @return void
22+
*/
23+
public function processAssertRegisterForm(CustomerAccountCreate $createAccountPage)
24+
{
25+
\PHPUnit_Framework_Assert::assertTrue(
26+
$createAccountPage->getRegisterFormWithCaptcha()->isVisibleCaptcha(),
27+
'Captcha image is not displayed on the storefront account register page.'
28+
);
29+
30+
\PHPUnit_Framework_Assert::assertTrue(
31+
$createAccountPage->getRegisterFormWithCaptcha()->isVisibleCaptchaReloadButton(),
32+
'Captcha reload button is not displayed on the storefront account register 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 displayed on the storefront account register page.';
44+
}
45+
}
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/fixture.xsd">
9+
<fixture name="customer">
10+
<field name="captcha" is_required="0" />
11+
</fixture>
12+
</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="CustomerAccountCreate">
10+
<block name="registerFormWithCaptcha" class="Magento\Captcha\Test\Block\Form\RegisterFormWithCaptcha" locator="#form-validate[novalidate='novalidate']" strategy="css selector"/>
11+
</page>
12+
</config>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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\Config\Test\Repository\ConfigData">
10+
<dataset name="captcha_storefront_register">
11+
<field name="customer/captcha/enable" xsi:type="array">
12+
<item name="scope_id" xsi:type="number">0</item>
13+
<item name="label" xsi:type="string">Yes</item>
14+
<item name="value" xsi:type="number">1</item>
15+
</field>
16+
<field name="customer/captcha/forms" xsi:type="array">
17+
<item name="scope_id" xsi:type="number">0</item>
18+
<item name="label" xsi:type="string">Create user</item>
19+
<item name="value" xsi:type="string">user_create</item>
20+
</field>
21+
<field name="customer/captcha/mode" xsi:type="array">
22+
<item name="scope_id" xsi:type="number">0</item>
23+
<item name="label" xsi:type="string">Always</item>
24+
<item name="value" xsi:type="string">always</item>
25+
</field>
26+
<field name="customer/captcha/length" xsi:type="array">
27+
<item name="scope" xsi:type="string">admin</item>
28+
<item name="scope_id" xsi:type="number">1</item>
29+
<item name="label" xsi:type="string"/>
30+
<item name="value" xsi:type="number">3</item>
31+
</field>
32+
<field name="customer/captcha/symbols" xsi:type="array">
33+
<item name="scope" xsi:type="string">admin</item>
34+
<item name="scope_id" xsi:type="number">1</item>
35+
<item name="label" xsi:type="string"/>
36+
<item name="value" xsi:type="number">1</item>
37+
</field>
38+
</dataset>
39+
<dataset name="captcha_storefront_register_rollback">
40+
<field name="customer/captcha/enable" xsi:type="array">
41+
<item name="scope" xsi:type="string">default</item>
42+
<item name="scope_id" xsi:type="number">1</item>
43+
<item name="label" xsi:type="string">No</item>
44+
<item name="value" xsi:type="number">0</item>
45+
</field>
46+
</dataset>
47+
</repository>
48+
</config>
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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\AssertCaptchaFieldOnRegisterForm;
12+
use Magento\Customer\Test\Fixture\Customer;
13+
use Magento\Customer\Test\Page\CustomerAccountCreate;
14+
use Magento\Mtf\Fixture\FixtureFactory;
15+
16+
/**
17+
* Preconditions:
18+
* 1. Enable CAPTCHA for customer.
19+
*
20+
* Test Flow:
21+
* 1. Open storefront account register form.
22+
* 2. Register customer using captcha.
23+
*
24+
* @group Captcha
25+
* @ZephyrId MAGETWO-43602
26+
*/
27+
class CaptchaOnStoreFrontRegisterTest extends Injectable
28+
{
29+
/**
30+
* Step factory.
31+
*
32+
* @var TestStepFactory
33+
*/
34+
private $stepFactory;
35+
36+
/**
37+
* Assert Captcha.
38+
*
39+
* @var AssertCaptchaFieldOnRegisterForm
40+
*/
41+
private $assertCaptcha;
42+
43+
/**
44+
* CustomerAccountCreate page.
45+
*
46+
* @var CustomerAccountCreate
47+
*/
48+
private $customerAccountCreate;
49+
50+
/**
51+
* Fixture factory.
52+
*
53+
* @var FixtureFactory
54+
*/
55+
private $fixtureFactory;
56+
57+
/**
58+
* Configuration setting.
59+
*
60+
* @var string
61+
*/
62+
private $configData;
63+
64+
/**
65+
* Injection data.
66+
*
67+
* @param TestStepFactory $stepFactory
68+
* @param AssertCaptchaFieldOnRegisterForm $assertCaptcha
69+
* @param CustomerAccountCreate $customerAccount
70+
* @param FixtureFactory $fixtureFactory
71+
* @return void
72+
*/
73+
public function __inject(
74+
TestStepFactory $stepFactory,
75+
AssertCaptchaFieldOnRegisterForm $assertCaptcha,
76+
CustomerAccountCreate $customerAccount,
77+
FixtureFactory $fixtureFactory
78+
) {
79+
$this->stepFactory = $stepFactory;
80+
$this->assertCaptcha = $assertCaptcha;
81+
$this->customerAccountCreate = $customerAccount;
82+
$this->fixtureFactory = $fixtureFactory;
83+
}
84+
85+
/**
86+
* Test creation for customer register with captcha on storefront.
87+
*
88+
* @param Customer $customer
89+
* @param null|string $configData
90+
* @return void
91+
*/
92+
public function test(
93+
Customer $customer,
94+
$configData
95+
) {
96+
$this->configData = $configData;
97+
98+
// Preconditions
99+
$this->stepFactory->create(
100+
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
101+
['configData' => $this->configData]
102+
)->run();
103+
104+
$this->customerAccountCreate->open();
105+
$this->assertCaptcha->processAssertRegisterForm($this->customerAccountCreate);
106+
$this->customerAccountCreate->getRegisterFormWithCaptcha()->getCaptchaReloadButton()->click();
107+
$this->customerAccountCreate->getRegisterFormWithCaptcha()->registerCustomer($customer);
108+
}
109+
110+
/**
111+
* Set default configuration.
112+
*
113+
* @return void
114+
*/
115+
public function tearDown()
116+
{
117+
$this->stepFactory->create(
118+
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
119+
['configData' => $this->configData, 'rollback' => true]
120+
)->run();
121+
}
122+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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\CaptchaOnStoreFrontRegisterTest" summary="Check CAPTCHA on StoreFront Register Page" ticketId="MAGETWO-43602">
10+
<variation name="CaptchaOnStoreFrontRegisterTestVariation1">
11+
<data name="customer/dataset" xsi:type="string">register_customer</data>
12+
<data name="customer/data/captcha" xsi:type="string">111</data>
13+
<data name="configData" xsi:type="string">captcha_storefront_register</data>
14+
<constraint name="Magento\Customer\Test\Constraint\AssertCustomerSuccessRegisterMessage"/>
15+
</variation>
16+
</testCase>
17+
</config>

dev/tests/functional/tests/app/Magento/Customer/Test/Page/CustomerAccountLogin.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/pages.xsd">
9-
<page name="CustomerAccountLogin" mca="customer/account/login" module="Magento_Customer">
10-
<block name="messages" class="Magento\Backend\Test\Block\Messages" locator=".page.messages" strategy="css selector"/>
11-
<block name="loginBlock" class="Magento\Customer\Test\Block\Form\Login" locator="#login-form" strategy="css selector"/>
12-
</page>
9+
<page name="CustomerAccountLogin" mca="customer/account/login" module="Magento_Customer">
10+
<block name="messages" class="Magento\Backend\Test\Block\Messages" locator=".page.messages" strategy="css selector"/>
11+
<block name="loginBlock" class="Magento\Customer\Test\Block\Form\Login" locator="#login-form" strategy="css selector"/>
12+
</page>
1313
</config>

0 commit comments

Comments
 (0)