Skip to content

Commit 9581647

Browse files
author
Akimov, Alexander(aakimov)
committed
Merge pull request #556 from magento-mpi/pr-mpi-200416
[MPI] Bugfixes
2 parents ebba9e7 + 60ef67a commit 9581647

File tree

36 files changed

+1472
-165
lines changed

36 files changed

+1472
-165
lines changed

app/code/Magento/CheckoutAgreements/view/frontend/templates/additional_agreements.phtml

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,45 @@
66

77
// @codingStandardsIgnoreFile
88

9-
?>
10-
<?php
119
/**
1210
* @var $block \Magento\CheckoutAgreements\Block\Agreements
1311
*/
14-
?>
15-
<?php if (!$block->getAgreements()) {
12+
if (!$block->getAgreements()) {
1613
return;
17-
} ?>
18-
<ol id="checkout-agreements" class="agreements checkout items">
19-
<?php /** @var \Magento\CheckoutAgreements\Api\Data\AgreementInterface $agreement */ ?>
20-
<?php foreach ($block->getAgreements() as $agreement): ?>
21-
<li class="item">
22-
<div class="checkout-agreement-item-content"<?php echo($agreement->getContentHeight() ? ' style="height:' . $agreement->getContentHeight() . '"' : '')?>>
23-
<?php if ($agreement->getIsHtml()):?>
24-
<?php /* @escapeNotVerified */ echo $agreement->getContent() ?>
25-
<?php else:?>
26-
<?php echo nl2br($block->escapeHtml($agreement->getContent())) ?>
27-
<?php endif; ?>
28-
</div>
29-
<?php if($agreement->getMode() == \Magento\CheckoutAgreements\Model\AgreementModeOptions::MODE_MANUAL): ?>
30-
<div id="checkout-agreements-form-<?php /* @escapeNotVerified */ echo $agreement->getAgreementId()?>" class="field choice agree required">
31-
<input type="checkbox"
32-
id="agreement-<?php /* @escapeNotVerified */ echo $agreement->getAgreementId()?>"
33-
name="agreement[<?php /* @escapeNotVerified */ echo $agreement->getAgreementId()?>]"
34-
value="1"
35-
title="<?php echo $block->escapeHtml($agreement->getCheckboxText()) ?>"
36-
class="checkbox"
37-
data-validate="{required:true}"/>
38-
<label class="label" for="agreement-<?php /* @escapeNotVerified */ echo $agreement->getAgreementId()?>">
39-
<span><?php echo $agreement->getIsHtml() ? $agreement->getCheckboxText() : $block->escapeHtml($agreement->getCheckboxText()) ?></span>
40-
</label>
41-
</div>
42-
<?php elseif($agreement->getMode() == \Magento\CheckoutAgreements\Model\AgreementModeOptions::MODE_AUTO): ?>
43-
<div id="checkout-agreements-form-<?php /* @escapeNotVerified */ echo $agreement->getAgreementId()?>" class="field choice agree">
44-
<span><?php echo $agreement->getIsHtml() ? $agreement->getCheckboxText() : $block->escapeHtml($agreement->getCheckboxText()) ?></span>
45-
</div>
46-
<?php endif; ?>
47-
</li>
48-
<?php endforeach ?>
49-
</ol>
14+
}
15+
16+
/** @var \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Collection $argeementsCollection */
17+
$argeementsCollection = $block->getAgreements();
18+
$agreementMappedArray = [];
19+
/** @var \Magento\CheckoutAgreements\Model\Agreement $agreement */
20+
foreach ($argeementsCollection as $agreement) {
21+
if ($agreement->getIsActive()) {
22+
$agreementMappedArray[] = [
23+
'mode' => $agreement->getMode(),
24+
'agreementId' => $agreement->getAgreementId(),
25+
'checkboxText' => $agreement->getCheckboxText(),
26+
'content' => $agreement->getContent()
27+
];
28+
}
29+
}
30+
$agreementJson = json_encode($agreementMappedArray);
31+
?>
32+
33+
<div data-bind="scope: 'checkout-agreements-component-scope'" class="checkout-agreements-block">
34+
<!-- ko template: getTemplate() --><!-- /ko -->
35+
</div>
36+
<script type="text/x-magento-init">
37+
{
38+
"*": {
39+
"Magento_Ui/js/core/app": {
40+
"components": {
41+
"checkout-agreements-component-scope": {
42+
"component": "Magento_CheckoutAgreements/js/view/checkout-agreements",
43+
"agreements": <?php /* @noEscape */ echo $agreementJson; ?>,
44+
"isVisible": true
45+
}
46+
}
47+
}
48+
}
49+
}
50+
</script>

