Skip to content

Commit

Permalink
Merge pull request #556 from magento-mpi/pr-mpi-200416
Browse files Browse the repository at this point in the history
[MPI] Bugfixes
  • Loading branch information
Akimov, Alexander(aakimov) committed Apr 22, 2016
2 parents ebba9e7 + 60ef67a commit 9581647
Show file tree
Hide file tree
Showing 36 changed files with 1,472 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,45 @@

// @codingStandardsIgnoreFile

?>
<?php
/**
* @var $block \Magento\CheckoutAgreements\Block\Agreements
*/
?>
<?php if (!$block->getAgreements()) {
if (!$block->getAgreements()) {
return;
} ?>
<ol id="checkout-agreements" class="agreements checkout items">
<?php /** @var \Magento\CheckoutAgreements\Api\Data\AgreementInterface $agreement */ ?>
<?php foreach ($block->getAgreements() as $agreement): ?>
<li class="item">
<div class="checkout-agreement-item-content"<?php echo($agreement->getContentHeight() ? ' style="height:' . $agreement->getContentHeight() . '"' : '')?>>
<?php if ($agreement->getIsHtml()):?>
<?php /* @escapeNotVerified */ echo $agreement->getContent() ?>
<?php else:?>
<?php echo nl2br($block->escapeHtml($agreement->getContent())) ?>
<?php endif; ?>
</div>
<?php if($agreement->getMode() == \Magento\CheckoutAgreements\Model\AgreementModeOptions::MODE_MANUAL): ?>
<div id="checkout-agreements-form-<?php /* @escapeNotVerified */ echo $agreement->getAgreementId()?>" class="field choice agree required">
<input type="checkbox"
id="agreement-<?php /* @escapeNotVerified */ echo $agreement->getAgreementId()?>"
name="agreement[<?php /* @escapeNotVerified */ echo $agreement->getAgreementId()?>]"
value="1"
title="<?php echo $block->escapeHtml($agreement->getCheckboxText()) ?>"
class="checkbox"
data-validate="{required:true}"/>
<label class="label" for="agreement-<?php /* @escapeNotVerified */ echo $agreement->getAgreementId()?>">
<span><?php echo $agreement->getIsHtml() ? $agreement->getCheckboxText() : $block->escapeHtml($agreement->getCheckboxText()) ?></span>
</label>
</div>
<?php elseif($agreement->getMode() == \Magento\CheckoutAgreements\Model\AgreementModeOptions::MODE_AUTO): ?>
<div id="checkout-agreements-form-<?php /* @escapeNotVerified */ echo $agreement->getAgreementId()?>" class="field choice agree">
<span><?php echo $agreement->getIsHtml() ? $agreement->getCheckboxText() : $block->escapeHtml($agreement->getCheckboxText()) ?></span>
</div>
<?php endif; ?>
</li>
<?php endforeach ?>
</ol>
}

/** @var \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Collection $argeementsCollection */
$argeementsCollection = $block->getAgreements();
$agreementMappedArray = [];
/** @var \Magento\CheckoutAgreements\Model\Agreement $agreement */
foreach ($argeementsCollection as $agreement) {
if ($agreement->getIsActive()) {
$agreementMappedArray[] = [
'mode' => $agreement->getMode(),
'agreementId' => $agreement->getAgreementId(),
'checkboxText' => $agreement->getCheckboxText(),
'content' => $agreement->getContent()
];
}
}
$agreementJson = json_encode($agreementMappedArray);
?>

