forked from magento/magento2
/
GiftOptions.php
107 lines (98 loc) · 3.18 KB
/
GiftOptions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\GiftMessage\Test\Block\Cart;
use Magento\GiftMessage\Test\Fixture\GiftMessage;
use Magento\Mtf\Block\BlockFactory;
use Magento\Mtf\Block\Form;
use Magento\Mtf\Block\Mapper;
use Magento\Mtf\Client\BrowserInterface;
use Magento\Mtf\Client\Element\SimpleElement;
use Magento\Mtf\Fixture\FixtureFactory;
use Magento\Mtf\Util\ModuleResolver\SequenceSorterInterface;
/**
* Class GiftOptions
* Add gift options on checkout cart order level
*/
class GiftOptions extends Form
{
/**
* Selector for gift message on order form
*
* @var string
*/
protected $giftMessageOrderForm = ".gift-message fieldset";
/**
* Allow gift message on order level
*
* @var string
*/
protected $allowGiftOptions = '.title';
/**
* Selector for apply Gift Message button on item
*
* @var string
*/
protected $giftMessageOrderButton = ".action-update";
/**
* Selector for Gift Message Summary
*
* @var string
*/
protected $giftMessageSummary = ".gift-message-summary";
/**
* Fixture factory.
*
* @var FixtureFactory
*/
protected $fixtureFactory;
/**
* @param SimpleElement $element
* @param BlockFactory $blockFactory
* @param Mapper $mapper
* @param BrowserInterface $browser
* @param SequenceSorterInterface $sequenceSorter
* @param FixtureFactory $fixtureFactory
* @param array $config [optional]
*/
public function __construct(
SimpleElement $element,
BlockFactory $blockFactory,
Mapper $mapper,
BrowserInterface $browser,
SequenceSorterInterface $sequenceSorter,
FixtureFactory $fixtureFactory,
array $config = []
) {
parent::__construct($element, $blockFactory, $mapper, $browser, $sequenceSorter, $config);
$this->fixtureFactory = $fixtureFactory;
}
/**
* Fill gift message form on order level
*
* @param GiftMessage $giftMessage
* @return void
*/
public function fillGiftMessageOrder(GiftMessage $giftMessage)
{
/** @var \Magento\GiftMessage\Test\Block\Cart\GiftOptions\GiftMessageForm $giftMessageForm */
if ($giftMessage->getAllowGiftMessagesForOrder() === 'Yes') {
$this->_rootElement->find($this->allowGiftOptions)->click();
$giftMessageForm = $this->blockFactory->create(
\Magento\GiftMessage\Test\Block\Cart\GiftOptions\GiftMessageForm::class,
['element' => $this->_rootElement->find($this->giftMessageOrderForm)]
);
$formData = [
'sender' => $giftMessage->getSender(),
'recipient' => $giftMessage->getRecipient(),
'message' => $giftMessage->getMessage()
];
$formData = $this->fixtureFactory->createByCode('giftMessage', ['data' => $formData]);
$giftMessageForm->fill($formData);
$this->_rootElement->find($this->giftMessageOrderButton)->click();
$this->waitForElementVisible($this->giftMessageSummary);
}
}
}