Skip to content

Commit 8fd754d

Browse files
Merge branch 'MTO-136' into pr3
2 parents 4b608de + f73ccf1 commit 8fd754d

File tree

13 files changed

+549
-0
lines changed

13 files changed

+549
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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\Fixture\FixtureInterface;
12+
use Magento\Mtf\Client\Element\SimpleElement;
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+
* Click submit button.
72+
*
73+
* @return void
74+
*/
75+
public function sendComment()
76+
{
77+
$this->_rootElement->find($this->submit, Locator::SELECTOR_CSS)->click();
78+
}
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+
}
97+
}
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\Contact\Test\Page\ContactIndex;
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 ContactIndex $contactIndex
21+
* @return void
22+
*/
23+
public function processAssertRegisterForm(ContactIndex $contactIndex)
24+
{
25+
\PHPUnit_Framework_Assert::assertTrue(
26+
$contactIndex->getFormWithCaptcha()->isVisibleCaptcha(),
27+
'Captcha image is not displayed on the Contact Us page.'
28+
);
29+
30+
\PHPUnit_Framework_Assert::assertTrue(
31+
$contactIndex->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+
}
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="comment">
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="ContactIndex" mca="contact/index/index" module="Magento_Contact">
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: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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\Contact\Test\Page\ContactIndex;
13+
use Magento\Contact\Test\Fixture\Comment;
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 on "Contact Us" page.
37+
*
38+
* @var AssertCaptchaFieldOnContactUsForm
39+
*/
40+
private $assertCaptcha;
41+
42+
/**
43+
* ContactIndex page.
44+
*
45+
* @var ContactIndex
46+
*/
47+
private $contactIndex;
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 ContactIndex $contactIndex
62+
* @return void
63+
*/
64+
public function __inject(
65+
TestStepFactory $stepFactory,
66+
AssertCaptchaFieldOnContactUsForm $assertCaptcha,
67+
ContactIndex $contactIndex
68+
) {
69+
$this->stepFactory = $stepFactory;
70+
$this->assertCaptcha = $assertCaptcha;
71+
$this->contactIndex = $contactIndex;
72+
}
73+
74+
/**
75+
* Test creation for send comment using the contact us form with captcha.
76+
*
77+
* @param Comment $comment
78+
* @param null|string $configData
79+
* @return void
80+
*/
81+
public function test(
82+
Comment $comment,
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->contactIndex->open();
94+
$this->assertCaptcha->processAssertRegisterForm($this->contactIndex);
95+
$this->contactIndex->getFormWithCaptcha()->fill($comment);
96+
$this->contactIndex->getFormWithCaptcha()->reloadCaptcha();
97+
$this->contactIndex->getFormWithCaptcha()->sendComment();
98+
}
99+
100+
/**
101+
* Set default configuration.
102+
*
103+
* @return void
104+
*/
105+
public function tearDown()
106+
{
107+
$this->stepFactory->create(
108+
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
109+
['configData' => $this->configData, 'rollback' => true]
110+
)->run();
111+
}
112+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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="comment/data/comment" xsi:type="string">some comment</data>
12+
<data name="comment/data/captcha" xsi:type="string">111</data>
13+
<data name="comment/data/customer/dataset" xsi:type="string">default</data>
14+
<data name="configData" xsi:type="string">captcha_storefront_contact_us</data>
15+
<constraint name="Magento\Contact\Test\Constraint\AssertContactUsSuccessMessage"/>
16+
</variation>
17+
</testCase>
18+
</config>

0 commit comments

Comments
 (0)