<div data-bind="scope: 'checkout-agreements-component-scope'" class="checkout-agreements-block">
<!-- ko template: getTemplate() --><!-- /ko -->
</div>
<script type="text/x-magento-init">
{
"*": {
"Magento_Ui/js/core/app": {
"components": {
"checkout-agreements-component-scope": {
"component": "Magento_CheckoutAgreements/js/view/checkout-agreements",
"agreements": <?php /* @noEscape */ echo $agreementJson; ?>,
"isVisible": true
}
}
}
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ define(
],
function ($) {
'use strict';
var agreementsConfig = window.checkoutConfig.checkoutAgreements;
var checkoutConfig = window.checkoutConfig,
agreementsConfig = checkoutConfig ? checkoutConfig.checkoutAgreements : {};

return {
/**
* Validate checkout agreements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ define(
],
function (ko, $, Component, agreementsModal) {
'use strict';
var agreementsConfig = window.checkoutConfig.checkoutAgreements,
agreementManualMode = 1;
var checkoutConfig = window.checkoutConfig,
agreementManualMode = 1,
agreementsConfig = checkoutConfig ? checkoutConfig.checkoutAgreements : {};

return Component.extend({
defaults: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See COPYING.txt for license details.
*/
-->
<form data-role="checkout-agreements" method="post">
<div data-role="checkout-agreements">
<div class="checkout-agreements" data-bind="visible: isVisible">
<!-- ko foreach: agreements -->
<!-- ko if: ($parent.isAgreementRequired($data)) -->
Expand All @@ -15,8 +15,7 @@
'name': 'agreement[' + agreementId + ']',
'value': agreementId
}"
data-validate="{required:true}"
>
data-validate="{required:true}" />
<label data-bind="attr: {'for': 'agreement_' + agreementId}">
<button type="button"
class="action action-show"
Expand All @@ -40,4 +39,4 @@
<div class="checkout-agreements-item-content" data-bind="html: modalContent"></div>
</div>
</div>
</form>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@

namespace Magento\Customer\Model\ResourceModel\Grid;

use Magento\Customer\Ui\Component\DataProvider\Document;
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface as FetchStrategy;
use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory;
use Magento\Framework\Event\ManagerInterface as EventManager;
use Psr\Log\LoggerInterface as Logger;

class Collection extends \Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult
{
/**
* @inheritdoc
*/
protected $document = Document::class;

/**
* Initialize dependencies.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Test\Unit\Ui\Component\DataProvider;

use Magento\Customer\Api\CustomerMetadataInterface;
use Magento\Customer\Api\Data\AttributeMetadataInterface;
use Magento\Customer\Api\Data\GroupInterface;
use Magento\Customer\Api\Data\OptionInterface;
use Magento\Customer\Api\GroupRepositoryInterface;
use Magento\Customer\Ui\Component\DataProvider\Document;
use Magento\Framework\Api\AttributeValue;
use Magento\Framework\Api\AttributeValueFactory;
use Magento\Sales\Model\Order\Invoice;
use Magento\Store\Api\Data\WebsiteInterface;
use Magento\Store\Model\StoreManagerInterface;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
* Class DocumentTest
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class DocumentTest extends \PHPUnit_Framework_TestCase
{
/**
* @var GroupRepositoryInterface|MockObject
*/
private $groupRepository;

/**
* @var AttributeValueFactory|MockObject
*/
private $attributeValueFactory;

/**
* @var CustomerMetadataInterface|MockObject
*/
private $customerMetadata;

/**
* @var StoreManagerInterface|MockObject
*/
private $storeManager;

/**
* @var Document
*/
private $document;

protected function setUp()
{
$this->initAttributeValueFactoryMock();

$this->groupRepository = $this->getMockForAbstractClass(GroupRepositoryInterface::class);

$this->customerMetadata = $this->getMockForAbstractClass(CustomerMetadataInterface::class);

$this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class);

$this->document = new Document(
$this->attributeValueFactory,
$this->groupRepository,
$this->customerMetadata,
$this->storeManager
);
}

/**
* @covers \Magento\Customer\Ui\Component\DataProvider\Document::getCustomAttribute
*/
public function testGetGenderAttribute()
{
$genderId = 1;
$this->document->setData('gender', $genderId);

$this->groupRepository->expects(static::never())
->method('getById');

$this->storeManager->expects(static::never())
->method('getWebsites');

$metadata = $this->getMockForAbstractClass(AttributeMetadataInterface::class);

$this->customerMetadata->expects(static::once())
->method('getAttributeMetadata')
->willReturn($metadata);

$option = $this->getMockForAbstractClass(OptionInterface::class);

$metadata->expects(static::once())
->method('getOptions')
->willReturn([$genderId => $option]);

$option->expects(static::once())
->method('getLabel')
->willReturn('Male');

$attribute = $this->document->getCustomAttribute('gender');
static::assertEquals('Male', $attribute->getValue());
}

/**
* @covers \Magento\Customer\Ui\Component\DataProvider\Document::getCustomAttribute
*/
public function testGetGroupAttribute()
{
$this->document->setData('group_id', 1);

$this->customerMetadata->expects(static::never())
->method('getAttributeMetadata');

$this->storeManager->expects(static::never())
->method('getWebsites');

$group = $this->getMockForAbstractClass(GroupInterface::class);

$this->groupRepository->expects(static::once())
->method('getById')
->willReturn($group);

$group->expects(static::once())
->method('getCode')
->willReturn('General');

$attribute = $this->document->getCustomAttribute('group_id');
static::assertEquals('General', $attribute->getValue());
}

/**
* @covers \Magento\Customer\Ui\Component\DataProvider\Document::getCustomAttribute
*/
public function testGetWebsiteAttribute()
{
$websiteId = 1;
$this->document->setData('website_id', $websiteId);

$this->groupRepository->expects(static::never())
->method('getById');

$this->customerMetadata->expects(static::never())
->method('getAttributeMetadata');

$website = $this->getMockForAbstractClass(WebsiteInterface::class);

$this->storeManager->expects(static::once())
->method('getWebsites')
->willReturn([$websiteId => $website]);

$website->expects(static::once())
->method('getName')
->willReturn('Main Website');

$attribute = $this->document->getCustomAttribute('website_id');
static::assertEquals('Main Website', $attribute->getValue());
}

/**
* Create mock for attribute value factory
* @return void
*/
private function initAttributeValueFactoryMock()
{
$this->attributeValueFactory = $this->getMockBuilder(AttributeValueFactory::class)
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();

$attributeValue = new AttributeValue();

$this->attributeValueFactory->expects(static::once())
->method('create')
->willReturn($attributeValue);
}
}
Loading

0 comments on commit 9581647

Please sign in to comment.