app/code/Magento/CheckoutAgreements/view/frontend/web/js/model/agreement-validator.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ define(
1111
],
1212
function ($) {
1313
'use strict';
14-
var agreementsConfig = window.checkoutConfig.checkoutAgreements;
14+
var checkoutConfig = window.checkoutConfig,
15+
agreementsConfig = checkoutConfig ? checkoutConfig.checkoutAgreements : {};
16+
1517
return {
1618
/**
1719
* Validate checkout agreements

app/code/Magento/CheckoutAgreements/view/frontend/web/js/view/checkout-agreements.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ define(
1111
],
1212
function (ko, $, Component, agreementsModal) {
1313
'use strict';
14-
var agreementsConfig = window.checkoutConfig.checkoutAgreements,
15-
agreementManualMode = 1;
14+
var checkoutConfig = window.checkoutConfig,
15+
agreementManualMode = 1,
16+
agreementsConfig = checkoutConfig ? checkoutConfig.checkoutAgreements : {};
1617

1718
return Component.extend({
1819
defaults: {

app/code/Magento/CheckoutAgreements/view/frontend/web/template/checkout/checkout-agreements.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66
-->
7-
<form data-role="checkout-agreements" method="post">
7+
<div data-role="checkout-agreements">
88
<div class="checkout-agreements" data-bind="visible: isVisible">
99
<!-- ko foreach: agreements -->
1010
<!-- ko if: ($parent.isAgreementRequired($data)) -->
@@ -15,8 +15,7 @@
1515
'name': 'agreement[' + agreementId + ']',
1616
'value': agreementId
1717
}"
18-
data-validate="{required:true}"
19-
>
18+
data-validate="{required:true}" />
2019
<label data-bind="attr: {'for': 'agreement_' + agreementId}">
2120
<button type="button"
2221
class="action action-show"
@@ -40,4 +39,4 @@
4039
<div class="checkout-agreements-item-content" data-bind="html: modalContent"></div>
4140
</div>
4241
</div>
43-
</form>
42+
</div>

app/code/Magento/Customer/Model/ResourceModel/Grid/Collection.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@
66

77
namespace Magento\Customer\Model\ResourceModel\Grid;
88

9+
use Magento\Customer\Ui\Component\DataProvider\Document;
910
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface as FetchStrategy;
1011
use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory;
1112
use Magento\Framework\Event\ManagerInterface as EventManager;
1213
use Psr\Log\LoggerInterface as Logger;
1314

1415
class Collection extends \Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult
1516
{
17+
/**
18+
* @inheritdoc
19+
*/
20+
protected $document = Document::class;
21+
1622
/**
1723
* Initialize dependencies.
1824
*
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Test\Unit\Ui\Component\DataProvider;
7+
8+
use Magento\Customer\Api\CustomerMetadataInterface;
9+
use Magento\Customer\Api\Data\AttributeMetadataInterface;
10+
use Magento\Customer\Api\Data\GroupInterface;
11+
use Magento\Customer\Api\Data\OptionInterface;
12+
use Magento\Customer\Api\GroupRepositoryInterface;
13+
use Magento\Customer\Ui\Component\DataProvider\Document;
14+
use Magento\Framework\Api\AttributeValue;
15+
use Magento\Framework\Api\AttributeValueFactory;
16+
use Magento\Sales\Model\Order\Invoice;
17+
use Magento\Store\Api\Data\WebsiteInterface;
18+
use Magento\Store\Model\StoreManagerInterface;
19+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
20+
21+
/**
22+
* Class DocumentTest
23+
*
24+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
25+
*/
26+
class DocumentTest extends \PHPUnit_Framework_TestCase
27+
{
28+
/**
29+
* @var GroupRepositoryInterface|MockObject
30+
*/
31+
private $groupRepository;
32+
33+
/**
34+
* @var AttributeValueFactory|MockObject
35+
*/
36+
private $attributeValueFactory;
37+
38+
/**
39+
* @var CustomerMetadataInterface|MockObject
40+
*/
41+
private $customerMetadata;
42+
43+
/**
44+
* @var StoreManagerInterface|MockObject
45+
*/
46+
private $storeManager;
47+
48+
/**
49+
* @var Document
50+
*/
51+
private $document;
52+
53+
protected function setUp()
54+
{
55+
$this->initAttributeValueFactoryMock();
56+
57+
$this->groupRepository = $this->getMockForAbstractClass(GroupRepositoryInterface::class);
58+
59+
$this->customerMetadata = $this->getMockForAbstractClass(CustomerMetadataInterface::class);
60+
61+
$this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class);
62+
63+
$this->document = new Document(
64+
$this->attributeValueFactory,
65+
$this->groupRepository,
66+
$this->customerMetadata,
67+
$this->storeManager
68+
);
69+
}
70+
71+
/**
72+
* @covers \Magento\Customer\Ui\Component\DataProvider\Document::getCustomAttribute
73+
*/
74+
public function testGetGenderAttribute()
75+
{
76+
$genderId = 1;
77+
$this->document->setData('gender', $genderId);
78+
79+
$this->groupRepository->expects(static::never())
80+
->method('getById');
81+
82+
$this->storeManager->expects(static::never())
83+
->method('getWebsites');
84+
85+
$metadata = $this->getMockForAbstractClass(AttributeMetadataInterface::class);
86+
87+
$this->customerMetadata->expects(static::once())
88+
->method('getAttributeMetadata')
89+
->willReturn($metadata);
90+
91+
$option = $this->getMockForAbstractClass(OptionInterface::class);
92+
93+
$metadata->expects(static::once())
94+
->method('getOptions')
95+
->willReturn([$genderId => $option]);
96+
97+
$option->expects(static::once())
98+
->method('getLabel')
99+
->willReturn('Male');
100+
101+
$attribute = $this->document->getCustomAttribute('gender');
102+
static::assertEquals('Male', $attribute->getValue());
103+
}
104+
105+
/**
106+
* @covers \Magento\Customer\Ui\Component\DataProvider\Document::getCustomAttribute
107+
*/
108+
public function testGetGroupAttribute()
109+
{
110+
$this->document->setData('group_id', 1);
111+
112+
$this->customerMetadata->expects(static::never())
113+
->method('getAttributeMetadata');
114+
115+
$this->storeManager->expects(static::never())
116+
->method('getWebsites');
117+
118+
$group = $this->getMockForAbstractClass(GroupInterface::class);
119+
120+
$this->groupRepository->expects(static::once())
121+
->method('getById')
122+
->willReturn($group);
123+
124+
$group->expects(static::once())
125+
->method('getCode')
126+
->willReturn('General');
127+
128+
$attribute = $this->document->getCustomAttribute('group_id');
129+
static::assertEquals('General', $attribute->getValue());
130+
}
131+
132+
/**
133+
* @covers \Magento\Customer\Ui\Component\DataProvider\Document::getCustomAttribute
134+
*/
135+
public function testGetWebsiteAttribute()
136+
{
137+
$websiteId = 1;
138+
$this->document->setData('website_id', $websiteId);
139+
140+
$this->groupRepository->expects(static::never())
141+
->method('getById');
142+
143+
$this->customerMetadata->expects(static::never())
144+
->method('getAttributeMetadata');
145+
146+
$website = $this->getMockForAbstractClass(WebsiteInterface::class);
147+
148+
$this->storeManager->expects(static::once())
149+
->method('getWebsites')
150+
->willReturn([$websiteId => $website]);
151+
152+
$website->expects(static::once())
153+
->method('getName')
154+
->willReturn('Main Website');
155+
156+
$attribute = $this->document->getCustomAttribute('website_id');
157+
static::assertEquals('Main Website', $attribute->getValue());
158+
}
159+
160+
/**
161+
* Create mock for attribute value factory
162+
* @return void
163+
*/
164+
private function initAttributeValueFactoryMock()
165+
{
166+
$this->attributeValueFactory = $this->getMockBuilder(AttributeValueFactory::class)
167+
->disableOriginalConstructor()
168+
->setMethods(['create'])
169+
->getMock();
170+
171+
$attributeValue = new AttributeValue();
172+
173+
$this->attributeValueFactory->expects(static::once())
174+
->method('create')
175+
->willReturn($attributeValue);
176+
}
177+
}

0 commit comments

Comments
 (0)