diff --git a/app/code/Magento/Braintree/Model/PaymentMethod.php b/app/code/Magento/Braintree/Model/PaymentMethod.php index 8e14ed191e350097a62984c7570d667c149a077b..45171956e87bcf8832723f7b7dffeb90ea5f1f79 100644 --- a/app/code/Magento/Braintree/Model/PaymentMethod.php +++ b/app/code/Magento/Braintree/Model/PaymentMethod.php @@ -11,6 +11,7 @@ use \Braintree_Exception; use \Braintree_Transaction; use \Braintree_Result_Successful; use Magento\Framework\Exception\LocalizedException; +use Magento\Sales\Model\Order\Payment\Transaction; use Magento\Sales\Model\ResourceModel\Order\Payment\Transaction\CollectionFactory as TransactionCollectionFactory; use Magento\Sales\Model\Order\Payment\Transaction as PaymentTransaction; use Magento\Payment\Model\InfoInterface; @@ -648,6 +649,7 @@ class PaymentMethod extends \Magento\Payment\Model\Method\Cc } } + // transaction should be voided if it not settled $canVoid = ($transaction->status === \Braintree_Transaction::AUTHORIZED || $transaction->status === \Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT); $result = $canVoid @@ -655,6 +657,7 @@ class PaymentMethod extends \Magento\Payment\Model\Method\Cc : $this->braintreeTransaction->refund($transactionId, $amount); $this->_debug($this->_convertObjToArray($result)); if ($result->success) { + $payment->setTransactionId($transactionId . '-' . Transaction::TYPE_REFUND); $payment->setIsTransactionClosed(true); } else { throw new LocalizedException($this->errorHelper->parseBraintreeError($result)); diff --git a/app/code/Magento/Braintree/Test/Unit/Model/PaymentMethodTest.php b/app/code/Magento/Braintree/Test/Unit/Model/PaymentMethodTest.php index f8f0494c128672811a883a0f832ae464b5f663dc..e20af765062e3b3b0713c5732d5b67f8f3c279f3 100644 --- a/app/code/Magento/Braintree/Test/Unit/Model/PaymentMethodTest.php +++ b/app/code/Magento/Braintree/Test/Unit/Model/PaymentMethodTest.php @@ -8,6 +8,7 @@ namespace Magento\Braintree\Test\Unit\Model; use Magento\Braintree\Model\PaymentMethod; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; +use Magento\Sales\Model\Order\Payment\Transaction; use \Magento\Sales\Model\ResourceModel\Order\Payment\Transaction\CollectionFactory as TransactionCollectionFactory; use Magento\Framework\Exception\LocalizedException; use \Braintree_Result_Successful; @@ -2378,6 +2379,7 @@ class PaymentMethodTest extends \PHPUnit_Framework_TestCase $this->model->refund($paymentObject, $amount); $this->assertEquals(1, $paymentObject->getIsTransactionClosed()); + $this->assertEquals($refundTransactionId . '-' .Transaction::TYPE_REFUND, $paymentObject->getTransactionId()); } /** diff --git a/app/code/Magento/Braintree/view/adminhtml/templates/form.phtml b/app/code/Magento/Braintree/view/adminhtml/templates/form.phtml index c27901cd4e8704fc7fdf044e47b8cc40db1a7e40..5610e082e1715e36dcecc8f7cc241bf1aeee2798 100644 --- a/app/code/Magento/Braintree/view/adminhtml/templates/form.phtml +++ b/app/code/Magento/Braintree/view/adminhtml/templates/form.phtml @@ -133,7 +133,7 @@ $ccExpYear = $block->getInfoData('cc_exp_year'); </div> </fieldset> <?php endif; ?> - <?php if($_useVault): ?> + <?php if($useVault): ?> <fieldset class="admin__fieldset hide_if_token_selected"> <div id="<?php /* @noEscape */ echo $code; ?>_store_in_vault_div" style="text-align:left;" class=""> <input type="checkbox" title="<?php echo $block->escapeHtml(__('Save this card for future use')); ?>" diff --git a/app/code/Magento/Braintree/view/frontend/layout/braintree_paypal_review.xml b/app/code/Magento/Braintree/view/frontend/layout/braintree_paypal_review.xml index 1c7b14abfa13d308f65ec8ff17aa6042c42a1497..126f80a2e25e82ba2d4c82638fb13d035844481d 100644 --- a/app/code/Magento/Braintree/view/frontend/layout/braintree_paypal_review.xml +++ b/app/code/Magento/Braintree/view/frontend/layout/braintree_paypal_review.xml @@ -24,7 +24,7 @@ <block class="Magento\Framework\View\Element\Text\ListText" name="paypal.additional.actions"/> <block class="Magento\Paypal\Block\Express\Review\Details" name="paypal.express.review.details" as="details" template="express/review/details.phtml"> <block class="Magento\Framework\View\Element\RendererList" name="checkout.onepage.review.item.renderers" as="renderer.list"/> - <block class="Magento\Checkout\Block\Cart\Totals" name="paypal.express.review.details.totals" as="totals" template="onepage/review/totals.phtml"/> + <block class="Magento\Checkout\Block\Cart\Totals" name="paypal.express.review.details.totals" as="totals" template="checkout/onepage/review/totals.phtml"/> </block> <block class="Magento\CheckoutAgreements\Block\Agreements" name="paypal.express.review.details.agreements" as="agreements" template="Magento_CheckoutAgreements::additional_agreements.phtml"/> </block> diff --git a/app/code/Magento/Braintree/view/frontend/templates/creditcard/index.phtml b/app/code/Magento/Braintree/view/frontend/templates/creditcard/index.phtml index fd9ee17028bb6eae399fe70103f3f8e82933681f..467e2523e6162efa00389deb18ecfe9f5fa43f9a 100644 --- a/app/code/Magento/Braintree/view/frontend/templates/creditcard/index.phtml +++ b/app/code/Magento/Braintree/view/frontend/templates/creditcard/index.phtml @@ -19,7 +19,7 @@ $storedCards = $block->getCurrentCustomerStoredCards(); <?php endif; ?> </div> <?php echo $block->getLayout()->getMessagesBlock()->getGroupedHtml(); ?> -<?php if (count($_storedCards)): ?> +<?php if (count($storedCards)): ?> <table class="data-table" id="my-quotes-table"> <col width="1" /> <col width="1" /> diff --git a/app/code/Magento/Checkout/Block/Onepage.php b/app/code/Magento/Checkout/Block/Onepage.php index d298599319540e5cbdf5143567e4e04fda46246b..25cbb6081959d727fd6415fec3896657846faf93 100644 --- a/app/code/Magento/Checkout/Block/Onepage.php +++ b/app/code/Magento/Checkout/Block/Onepage.php @@ -5,15 +5,11 @@ */ namespace Magento\Checkout\Block; -use Magento\Checkout\Block\Checkout\LayoutProcessorInterface; -use Magento\Customer\Api\CustomerRepositoryInterface; -use Magento\Customer\Model\Address\Config as AddressConfig; - /** * Onepage checkout block * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Onepage extends \Magento\Checkout\Block\Onepage\AbstractOnepage +class Onepage extends \Magento\Framework\View\Element\Template { /** * @var \Magento\Framework\Data\Form\FormKey @@ -36,60 +32,25 @@ class Onepage extends \Magento\Checkout\Block\Onepage\AbstractOnepage protected $configProvider; /** - * @var array|Checkout\LayoutProcessorInterface[] + * @var array|\Magento\Checkout\Block\Checkout\LayoutProcessorInterface[] */ protected $layoutProcessors; /** * @param \Magento\Framework\View\Element\Template\Context $context - * @param \Magento\Directory\Helper\Data $directoryHelper - * @param \Magento\Framework\App\Cache\Type\Config $configCacheType - * @param \Magento\Customer\Model\Session $customerSession - * @param \Magento\Checkout\Model\Session $resourceSession - * @param \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory - * @param \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollectionFactory - * @param CustomerRepositoryInterface $customerRepository - * @param AddressConfig $addressConfig - * @param \Magento\Framework\App\Http\Context $httpContext - * @param \Magento\Customer\Model\Address\Mapper $addressMapper * @param \Magento\Framework\Data\Form\FormKey $formKey * @param \Magento\Checkout\Model\CompositeConfigProvider $configProvider - * @param LayoutProcessorInterface[] $layoutProcessors + * @param array $layoutProcessors * @param array $data - * @codeCoverageIgnore - * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( \Magento\Framework\View\Element\Template\Context $context, - \Magento\Directory\Helper\Data $directoryHelper, - \Magento\Framework\App\Cache\Type\Config $configCacheType, - \Magento\Customer\Model\Session $customerSession, - \Magento\Checkout\Model\Session $resourceSession, - \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory, - \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollectionFactory, - CustomerRepositoryInterface $customerRepository, - AddressConfig $addressConfig, - \Magento\Framework\App\Http\Context $httpContext, - \Magento\Customer\Model\Address\Mapper $addressMapper, \Magento\Framework\Data\Form\FormKey $formKey, \Magento\Checkout\Model\CompositeConfigProvider $configProvider, array $layoutProcessors = [], array $data = [] ) { - parent::__construct( - $context, - $directoryHelper, - $configCacheType, - $customerSession, - $resourceSession, - $countryCollectionFactory, - $regionCollectionFactory, - $customerRepository, - $addressConfig, - $httpContext, - $addressMapper, - $data - ); + parent::__construct($context, $data); $this->formKey = $formKey; $this->_isScopePrivate = true; $this->jsLayout = isset($data['jsLayout']) && is_array($data['jsLayout']) ? $data['jsLayout'] : []; diff --git a/app/code/Magento/Checkout/Block/Onepage/AbstractOnepage.php b/app/code/Magento/Checkout/Block/Onepage/AbstractOnepage.php deleted file mode 100644 index 6b4e92640ec7090878068aed4f6f6be55afee980..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/Block/Onepage/AbstractOnepage.php +++ /dev/null @@ -1,391 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Checkout\Block\Onepage; - -use Magento\Customer\Api\CustomerRepositoryInterface; -use Magento\Customer\Model\Address\Config as AddressConfig; -use Magento\Directory\Model\ResourceModel\Country\Collection; -use Magento\Directory\Model\ResourceModel\Region\Collection as RegionCollection; -use Magento\Framework\Exception\NoSuchEntityException; -use Magento\Quote\Model\Quote; - -/** - * One page common functionality block - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) - */ -abstract class AbstractOnepage extends \Magento\Framework\View\Element\Template -{ - /** - * @var \Magento\Framework\App\Cache\Type\Config - */ - protected $_configCacheType; - - /** - * @var \Magento\Customer\Api\Data\CustomerInterface - */ - protected $_customer; - - /** - * @var Quote - */ - protected $_quote; - - /** - * @var Collection - */ - protected $_countryCollection; - - /** - * @var RegionCollection - */ - protected $_regionCollection; - - /** - * @var mixed - */ - protected $_addressesCollection; - - /** - * @var \Magento\Checkout\Model\Session - */ - protected $_checkoutSession; - - /** - * @var \Magento\Directory\Model\ResourceModel\Region\CollectionFactory - */ - protected $_regionCollectionFactory; - - /** - * @var \Magento\Directory\Model\ResourceModel\Country\CollectionFactory - */ - protected $_countryCollectionFactory; - - /** - * @var \Magento\Directory\Helper\Data - */ - protected $directoryHelper; - - /** - * @var CustomerRepositoryInterface - */ - protected $customerRepository; - - /** - * @var \Magento\Customer\Model\Address\Config - */ - private $_addressConfig; - - /** - * @var \Magento\Framework\App\Http\Context - */ - protected $httpContext; - - /** - * @var \Magento\Customer\Model\Address\Mapper - */ - protected $addressMapper; - - /** - * @param \Magento\Framework\View\Element\Template\Context $context - * @param \Magento\Directory\Helper\Data $directoryHelper - * @param \Magento\Framework\App\Cache\Type\Config $configCacheType - * @param \Magento\Customer\Model\Session $customerSession - * @param \Magento\Checkout\Model\Session $resourceSession - * @param \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory - * @param \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollectionFactory - * @param CustomerRepositoryInterface $customerRepository - * @param AddressConfig $addressConfig - * @param \Magento\Framework\App\Http\Context $httpContext - * @param \Magento\Customer\Model\Address\Mapper $addressMapper - * @param array $data - * @SuppressWarnings(PHPMD.ExcessiveParameterList) - */ - public function __construct( - \Magento\Framework\View\Element\Template\Context $context, - \Magento\Directory\Helper\Data $directoryHelper, - \Magento\Framework\App\Cache\Type\Config $configCacheType, - \Magento\Customer\Model\Session $customerSession, - \Magento\Checkout\Model\Session $resourceSession, - \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory, - \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollectionFactory, - CustomerRepositoryInterface $customerRepository, - AddressConfig $addressConfig, - \Magento\Framework\App\Http\Context $httpContext, - \Magento\Customer\Model\Address\Mapper $addressMapper, - array $data = [] - ) { - $this->directoryHelper = $directoryHelper; - $this->_configCacheType = $configCacheType; - $this->_customerSession = $customerSession; - $this->_checkoutSession = $resourceSession; - $this->_countryCollectionFactory = $countryCollectionFactory; - $this->_regionCollectionFactory = $regionCollectionFactory; - $this->httpContext = $httpContext; - parent::__construct($context, $data); - $this->_isScopePrivate = true; - $this->customerRepository = $customerRepository; - $this->_addressConfig = $addressConfig; - $this->addressMapper = $addressMapper; - } - - /** - * Get config - * - * @param string $path - * @return string|null - */ - public function getConfig($path) - { - return $this->_scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); - } - - /** - * Get logged in customer - * - * @return \Magento\Customer\Api\Data\CustomerInterface - */ - protected function _getCustomer() - { - if (empty($this->_customer)) { - $this->_customer = $this->customerRepository->getById($this->_customerSession->getCustomerId()); - } - return $this->_customer; - } - - /** - * Retrieve checkout session model - * - * @return \Magento\Checkout\Model\Session - */ - public function getCheckout() - { - return $this->_checkoutSession; - } - - /** - * Retrieve sales quote model - * - * @return Quote - */ - public function getQuote() - { - if (empty($this->_quote)) { - $this->_quote = $this->getCheckout()->getQuote(); - } - return $this->_quote; - } - - /** - * @return bool - */ - public function isCustomerLoggedIn() - { - return $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH); - } - - /** - * @return Collection - * @removeCandidate - */ - public function getCountryCollection() - { - if (!$this->_countryCollection) { - $this->_countryCollection = $this->_countryCollectionFactory->create()->loadByStore(); - } - return $this->_countryCollection; - } - - /** - * @return RegionCollection - * @removeCandidate - */ - public function getRegionCollection() - { - if (!$this->_regionCollection) { - $this->_regionCollection = $this->_regionCollectionFactory->create()->addCountryFilter( - $this->getAddress()->getCountryId() - )->load(); - } - return $this->_regionCollection; - } - - /** - * @return int - * @removeCandidate - */ - public function customerHasAddresses() - { - try { - return count($this->_getCustomer()->getAddresses()); - } catch (NoSuchEntityException $e) { - return 0; - } - } - - /** - * @param string $type - * @return string - * @removeCandidate - */ - public function getAddressesHtmlSelect($type) - { - if ($this->isCustomerLoggedIn()) { - $options = []; - - try { - $addresses = $this->_getCustomer()->getAddresses(); - } catch (NoSuchEntityException $e) { - $addresses = []; - } - - foreach ($addresses as $address) { - $builtOutputAddressData = $this->addressMapper->toFlatArray($address); - $label = $this->_addressConfig - ->getFormatByCode(AddressConfig::DEFAULT_ADDRESS_FORMAT) - ->getRenderer() - ->renderArray($builtOutputAddressData); - - $options[] = ['value' => $address->getId(), 'label' => $label]; - } - - $addressId = $this->getAddress()->getCustomerAddressId(); - if (empty($addressId)) { - try { - if ($type == 'billing') { - $addressId = $this->_getCustomer()->getDefaultBilling(); - } else { - $addressId = $this->_getCustomer()->getDefaultShipping(); - } - } catch (NoSuchEntityException $e) { - // Do nothing - } - } - - $select = $this->getLayout()->createBlock('Magento\Framework\View\Element\Html\Select') - ->setName($type . '_address_id') - ->setId($type . ':address-select') - ->setClass('address-select') - ->setValue($addressId) - ->setOptions($options); - - $select->addOption('', __('New Address')); - - return $select->getHtml(); - } - return ''; - } - - /** - * @param string $type - * @return string - * @removeCandidate - */ - public function getCountryHtmlSelect($type) - { - $countryId = $this->getAddress()->getCountryId(); - if ($countryId === null) { - $countryId = $this->directoryHelper->getDefaultCountry(); - } - $select = $this->getLayout()->createBlock( - 'Magento\Framework\View\Element\Html\Select' - )->setName( - $type . '[country_id]' - )->setId( - $type . ':country_id' - )->setTitle( - __('Country') - )->setClass( - 'validate-select' - )->setValue( - $countryId - )->setOptions( - $this->getCountryOptions() - ); - return $select->getHtml(); - } - - /** - * @param string $type - * @return string - * @removeCandidate - */ - public function getRegionHtmlSelect($type) - { - $select = $this->getLayout()->createBlock( - 'Magento\Framework\View\Element\Html\Select' - )->setName( - $type . '[region]' - )->setId( - $type . ':region' - )->setTitle( - __('State/Province') - )->setClass( - 'required-entry validate-state' - )->setValue( - $this->getAddress()->getRegionId() - )->setOptions( - $this->getRegionCollection()->toOptionArray() - ); - - return $select->getHtml(); - } - - /** - * @return mixed - * @removeCandidate - */ - public function getCountryOptions() - { - $options = false; - $cacheId = 'DIRECTORY_COUNTRY_SELECT_STORE_' . $this->_storeManager->getStore()->getCode(); - if ($optionsCache = $this->_configCacheType->load($cacheId)) { - $options = unserialize($optionsCache); - } - - if ($options == false) { - $options = $this->getCountryCollection()->toOptionArray(); - $this->_configCacheType->save(serialize($options), $cacheId); - } - return $options; - } - - /** - * Get checkout steps codes - * - * @return string[] - * @removeCandidate - */ - protected function _getStepCodes() - { - return ['login', 'billing', 'shipping', 'shipping_method', 'payment', 'review']; - } - - /** - * Retrieve is allow and show block - * - * @return bool - * @removeCandidate - */ - public function isShow() - { - return true; - } - - /** - * Return the html text for shipping price - * - * @param \Magento\Quote\Model\Quote\Address\Rate $rate - * @return string - * @removeCandidate - */ - public function getShippingPriceHtml(\Magento\Quote\Model\Quote\Address\Rate $rate) - { - /** @var \Magento\Checkout\Block\Shipping\Price $block */ - $block = $this->getLayout()->getBlock('checkout.shipping.price'); - $block->setShippingRate($rate); - return $block->toHtml(); - } -} diff --git a/app/code/Magento/Checkout/Block/Onepage/Billing.php b/app/code/Magento/Checkout/Block/Onepage/Billing.php deleted file mode 100644 index 1aee1948f0f3518fd9480e9e2992db5fca543824..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/Block/Onepage/Billing.php +++ /dev/null @@ -1,235 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Checkout\Block\Onepage; - -use Magento\Customer\Api\CustomerRepositoryInterface; -use Magento\Customer\Model\Address\Config as AddressConfig; - -/** - * One page checkout status - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) - * @removeCandidate - */ -class Billing extends \Magento\Checkout\Block\Onepage\AbstractOnepage -{ - /** - * Sales Quote Billing Address instance - * - * @var \Magento\Quote\Model\Quote\Address - */ - protected $_address; - - /** - * Customer Taxvat Widget block - * - * @var \Magento\Customer\Block\Widget\Taxvat - */ - protected $_taxvat; - - /** - * @var \Magento\Quote\Model\Quote\AddressFactory - */ - protected $_addressFactory; - - /** - * @param \Magento\Framework\View\Element\Template\Context $context - * @param \Magento\Directory\Helper\Data $directoryHelper - * @param \Magento\Framework\App\Cache\Type\Config $configCacheType - * @param \Magento\Customer\Model\Session $customerSession - * @param \Magento\Checkout\Model\Session $resourceSession - * @param \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory - * @param \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollectionFactory - * @param CustomerRepositoryInterface $customerRepository - * @param AddressConfig $addressConfig - * @param \Magento\Framework\App\Http\Context $httpContext - * @param \Magento\Customer\Model\Address\Mapper $addressMapper - * @param \Magento\Quote\Model\Quote\AddressFactory $addressFactory - * @param array $data - * @SuppressWarnings(PHPMD.ExcessiveParameterList) - */ - public function __construct( - \Magento\Framework\View\Element\Template\Context $context, - \Magento\Directory\Helper\Data $directoryHelper, - \Magento\Framework\App\Cache\Type\Config $configCacheType, - \Magento\Customer\Model\Session $customerSession, - \Magento\Checkout\Model\Session $resourceSession, - \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory, - \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollectionFactory, - CustomerRepositoryInterface $customerRepository, - AddressConfig $addressConfig, - \Magento\Framework\App\Http\Context $httpContext, - \Magento\Customer\Model\Address\Mapper $addressMapper, - \Magento\Quote\Model\Quote\AddressFactory $addressFactory, - array $data = [] - ) { - $this->_addressFactory = $addressFactory; - parent::__construct( - $context, - $directoryHelper, - $configCacheType, - $customerSession, - $resourceSession, - $countryCollectionFactory, - $regionCollectionFactory, - $customerRepository, - $addressConfig, - $httpContext, - $addressMapper, - $data - ); - $this->_isScopePrivate = true; - } - - /** - * Initialize billing address step - * - * @return void - */ - protected function _construct() - { - $this->getCheckout()->setStepData( - 'billing', - ['label' => __('Billing Information'), 'is_show' => $this->isShow()] - ); - - if ($this->isCustomerLoggedIn()) { - $this->getCheckout()->setStepData('billing', 'allow', true); - } - parent::_construct(); - } - - /** - * @return bool - */ - public function isUseBillingAddressForShipping() - { - if ($this->getQuote()->getIsVirtual() || !$this->getQuote()->getShippingAddress()->getSameAsBilling()) { - return false; - } - return true; - } - - /** - * Return country collection - * - * @return \Magento\Directory\Model\ResourceModel\Country\Collection - */ - public function getCountries() - { - return $this->_countryCollectionFactory->create()->loadByStore(); - } - - /** - * Return checkout method - * - * @return string - */ - public function getMethod() - { - return $this->getQuote()->getCheckoutMethod(); - } - - /** - * Return Sales Quote Address model - * - * @return \Magento\Quote\Model\Quote\Address - */ - public function getAddress() - { - if ($this->_address === null) { - if ($this->isCustomerLoggedIn()) { - $this->_address = $this->getQuote()->getBillingAddress(); - if (!$this->_address->getFirstname()) { - $this->_address->setFirstname($this->getQuote()->getCustomer()->getFirstname()); - } - if (!$this->_address->getLastname()) { - $this->_address->setLastname($this->getQuote()->getCustomer()->getLastname()); - } - } else { - $this->_address = $this->_addressFactory->create(); - } - } - - return $this->_address; - } - - /** - * Return Customer Address First Name - * If Sales Quote Address First Name is not defined - return Customer First Name - * - * @return string - */ - public function getFirstname() - { - return $this->getAddress()->getFirstname(); - } - - /** - * Return Customer Address Last Name - * If Sales Quote Address Last Name is not defined - return Customer Last Name - * - * @return string - */ - public function getLastname() - { - return $this->getAddress()->getLastname(); - } - - /** - * Check is Quote items can ship to - * - * @return bool - */ - public function canShip() - { - return !$this->getQuote()->isVirtual(); - } - - /** - * @return void - */ - public function getSaveUrl() - { - } - - /** - * Get Customer Taxvat Widget block - * - * @return \Magento\Customer\Block\Widget\Taxvat - */ - protected function _getTaxvat() - { - if (!$this->_taxvat) { - $this->_taxvat = $this->getLayout()->createBlock('Magento\Customer\Block\Widget\Taxvat'); - } - - return $this->_taxvat; - } - - /** - * Check whether taxvat is enabled - * - * @return bool - */ - public function isTaxvatEnabled() - { - return $this->_getTaxvat()->isEnabled(); - } - - /** - * @return string - */ - public function getTaxvatHtml() - { - return $this->_getTaxvat()->setTaxvat( - $this->getQuote()->getCustomerTaxvat() - )->setFieldIdFormat( - 'billing:%s' - )->setFieldNameFormat( - 'billing[%s]' - )->toHtml(); - } -} diff --git a/app/code/Magento/Checkout/Block/Onepage/Payment.php b/app/code/Magento/Checkout/Block/Onepage/Payment.php deleted file mode 100644 index 4298784226ae932e3c74dea26f35d79cf082b1eb..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/Block/Onepage/Payment.php +++ /dev/null @@ -1,69 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Checkout\Block\Onepage; - -/** - * One page checkout status - * - * @author Magento Core Team <core@magentocommerce.com> - * @removeCandidate - */ -class Payment extends \Magento\Checkout\Block\Onepage\AbstractOnepage -{ - /** - * @return void - */ - protected function _construct() - { - $this->getCheckout()->setStepData( - 'payment', - ['label' => __('Payment Information'), 'is_show' => $this->isShow()] - ); - parent::_construct(); - } - - /** - * Getter - * - * @return float - */ - public function getQuoteBaseGrandTotal() - { - return (double)$this->getQuote()->getBaseGrandTotal(); - } - - /** - * Get options - * - * @return array - */ - public function getOptions() - { - $registerParam = $this->getRequest()->getParam('register'); - return [ - 'quoteBaseGrandTotal' => $this->getQuoteBaseGrandTotal(), - 'progressUrl' => $this->getUrl('checkout/onepage/progress'), - 'reviewUrl' => $this->getUrl('checkout/onepage/review'), - 'failureUrl' => $this->getUrl('checkout/cart'), - 'getAddressUrl' => $this->getUrl('checkout/onepage/getAddress') . 'address/', - 'checkout' => [ - 'suggestRegistration' => $registerParam || $registerParam === '', - 'saveUrl' => $this->getUrl('checkout/onepage/saveMethod'), - ], - 'billing' => ['saveUrl' => $this->getUrl('checkout/onepage/saveBilling')], - 'shipping' => ['saveUrl' => $this->getUrl('checkout/onepage/saveShipping')], - 'shippingMethod' => ['saveUrl' => $this->getUrl('checkout/onepage/saveShippingMethod')], - 'payment' => [ - 'defaultPaymentMethod' => $this->getChildBlock('methods')->getSelectedMethodCode(), - 'saveUrl' => $this->getUrl('checkout/onepage/savePayment'), - ], - 'review' => [ - 'saveUrl' => $this->getUrl('checkout/onepage/saveOrder'), - 'successUrl' => $this->getUrl('checkout/onepage/success'), - ] - ]; - } -} diff --git a/app/code/Magento/Checkout/Block/Onepage/Payment/Info.php b/app/code/Magento/Checkout/Block/Onepage/Payment/Info.php deleted file mode 100644 index 67f682a25c19d95c37798e534a75376a8f7c2b49..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/Block/Onepage/Payment/Info.php +++ /dev/null @@ -1,63 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Checkout\Block\Onepage\Payment; - -/** - * Checkout payment information data - * - * @author Magento Core Team <core@magentocommerce.com> - * @removeCandidate - */ -class Info extends \Magento\Payment\Block\Info\AbstractContainer -{ - /** - * @var \Magento\Checkout\Model\Session - */ - protected $_checkoutSession; - - /** - * @param \Magento\Framework\View\Element\Template\Context $context - * @param \Magento\Payment\Helper\Data $paymentData - * @param \Magento\Checkout\Model\Session $checkoutSession - * @param array $data - */ - public function __construct( - \Magento\Framework\View\Element\Template\Context $context, - \Magento\Payment\Helper\Data $paymentData, - \Magento\Checkout\Model\Session $checkoutSession, - array $data = [] - ) { - $this->_checkoutSession = $checkoutSession; - parent::__construct($context, $paymentData, $data); - $this->_isScopePrivate = true; - } - - /** - * Retrieve payment info model - * - * @return \Magento\Payment\Model\Info|false - */ - public function getPaymentInfo() - { - $info = $this->_checkoutSession->getQuote()->getPayment(); - if ($info->getMethod()) { - return $info; - } - return false; - } - - /** - * @return string - */ - protected function _toHtml() - { - $html = ''; - if ($block = $this->getChildBlock($this->_getInfoBlockName())) { - $html = $block->toHtml(); - } - return $html; - } -} diff --git a/app/code/Magento/Checkout/Block/Onepage/Payment/Methods.php b/app/code/Magento/Checkout/Block/Onepage/Payment/Methods.php deleted file mode 100644 index 48285ad73dc277fa9890d46e7fa758246d5865e0..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/Block/Onepage/Payment/Methods.php +++ /dev/null @@ -1,113 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -/** - * One page checkout status - * - * @author Magento Core Team <core@magentocommerce.com> - * @removeCandidate - */ -namespace Magento\Checkout\Block\Onepage\Payment; - -class Methods extends \Magento\Payment\Block\Form\Container -{ - /** - * @var \Magento\Checkout\Model\Session - */ - protected $_checkoutSession; - - /** - * @param \Magento\Framework\View\Element\Template\Context $context - * @param \Magento\Payment\Helper\Data $paymentHelper - * @param \Magento\Payment\Model\Checks\SpecificationFactory $methodSpecificationFactory - * @param \Magento\Checkout\Model\Session $checkoutSession - * @param array $data - */ - public function __construct( - \Magento\Framework\View\Element\Template\Context $context, - \Magento\Payment\Helper\Data $paymentHelper, - \Magento\Payment\Model\Checks\SpecificationFactory $methodSpecificationFactory, - \Magento\Checkout\Model\Session $checkoutSession, - array $data = [] - ) { - $this->_checkoutSession = $checkoutSession; - parent::__construct($context, $paymentHelper, $methodSpecificationFactory, $data); - $this->_isScopePrivate = true; - } - - /** - * @return \Magento\Quote\Model\Quote - */ - public function getQuote() - { - return $this->_checkoutSession->getQuote(); - } - - /** - * Check payment method model - * - * @param \Magento\Payment\Model\MethodInterface $method - * @return bool - */ - protected function _canUseMethod($method) - { - return $method && $method->canUseCheckout() && parent::_canUseMethod($method); - } - - /** - * Retrieve code of current payment method - * - * @return mixed - */ - public function getSelectedMethodCode() - { - $method = $this->getQuote()->getPayment()->getMethod(); - if ($method) { - return $method; - } - return false; - } - - /** - * Payment method form html getter - * - * @param \Magento\Payment\Model\MethodInterface $method - * @return string - */ - public function getPaymentMethodFormHtml(\Magento\Payment\Model\MethodInterface $method) - { - return $this->getChildHtml('payment.method.' . $method->getCode()); - } - - /** - * Return method title for payment selection page - * - * @param \Magento\Payment\Model\MethodInterface $method - * @return string - */ - public function getMethodTitle(\Magento\Payment\Model\MethodInterface $method) - { - $form = $this->getChildBlock('payment.method.' . $method->getCode()); - if ($form && $form->hasMethodTitle()) { - return $form->getMethodTitle(); - } - return $method->getTitle(); - } - - /** - * Payment method additional label part getter - * - * @param \Magento\Payment\Model\MethodInterface $method - * @return string - */ - public function getMethodLabelAfterHtml(\Magento\Payment\Model\MethodInterface $method) - { - $form = $this->getChildBlock('payment.method.' . $method->getCode()); - if ($form) { - return $form->getMethodLabelAfterHtml(); - } - } -} diff --git a/app/code/Magento/Checkout/Block/Onepage/Review/Button.php b/app/code/Magento/Checkout/Block/Onepage/Review/Button.php deleted file mode 100644 index 39cba9ffce7470f1f0508fc8503fed741cf84341..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/Block/Onepage/Review/Button.php +++ /dev/null @@ -1,29 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Checkout\Block\Onepage\Review; - -use Magento\Framework\View\Element\Template; - -/** - * One page checkout order review button - * @removeCandidate - */ -class Button extends Template -{ - /** - * {@inheritdoc} - * - * @param string $template - * @return $this - */ - public function setTemplate($template) - { - if (!empty($template)) { - parent::setTemplate($template); - } - return $this; - } -} diff --git a/app/code/Magento/Checkout/Block/Onepage/Review/Info.php b/app/code/Magento/Checkout/Block/Onepage/Review/Info.php deleted file mode 100644 index 9adbc1c4e5ed140507e0c613ae8bd66c13ea7b6b..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/Block/Onepage/Review/Info.php +++ /dev/null @@ -1,49 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Checkout\Block\Onepage\Review; - -/** - * One page checkout order review - * @removeCandidate - */ -class Info extends \Magento\Sales\Block\Items\AbstractItems -{ - /** - * @var \Magento\Checkout\Model\Session - */ - protected $_checkoutSession; - - /** - * @param \Magento\Framework\View\Element\Template\Context $context - * @param \Magento\Checkout\Model\Session $checkoutSession - * @param array $data - */ - public function __construct( - \Magento\Framework\View\Element\Template\Context $context, - \Magento\Checkout\Model\Session $checkoutSession, - array $data = [] - ) { - $this->_checkoutSession = $checkoutSession; - parent::__construct($context, $data); - $this->_isScopePrivate = true; - } - - /** - * @return array - */ - public function getItems() - { - return $this->_checkoutSession->getQuote()->getAllVisibleItems(); - } - - /** - * @return array - */ - public function getTotals() - { - return $this->_checkoutSession->getQuote()->getTotals(); - } -} diff --git a/app/code/Magento/Checkout/Block/Onepage/Shipping.php b/app/code/Magento/Checkout/Block/Onepage/Shipping.php deleted file mode 100644 index d8dcad11e01c0e50a726c2f85e2f1a10165ac12c..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/Block/Onepage/Shipping.php +++ /dev/null @@ -1,131 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Checkout\Block\Onepage; - -use Magento\Customer\Api\CustomerRepositoryInterface; -use Magento\Customer\Model\Address\Config as AddressConfig; - -/** - * One page checkout status - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) - * @removeCandidate - */ -class Shipping extends \Magento\Checkout\Block\Onepage\AbstractOnepage -{ - /** - * Sales Quote Shipping Address instance - * - * @var \Magento\Quote\Model\Quote\Address - */ - protected $_address = null; - - /** - * @var \Magento\Quote\Model\Quote\AddressFactory - */ - protected $_addressFactory; - - /** - * @param \Magento\Framework\View\Element\Template\Context $context - * @param \Magento\Directory\Helper\Data $directoryHelper - * @param \Magento\Framework\App\Cache\Type\Config $configCacheType - * @param \Magento\Customer\Model\Session $customerSession - * @param \Magento\Checkout\Model\Session $resourceSession - * @param \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory - * @param \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollectionFactory - * @param CustomerRepositoryInterface $customerRepository - * @param AddressConfig $addressConfig - * @param \Magento\Framework\App\Http\Context $httpContext - * @param \Magento\Customer\Model\Address\Mapper $addressMapper - * @param \Magento\Quote\Model\Quote\AddressFactory $addressFactory - * @param array $data - * @SuppressWarnings(PHPMD.ExcessiveParameterList) - */ - public function __construct( - \Magento\Framework\View\Element\Template\Context $context, - \Magento\Directory\Helper\Data $directoryHelper, - \Magento\Framework\App\Cache\Type\Config $configCacheType, - \Magento\Customer\Model\Session $customerSession, - \Magento\Checkout\Model\Session $resourceSession, - \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory, - \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollectionFactory, - CustomerRepositoryInterface $customerRepository, - AddressConfig $addressConfig, - \Magento\Framework\App\Http\Context $httpContext, - \Magento\Customer\Model\Address\Mapper $addressMapper, - \Magento\Quote\Model\Quote\AddressFactory $addressFactory, - array $data = [] - ) { - $this->_addressFactory = $addressFactory; - parent::__construct( - $context, - $directoryHelper, - $configCacheType, - $customerSession, - $resourceSession, - $countryCollectionFactory, - $regionCollectionFactory, - $customerRepository, - $addressConfig, - $httpContext, - $addressMapper, - $data - ); - $this->_isScopePrivate = true; - } - - /** - * Initialize shipping address step - * - * @return void - */ - protected function _construct() - { - $this->getCheckout()->setStepData( - 'shipping', - ['label' => __('Shipping Information'), 'is_show' => $this->isShow()] - ); - - parent::_construct(); - } - - /** - * Return checkout method - * - * @return string - */ - public function getMethod() - { - return $this->getQuote()->getCheckoutMethod(); - } - - /** - * Return Sales Quote Address model (shipping address) - * - * @return \Magento\Quote\Model\Quote\Address - */ - public function getAddress() - { - if ($this->_address === null) { - if ($this->isCustomerLoggedIn()) { - $this->_address = $this->getQuote()->getShippingAddress(); - } else { - $this->_address = $this->_addressFactory->create(); - } - } - - return $this->_address; - } - - /** - * Retrieve is allow and show block - * - * @return bool - */ - public function isShow() - { - return !$this->getQuote()->isVirtual(); - } -} diff --git a/app/code/Magento/Checkout/Block/Onepage/Shipping/Method.php b/app/code/Magento/Checkout/Block/Onepage/Shipping/Method.php deleted file mode 100644 index 5145d6fdca269a7613618b6b12f0dd979220e0e9..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/Block/Onepage/Shipping/Method.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Checkout\Block\Onepage\Shipping; - -/** - * One page checkout status - * - * @author Magento Core Team <core@magentocommerce.com> - * @removeCandidate - */ -class Method extends \Magento\Checkout\Block\Onepage\AbstractOnepage -{ - /** - * @return void - */ - protected function _construct() - { - $this->getCheckout()->setStepData( - 'shipping_method', - ['label' => __('Shipping Method'), 'is_show' => $this->isShow()] - ); - parent::_construct(); - } - - /** - * Retrieve is allow and show block - * - * @return bool - */ - public function isShow() - { - return !$this->getQuote()->isVirtual(); - } -} diff --git a/app/code/Magento/Checkout/Block/Onepage/Shipping/Method/Additional.php b/app/code/Magento/Checkout/Block/Onepage/Shipping/Method/Additional.php deleted file mode 100644 index bf27a8fa212086889f4b88616f84edb14f6307df..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/Block/Onepage/Shipping/Method/Additional.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Checkout\Block\Onepage\Shipping\Method; - -/** - * Block for additional information in shipping method - * - * @author Magento Core Team <core@magentocommerce.com> - * @removeCandidate - */ -class Additional extends \Magento\Checkout\Block\Onepage\AbstractOnepage -{ -} diff --git a/app/code/Magento/Checkout/Block/Onepage/Shipping/Method/Available.php b/app/code/Magento/Checkout/Block/Onepage/Shipping/Method/Available.php deleted file mode 100644 index 582beafbbb5f4710f9be6558cc1644cad16e8376..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/Block/Onepage/Shipping/Method/Available.php +++ /dev/null @@ -1,122 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Checkout\Block\Onepage\Shipping\Method; - -use Magento\Customer\Api\CustomerRepositoryInterface; -use Magento\Customer\Model\Address\Config as AddressConfig; -use Magento\Quote\Model\Quote\Address; - -/** - * One page checkout status - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) - * @removeCandidate - */ -class Available extends \Magento\Checkout\Block\Onepage\AbstractOnepage -{ - /** - * @var array - */ - protected $_rates; - - /** - * @var Address - */ - protected $_address; - - /** - * @param \Magento\Framework\View\Element\Template\Context $context - * @param \Magento\Directory\Helper\Data $directoryHelper - * @param \Magento\Framework\App\Cache\Type\Config $configCacheType - * @param \Magento\Customer\Model\Session $customerSession - * @param \Magento\Checkout\Model\Session $resourceSession - * @param \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory - * @param \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollectionFactory - * @param CustomerRepositoryInterface $customerRepository - * @param AddressConfig $addressConfig - * @param \Magento\Framework\App\Http\Context $httpContext - * @param \Magento\Customer\Model\Address\Mapper $addressMapper - * @param array $data - * @SuppressWarnings(PHPMD.ExcessiveParameterList) - */ - public function __construct( - \Magento\Framework\View\Element\Template\Context $context, - \Magento\Directory\Helper\Data $directoryHelper, - \Magento\Framework\App\Cache\Type\Config $configCacheType, - \Magento\Customer\Model\Session $customerSession, - \Magento\Checkout\Model\Session $resourceSession, - \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory, - \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollectionFactory, - CustomerRepositoryInterface $customerRepository, - AddressConfig $addressConfig, - \Magento\Framework\App\Http\Context $httpContext, - \Magento\Customer\Model\Address\Mapper $addressMapper, - array $data = [] - ) { - parent::__construct( - $context, - $directoryHelper, - $configCacheType, - $customerSession, - $resourceSession, - $countryCollectionFactory, - $regionCollectionFactory, - $customerRepository, - $addressConfig, - $httpContext, - $addressMapper, - $data - ); - $this->_isScopePrivate = true; - } - - /** - * @return array - */ - public function getShippingRates() - { - if (empty($this->_rates)) { - $this->getAddress()->collectShippingRates()->save(); - $this->_rates = $this->getAddress()->getGroupedAllShippingRates(); - } - - return $this->_rates; - } - - /** - * @return Address - */ - public function getAddress() - { - if (empty($this->_address)) { - $this->_address = $this->getQuote()->getShippingAddress(); - } - return $this->_address; - } - - /** - * @param string $carrierCode - * @return string - */ - public function getCarrierName($carrierCode) - { - if ($name = $this->_scopeConfig->getValue( - 'carriers/' . $carrierCode . '/title', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ) - ) { - return $name; - } - return $carrierCode; - } - - /** - * @return string - */ - public function getAddressShippingMethod() - { - return $this->getAddress()->getShippingMethod(); - } -} diff --git a/app/code/Magento/Checkout/Controller/Onepage/SaveOrder.php b/app/code/Magento/Checkout/Controller/Onepage/SaveOrder.php index 82e9d18b8854e5e2f0e51b131a2f4a84a496bb69..6c66fd165de554889cdbbd39b4b1f40608bb9983 100644 --- a/app/code/Magento/Checkout/Controller/Onepage/SaveOrder.php +++ b/app/code/Magento/Checkout/Controller/Onepage/SaveOrder.php @@ -8,9 +8,6 @@ namespace Magento\Checkout\Controller\Onepage; use Magento\Framework\DataObject; use Magento\Framework\Exception\PaymentException; -/** - * @removeCandidate - */ class SaveOrder extends \Magento\Checkout\Controller\Onepage { /** diff --git a/app/code/Magento/Checkout/Test/Unit/Block/OnepageTest.php b/app/code/Magento/Checkout/Test/Unit/Block/OnepageTest.php index e3ef9b58e827f6031b03c6678e8aeea99f0dd536..d29475962ef4dfe3b80b3b98f01f8ccb5983cd0e 100644 --- a/app/code/Magento/Checkout/Test/Unit/Block/OnepageTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Block/OnepageTest.php @@ -35,13 +35,6 @@ class OnepageTest extends \PHPUnit_Framework_TestCase protected function setUp() { $contextMock = $this->getMock('\Magento\Framework\View\Element\Template\Context', [], [], '', false); - $directoryHelperMock = $this->getMock('\Magento\Directory\Helper\Data', [], [], '', false); - $configCacheTypeMock = $this->getMock('\Magento\Framework\App\Cache\Type\Config', [], [], '', false); - $customerSessionMock = $this->getMock('\Magento\Customer\Model\Session', [], [], '', false); - $resourceSessionMock = $this->getMock('\Magento\Checkout\Model\Session', [], [], '', false); - $addressConfigMock = $this->getMock('\Magento\Customer\Model\Address\Config', [], [], '', false); - $httpContextMock = $this->getMock('\Magento\Framework\App\Http\Context', [], [], '', false); - $addressMapperMock = $this->getMock('\Magento\Customer\Model\Address\Mapper', [], [], '', false); $this->formKeyMock = $this->getMock('\Magento\Framework\Data\Form\FormKey', [], [], '', false); $this->configProviderMock = $this->getMock( '\Magento\Checkout\Model\CompositeConfigProvider', @@ -50,27 +43,6 @@ class OnepageTest extends \PHPUnit_Framework_TestCase '', false ); - $countryCollectionFactoryMock = $this->getMock( - 'Magento\Directory\Model\ResourceModel\Country\CollectionFactory', - ['create'], - [], - '', - false - ); - $regionCollectionFactoryMock = $this->getMock( - 'Magento\Directory\Model\ResourceModel\Region\CollectionFactory', - ['create'], - [], - '', - false - ); - $customerRepositoryMock = $this->getMock( - '\Magento\Customer\Api\CustomerRepositoryInterface', - [], - [], - '', - false - ); $this->storeManagerMock = $this->getMock('\Magento\Store\Model\StoreManagerInterface', [], [], '', false); $contextMock->expects($this->once())->method('getStoreManager')->willReturn($this->storeManagerMock); @@ -84,16 +56,6 @@ class OnepageTest extends \PHPUnit_Framework_TestCase $this->model = new \Magento\Checkout\Block\Onepage( $contextMock, - $directoryHelperMock, - $configCacheTypeMock, - $customerSessionMock, - $resourceSessionMock, - $countryCollectionFactoryMock, - $regionCollectionFactoryMock, - $customerRepositoryMock, - $addressConfigMock, - $httpContextMock, - $addressMapperMock, $this->formKeyMock, $this->configProviderMock, [$this->layoutProcessorMock] diff --git a/app/code/Magento/Checkout/composer.json b/app/code/Magento/Checkout/composer.json index 775fe8406e930313ad64a49daf716d7792b60335..ca4d5b91da09dd595225d73f954bfefe0c0cfcac 100644 --- a/app/code/Magento/Checkout/composer.json +++ b/app/code/Magento/Checkout/composer.json @@ -15,7 +15,6 @@ "magento/module-tax": "1.0.0-beta", "magento/module-directory": "1.0.0-beta", "magento/module-eav": "1.0.0-beta", - "magento/module-gift-message": "1.0.0-beta", "magento/module-page-cache": "1.0.0-beta", "magento/module-sales-rule": "1.0.0-beta", "magento/module-theme": "1.0.0-beta", diff --git a/app/code/Magento/Checkout/view/frontend/requirejs-config.js b/app/code/Magento/Checkout/view/frontend/requirejs-config.js index e8a99235212544b2c3c7c219865cda4b7d3eab9c..a7055ed7d1558505ac1bf32b6c377d7b13f879f7 100644 --- a/app/code/Magento/Checkout/view/frontend/requirejs-config.js +++ b/app/code/Magento/Checkout/view/frontend/requirejs-config.js @@ -9,10 +9,7 @@ var config = { discountCode: 'Magento_Checkout/js/discount-codes', shoppingCart: 'Magento_Checkout/js/shopping-cart', regionUpdater: 'Magento_Checkout/js/region-updater', - opcOrderReview: 'Magento_Checkout/js/opc-order-review', - sidebar: 'Magento_Checkout/js/sidebar', - payment: 'Magento_Checkout/js/payment', - paymentAuthentication: 'Magento_Checkout/js/payment-authentication' + sidebar: 'Magento_Checkout/js/sidebar' } } }; diff --git a/app/code/Magento/Checkout/view/frontend/templates/onepage/billing.phtml b/app/code/Magento/Checkout/view/frontend/templates/onepage/billing.phtml deleted file mode 100644 index 49369053b5be56cb3ea02dee5726ba776aa1c40d..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/view/frontend/templates/onepage/billing.phtml +++ /dev/null @@ -1,214 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -// @codingStandardsIgnoreFile - -/** @var \Magento\Checkout\Block\Onepage\Billing $block */ -/** - * @removeCandidate - */ -?> -<form class="form billing" id="co-billing-form" data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>"> - - <?php if ($block->customerHasAddresses()): ?> - <div class="field addresses"> - <label class="label" for="billing:address-select"><span><?php /* @escapeNotVerified */ echo __('Select a billing address from your address book or enter a new address.') ?></span></label> - <div class="control"> - <?php echo $block->getAddressesHtmlSelect('billing') ?> - </div> - </div> - <?php endif; ?> - <fieldset class="fieldset address" id="billing-new-address-form"<?php if ($block->customerHasAddresses()): ?> style="display:none;"<?php endif; ?>> - <input type="hidden" name="billing[address_id]" value="<?php /* @escapeNotVerified */ echo $block->getAddress()->getId() ?>" id="billing:address_id" /> - - <?php echo $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Name')->setObject($block->getAddress()->getFirstname() ? $block->getAddress() : $block->getQuote()->getCustomer())->setForceUseCustomerRequiredAttributes(!$block->isCustomerLoggedIn())->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]')->toHtml() ?> - - <?php if (!$block->isCustomerLoggedIn()): ?> - <div class="field required email"> - <label class="label" for="billing:email"><span><?php /* @escapeNotVerified */ echo __('Email') ?></span></label> - <div class="control"> - <input type="email" name="billing[email]" id="billing:email" value="<?php echo $block->escapeHtml($block->getAddress()->getEmail()) ?>" title="<?php /* @escapeNotVerified */ echo __('Email') ?>" class="input-text" data-validate="{required:true, 'validate-email':true}"/> - </div> - </div> - <?php endif; ?> - - <div class="field company"> - <label class="label" for="billing:company"><span><?php /* @escapeNotVerified */ echo __('Company') ?></span></label> - <div class="control"> - <input type="text" id="billing:company" name="billing[company]" value="<?php echo $block->escapeHtml($block->getAddress()->getCompany()) ?>" title="<?php /* @escapeNotVerified */ echo __('Company') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('company') ?>" /> - </div> - </div> - - <?php if ($this->helper('Magento\Customer\Helper\Address')->isVatAttributeVisible()) : ?> - <div class="field taxvat"> - <label class="label" for="billing:vat_id"><span><?php /* @escapeNotVerified */ echo __('VAT Number') ?></span></label> - <div class="control"> - <input type="text" id="billing:vat_id" name="billing[vat_id]" value="<?php echo $block->escapeHtml($block->getAddress()->getVatId()) ?>" title="<?php /* @escapeNotVerified */ echo __('VAT Number') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('vat_id') ?>" /> - </div> - </div> - <?php endif; ?> - - <?php $_streetValidationClass = $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('street'); ?> - <div class="field street required"> - <label class="label" for="billing:street1"><span><?php /* @escapeNotVerified */ echo __('Address') ?></span></label> - <div class="control"> - <input type="text" title="<?php /* @escapeNotVerified */ echo __('Street Address') ?>" name="billing[street][]" id="billing:street1" value="<?php echo $block->escapeHtml($block->getAddress()->getStreetLine(1)) ?>" class="input-text <?php /* @escapeNotVerified */ echo $_streetValidationClass ?>" /> - <div class="nested"> - <?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?> - <?php for ($_i = 2, $_n = $this->helper('Magento\Customer\Helper\Address')->getStreetLines(); $_i <= $_n; $_i++): ?> - <div class="field additional"> - <label class="label" for="billing:street<?php /* @escapeNotVerified */ echo $_i ?>"> - <span><?php /* @escapeNotVerified */ echo __('Address') ?></span> - </label> - <div class="control"> - <input type="text" title="<?php /* @escapeNotVerified */ echo __('Street Address %1', $_i) ?>" name="billing[street][]" id="billing:street<?php /* @escapeNotVerified */ echo $_i ?>" value="<?php echo $block->escapeHtml($block->getAddress()->getStreetLine($_i)) ?>" class="input-text <?php /* @escapeNotVerified */ echo $_streetValidationClass ?>" /> - </div> - </div> - <?php endfor; ?> - </div> - </div> - </div> - - - <div class="field city required"> - <label class="label" for="billing:city"><span><?php /* @escapeNotVerified */ echo __('City') ?></span></label> - <div class="control"> - <input type="text" title="<?php /* @escapeNotVerified */ echo __('City') ?>" name="billing[city]" value="<?php echo $block->escapeHtml($block->getAddress()->getCity()) ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('city') ?>" id="billing:city" /> - </div> - </div> - - <div class="field region required"> - <label class="label" for="billing:region_id"><span><?php /* @escapeNotVerified */ echo __('State/Province') ?></span></label> - <div class="control"> - <select id="billing:region_id" - name="billing[region_id]" - title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" - data-validate="{'validate-select':true}" - <?php if ($block->getConfig('general/region/display_all') === 0):?>disabled="disabled"<?php endif; ?> - style="display:none;"> - <option value=""><?php /* @escapeNotVerified */ echo __('Please select a region, state or province.') ?></option> - </select> - <input type="text" - id="billing:region" - name="billing[region]" - value="<?php echo $block->escapeHtml($block->getAddress()->getRegion()) ?>" - title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" - class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('region') ?>" - <?php if ($block->getConfig('general/region/display_all') === 0):?>disabled="disabled"<?php endif; ?> - style="display:none;" /> - </div> - </div> - - <div class="field zip required"> - <label class="label" for="billing:postcode"><span><?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?></span></label> - <div class="control"> - <input type="text" title="<?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?>" name="billing[postcode]" id="billing:postcode" value="<?php echo $block->escapeHtml($block->getAddress()->getPostcode()) ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('postcode') ?>" data-validate="{'required':true, 'validate-zip-international':true}"/> - </div> - </div> - - <div class="field country required"> - <label class="label" for="billing:country_id"><span><?php /* @escapeNotVerified */ echo __('Country') ?></span></label> - <div class="control"> - <?php echo $block->getCountryHtmlSelect('billing') ?> - </div> - </div> - - <div class="field telephone required"> - <label class="label" for="billing:telephone"><span><?php /* @escapeNotVerified */ echo __('Phone Number') ?></span></label> - <div class="control"> - <input type="text" name="billing[telephone]" value="<?php echo $block->escapeHtml($block->getAddress()->getTelephone()) ?>" title="<?php /* @escapeNotVerified */ echo __('Telephone') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('telephone') ?>" id="billing:telephone" /> - </div> - </div> - - <div class="field fax"> - <label class="label" for="billing:fax"><span><?php /* @escapeNotVerified */ echo __('Fax') ?></span></label> - <div class="control"> - <input type="text" name="billing[fax]" value="<?php echo $block->escapeHtml($block->getAddress()->getFax()) ?>" title="<?php /* @escapeNotVerified */ echo __('Fax') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('fax') ?>" id="billing:fax" /> - </div> - </div> - - <?php if (!$block->isCustomerLoggedIn()): ?> - <?php $_dob = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Dob') ?> - <?php $_taxvat = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Taxvat') ?> - <?php $_gender = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Gender') ?> - - <?php if ($_dob->isEnabled()): ?> - <?php echo $_dob->setDate($block->getQuote()->getCustomerDob())->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]')->toHtml() ?> - <?php endif; ?> - <?php if ($_taxvat->isEnabled()): ?> - <?php echo $_taxvat->setTaxvat($block->getQuote()->getCustomerTaxvat())->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]')->toHtml() ?> - <?php endif ?> - <?php if ($_gender->isEnabled()): ?> - <?php echo $_gender->setGender($block->getQuote()->getCustomerGender())->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]')->toHtml() ?> - <?php endif ?> - <?php $customerAttributes = $block->getChildBlock('customer_form_customer_user_defined_attributes');?> - <?php if ($customerAttributes): ?> - <?php $customerAttributes->setEntityModelClass('Magento\Customer\Model\Customer')->setFieldIdFormat('billing:%1$s');?> - <?php $customerAttributes->setFieldNameFormat('billing[%1$s]')->setShowContainer(false);?> - <?php echo $customerAttributes->toHtml()?> - <?php endif;?> - <div class="field password required"> - <label class="label" for="billing:customer_password"><span><?php /* @escapeNotVerified */ echo __('Password') ?></span></label> - <div class="control"> - <input type="password" name="billing[customer_password]" id="billing:customer_password" title="<?php /* @escapeNotVerified */ echo __('Password') ?>" class="input-text" data-validate="{required:true, 'validate-password':true}"/> - </div> - </div> - <div class="field confirm required"> - <label class="label" for="billing:confirm_password"><span><?php /* @escapeNotVerified */ echo __('Confirm Password') ?></span></label> - <div class="control"> - <input type="password" name="billing[confirm_password]" title="<?php /* @escapeNotVerified */ echo __('Confirm Password') ?>" id="billing:confirm_password" class="input-text" data-validate="{required:true, 'validate-cpassword':true, equalTo: '#billing\\:customer_password'}"/> - </div> - </div> - <?php endif; ?> - <?php echo $block->getChildHtml('form_additional_info'); ?> - <?php if ($block->isCustomerLoggedIn() && $block->customerHasAddresses()):?> - <div class="field save choice"> - <input type="checkbox" name="billing[save_in_address_book]" value="1" title="<?php /* @escapeNotVerified */ echo __('Save in address book') ?>" id="billing:save_in_address_book" <?php if ($block->getAddress()->getSaveInAddressBook()):?> checked="checked"<?php endif;?> class="checkbox" /> - <label class="label" for="billing:save_in_address_book"><span><?php /* @escapeNotVerified */ echo __('Save in address book') ?></span></label> - </div> - <?php else:?> - <input type="hidden" name="billing[save_in_address_book]" value="1" /> - <?php endif; ?> - <?php /* Extensions placeholder */ ?> - <?php echo $block->getChildHtml('checkout.onepage.billing.extra')?> -</fieldset> -<?php if ($block->canShip()): ?> - <div class="field choice"> - <input type="radio" name="billing[use_for_shipping]" id="billing:use_for_shipping_yes" value="1"<?php if ($block->isUseBillingAddressForShipping()) { - ?> checked="checked"<?php -}?> class="radio" /> - <label class="label" for="billing:use_for_shipping_yes"><span><?php /* @escapeNotVerified */ echo __('Ship to this address') ?></span></label> - </div> - <div class="field choice"> - <input type="radio" name="billing[use_for_shipping]" id="billing:use_for_shipping_no" value="0"<?php if (!$block->isUseBillingAddressForShipping()) { - ?> checked="checked"<?php -}?> class="radio" /> - <label class="label" for="billing:use_for_shipping_no"><span><?php /* @escapeNotVerified */ echo __('Ship to different address') ?></span></label> - </div> -<?php endif; ?> - -<?php if (!$block->canShip()): ?> - <input type="hidden" name="billing[use_for_shipping]" value="1" /> -<?php endif; ?> -<div class="actions" id="billing-buttons-container"> - <div class="primary"><button data-role="opc-continue" type="button" class="button action continue primary"><span><?php /* @escapeNotVerified */ echo __('Continue') ?></span></button></div> -</div> -</form> -<script type="text/x-magento-init"> - { - "#billing\\:country_id": { - "regionUpdater": { - "optionalRegionAllowed": <?php /* @escapeNotVerified */ echo($block->getConfig('general/region/display_all') ? 'true' : 'false'); ?>, - "regionListId": "#billing\\:region_id", - "regionInputId": "#billing\\:region", - "postcodeId": "#billing\\:postcode", - "regionJson": <?php /* @escapeNotVerified */ echo $this->helper('Magento\Directory\Helper\Data')->getRegionJson() ?>, - "defaultRegion": "<?php /* @escapeNotVerified */ echo $block->getAddress()->getRegionId() ?>", - "countriesWithOptionalZip": <?php /* @escapeNotVerified */ echo $this->helper('Magento\Directory\Helper\Data')->getCountriesWithOptionalZip(true) ?> - } - } - } -</script> diff --git a/app/code/Magento/Checkout/view/frontend/templates/onepage/payment.phtml b/app/code/Magento/Checkout/view/frontend/templates/onepage/payment.phtml deleted file mode 100644 index f9ac39fd39dca380af9b9e422fb7e45656f50c20..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/view/frontend/templates/onepage/payment.phtml +++ /dev/null @@ -1,31 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -// @codingStandardsIgnoreFile - -/** - * @removeCandidate - */ -?> -<form id="co-payment-form" class="form payments"> - <?php echo $block->getBlockHtml('formkey') ?> - <fieldset class="fieldset"> - <legend class="legend payments-title"> - <span><?php /* @escapeNotVerified */ echo __('Payment Information') ?></span> - </legend><br> - <?php echo $block->getChildChildHtml('methods_additional') ?> - <div id="checkout-payment-method-load" class="opc-payment"></div> - </fieldset> - <?php echo $block->getChildChildHtml('additional') ?> - <div class="actions-toolbar" id="payment-buttons-container"> - <div class="primary"> - <button data-role="opc-continue" type="button" class="button action continue primary"><span><?php /* @escapeNotVerified */ echo __('Continue') ?></span></button> - </div> - <div class="secondary"> - <a class="action back" href="#"><span><?php /* @escapeNotVerified */ echo __('Back') ?></span></a> - </div> - </div> -</form> diff --git a/app/code/Magento/Checkout/view/frontend/templates/onepage/payment/methods.phtml b/app/code/Magento/Checkout/view/frontend/templates/onepage/payment/methods.phtml deleted file mode 100644 index f3c0f86cc46bb59bf8528a71db0e40a63635ec1a..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/view/frontend/templates/onepage/payment/methods.phtml +++ /dev/null @@ -1,52 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -// @codingStandardsIgnoreFile - -/** - * @removeCandidate - */ -?> -<?php -/** - * One page checkout payment methods - * - * @var $block \Magento\Checkout\Block\Onepage\Payment\Methods - */ -?> -<dl class="items methods-payment"> -<?php - $methods = $block->getMethods(); - $oneMethod = count($methods) <= 1; -?> -<?php if (empty($methods)): ?> - <dt class="item-title"> - <?php /* @escapeNotVerified */ echo __('No Payment Methods') ?> - </dt> -<?php else: - foreach ($methods as $_method): - $_code = $_method->getCode(); -?> - <dt class="item-title <?php /* @escapeNotVerified */ echo $_code ?>"> - <?php if (!$oneMethod): ?> - <input id="p_method_<?php /* @escapeNotVerified */ echo $_code ?>" value="<?php /* @escapeNotVerified */ echo $_code ?>" type="radio" name="payment[method]" title="<?php echo $block->escapeHtml($_method->getTitle()) ?>" <?php if ($block->getSelectedMethodCode() == $_code): ?> checked="checked"<?php endif; ?> class="radio" /> - <?php else: ?> - <input id="p_method_<?php /* @escapeNotVerified */ echo $_code ?>" value="<?php /* @escapeNotVerified */ echo $_code ?>" type="radio" name="payment[method]" checked="checked" class="radio no-display" /> - <?php $oneMethod = $_code; ?> - <?php endif; ?> - <label for="p_method_<?php /* @escapeNotVerified */ echo $_code ?>"><?php echo $block->escapeHtml($block->getMethodTitle($_method)) ?> <?php echo $block->getMethodLabelAfterHtml($_method) ?></label> - </dt> - <?php if ($html = $block->getPaymentMethodFormHtml($_method)): ?> - <dd class="item-content <?php /* @escapeNotVerified */ echo $_code ?>"> - <?php /* @escapeNotVerified */ echo $html; ?> - </dd> - <?php endif; ?> -<?php endforeach; - endif; -?> -</dl> -<div class="no-display" data-checkout-price="<?php echo (float)$block->getQuote()->getBaseGrandTotal(); ?>"></div> -<?php echo $block->getChildChildHtml('additional'); ?> diff --git a/app/code/Magento/Checkout/view/frontend/templates/onepage/review/button.phtml b/app/code/Magento/Checkout/view/frontend/templates/onepage/review/button.phtml deleted file mode 100644 index 1b26f9922c5faac3b3dc2e0e72d9a60644d0a925..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/view/frontend/templates/onepage/review/button.phtml +++ /dev/null @@ -1,13 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -// @codingStandardsIgnoreFile -/** - * @removeCandidate - */ -?> -<button data-role="review-save" type="submit" title="<?php /* @escapeNotVerified */ echo __('Place Order') ?>" - class="button action primary checkout"><span><?php /* @escapeNotVerified */ echo __('Place Order') ?></span></button> diff --git a/app/code/Magento/Checkout/view/frontend/templates/onepage/review/info.phtml b/app/code/Magento/Checkout/view/frontend/templates/onepage/review/info.phtml deleted file mode 100644 index 8e390e653fd79cf1743b4b7c6d134310d2f02f21..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/view/frontend/templates/onepage/review/info.phtml +++ /dev/null @@ -1,54 +0,0 @@ -\<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -// @codingStandardsIgnoreFile - -/** @var $block \Magento\Checkout\Block\Onepage\Review\Info */ - -/** - * @removeCandidate - */ -?> -<?php echo $block->getChildHtml('items_before'); ?> -<div id="checkout-review-table-wrapper" class="order-review-wrapper table-wrapper"> - <?php if ($this->helper('Magento\Tax\Helper\Data')->displayCartBothPrices()): $colspan = $rowspan = 2; else: $colspan = $rowspan = 1; endif; ?> - <table class="data table table-order-review items" id="checkout-review-table"> - <caption class="table-caption"><?php /* @escapeNotVerified */ echo __('Order Review'); ?></caption> - <thead> - <tr> - <th class="col item" scope="col"><?php /* @escapeNotVerified */ echo __('Product Name') ?></th> - <th class="col price" scope="col"><?php /* @escapeNotVerified */ echo __('Price') ?></th> - <th class="col qty" scope="col"><?php /* @escapeNotVerified */ echo __('Qty') ?></th> - <th class="col subtotal" scope="col"><?php /* @escapeNotVerified */ echo __('Subtotal') ?></th> - </tr> - </thead> - <tbody> - <?php foreach ($block->getItems() as $_item): ?> - <?php echo $block->getItemHtml($_item)?> - <?php endforeach ?> - </tbody> - <tfoot> - <?php echo $block->getChildHtml('totals'); ?> - </tfoot> - </table> -</div> -<?php echo $block->getChildHtml('items_after'); ?> -<div id="checkout-review-submit" data-mage-init='{"paymentAuthentication":{}}' class="checkout-submit-order"> - <?php echo $block->getChildHtml('agreements') ?> - <div class="actions-toolbar" id="review-buttons-container"> - <div class="primary"><?php echo $block->getChildHtml('button') ?></div> - <div class="secondary"> - <span id="checkout-review-edit-label"> - <?php /* @escapeNotVerified */ echo __('Forgot an Item?') ?> - </span> - <a href="<?php /* @escapeNotVerified */ echo $block->getUrl('checkout/cart') ?>" - aria-describedby="checkout-review-edit-label" - class="action edit"> - <span><?php /* @escapeNotVerified */ echo __('Edit Your Cart') ?></span> - </a> - </div> - </div> -</div> diff --git a/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item.phtml b/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item.phtml index 7d107a0589d53580c0e9b9512b3c936b063b49be..54748a318b6adedd0bf8d354eebaeaf8bdcd9c12 100644 --- a/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item.phtml +++ b/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item.phtml @@ -8,10 +8,6 @@ /** @var $block Magento\Checkout\Block\Cart\Item\Renderer */ -/** - * @removeCandidate - */ - $_item = $block->getItem(); ?> <tbody class="cart item"> diff --git a/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item/price/row_excl_tax.phtml b/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item/price/row_excl_tax.phtml index d10b01b1591fca77c9bd511743064a94588b836d..f0ead67e1bdc2a009f77e2bf646408e3e3d79929 100644 --- a/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item/price/row_excl_tax.phtml +++ b/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item/price/row_excl_tax.phtml @@ -8,10 +8,6 @@ /** @var $block \Magento\Checkout\Block\Item\Price\Renderer */ -/** - * @removeCandidate - */ - $_item = $block->getItem(); ?> <span class="cart-price"> diff --git a/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item/price/row_incl_tax.phtml b/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item/price/row_incl_tax.phtml index 09230fd5c336c67769392d2d083cb95af64e20f0..df0f4f3233cb73a5a3552a3355aa9d391f5f223c 100644 --- a/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item/price/row_incl_tax.phtml +++ b/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item/price/row_incl_tax.phtml @@ -8,10 +8,6 @@ /** @var $block \Magento\Checkout\Block\Item\Price\Renderer */ -/** - * @removeCandidate - */ - $_item = $block->getItem(); ?> <?php $_incl = $this->helper('Magento\Checkout\Helper\Data')->getSubtotalInclTax($_item); ?> diff --git a/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item/price/unit_excl_tax.phtml b/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item/price/unit_excl_tax.phtml index f81ddc607c938bbc6acc8ba9897b1a296a7e14c6..b4b340e78b553c84f10888facbbbbb9ef55f6101 100644 --- a/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item/price/unit_excl_tax.phtml +++ b/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item/price/unit_excl_tax.phtml @@ -8,10 +8,6 @@ /** @var $block \Magento\Checkout\Block\Item\Price\Renderer */ -/** - * @removeCandidate - */ - $_item = $block->getItem(); ?> <span class="cart-price"> diff --git a/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item/price/unit_incl_tax.phtml b/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item/price/unit_incl_tax.phtml index 6ff351b90f76a939edd05cce488504d0df22cf70..53118c3312595f301cb9afc861b3476da7a49194 100644 --- a/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item/price/unit_incl_tax.phtml +++ b/app/code/Magento/Checkout/view/frontend/templates/onepage/review/item/price/unit_incl_tax.phtml @@ -8,10 +8,6 @@ /** @var $block \Magento\Checkout\Block\Item\Price\Renderer */ -/** - * @removeCandidate - */ - $_item = $block->getItem(); ?> <?php $_incl = $this->helper('Magento\Checkout\Helper\Data')->getPriceInclTax($_item); ?> diff --git a/app/code/Magento/Checkout/view/frontend/templates/onepage/shipping.phtml b/app/code/Magento/Checkout/view/frontend/templates/onepage/shipping.phtml deleted file mode 100644 index aaff68ef03aca5f2230b68512bca28792c3cee9f..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/view/frontend/templates/onepage/shipping.phtml +++ /dev/null @@ -1,133 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -// @codingStandardsIgnoreFile - -/** - * @removeCandidate - */ -?> -<form class="form shipping address" id="co-shipping-form" data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>"> - -<?php if ($block->customerHasAddresses()): ?> - <div class="field addresses"> - <label class="label" for="shipping:address-select"><span><?php /* @escapeNotVerified */ echo __('Select a shipping address from your address book or enter a new address.') ?></span></label> - <div class="control"><?php echo $block->getAddressesHtmlSelect('shipping') ?></div> - </div> -<?php endif ?> - <fieldset class="fieldset address" id="shipping-new-address-form"<?php if ($block->customerHasAddresses()): ?> style="display:none;"<?php endif ?>> - <input type="hidden" name="shipping[address_id]" value="<?php /* @escapeNotVerified */ echo $block->getAddress()->getId() ?>" id="shipping:address_id" /> - <?php echo $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Name')->setObject($block->getAddress())->setFieldIdFormat('shipping:%s')->setFieldNameFormat('shipping[%s]')->toHtml() ?> - <div class="field company"> - <label class="label" for="shipping:company"><span><?php /* @escapeNotVerified */ echo __('Company') ?></span></label> - <div class="control"> - <input type="text" id="shipping:company" name="shipping[company]" value="<?php echo $block->escapeHtml($block->getAddress()->getCompany()) ?>" title="<?php /* @escapeNotVerified */ echo __('Company') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('company') ?>" /> - </div> - </div> - <?php if ($this->helper('Magento\Customer\Helper\Address')->isVatAttributeVisible()) : ?> - <div class="field taxvat"> - <label class="label" for="shipping:vat_id"><span><?php /* @escapeNotVerified */ echo __('VAT Number'); ?></span></label> - <div class="control"> - <input type="text" id="shipping:vat_id" name="shipping[vat_id]" value="<?php echo $block->escapeHtml($block->getAddress()->getVatId()); ?>" title="<?php /* @escapeNotVerified */ echo __('VAT Number'); ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('vat_id') ?>" /> - </div> - </div> - <?php endif; ?> - <?php $_streetValidationClass = $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('street'); ?> - <div class="field street required"> - <label class="label" for="shipping:street1"><span><?php /* @escapeNotVerified */ echo __('Address') ?></span></label> - <div class="control"> - <input type="text" title="<?php /* @escapeNotVerified */ echo __('Street Address') ?>" name="shipping[street][]" id="shipping:street1" value="<?php echo $block->escapeHtml($block->getAddress()->getStreetLine(1)) ?>" class="input-text <?php /* @escapeNotVerified */ echo $_streetValidationClass ?>" /> - <div class="nested"> - <?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?> - <?php for ($_i = 2, $_n = $this->helper('Magento\Customer\Helper\Address')->getStreetLines(); $_i <= $_n; $_i++): ?> - <div class="field additional"> - <label class="label" for="shipping:street<?php /* @escapeNotVerified */ echo $_i ?>"> - <span><?php /* @escapeNotVerified */ echo __('Street Address %1', $_i) ?></span> - </label> - <div class="control"> - <input type="text" title="<?php /* @escapeNotVerified */ echo __('Street Address %1', $_i) ?>" name="shipping[street][]" id="shipping:street<?php /* @escapeNotVerified */ echo $_i ?>" value="<?php echo $block->escapeHtml($block->getAddress()->getStreetLine($_i)) ?>" class="input-text <?php /* @escapeNotVerified */ echo $_streetValidationClass ?>" /> - </div> - </div> - <?php endfor; ?> - </div> - </div> - </div> - - <div class="field city required"> - <label class="label" for="shipping:city"><span><?php /* @escapeNotVerified */ echo __('City') ?></span></label> - <div class="control"> - <input type="text" title="<?php /* @escapeNotVerified */ echo __('City') ?>" name="shipping[city]" value="<?php echo $block->escapeHtml($block->getAddress()->getCity()) ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('city') ?>" id="shipping:city" /> - </div> - </div> - <div class="field region required"> - <label class="label" for="shipping:region"><span><?php /* @escapeNotVerified */ echo __('State/Province') ?></span></label> - <div class="control"> - <select id="shipping:region_id" name="shipping[region_id]" title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" class="validate-select" style="display:none;"> - <option value=""><?php /* @escapeNotVerified */ echo __('Please select a region, state or province.') ?></option> - </select> - <input type="text" id="shipping:region" name="shipping[region]" value="<?php echo $block->escapeHtml($block->getAddress()->getRegion()) ?>" title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('region') ?>" style="display:none;" /> - </div> - </div> - <div class="field zip required"> - <label class="label" for="shipping:postcode"><span><?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?></span></label> - <div class="control"> - <input type="text" title="<?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?>" name="shipping[postcode]" id="shipping:postcode" value="<?php echo $block->escapeHtml($block->getAddress()->getPostcode()) ?>" class="input-text validate-zip-international <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('postcode') ?>" data-validate="{'required':true, 'validate-zip-international':true}" /> - </div> - </div> - <div class="field country required"> - <label class="label" for="shipping:country_id"><span><?php /* @escapeNotVerified */ echo __('Country') ?></span></label> - <div class="control"> - <?php echo $block->getCountryHtmlSelect('shipping') ?> - </div> - </div> - <div class="field telephone required"> - <label class="label" for="shipping:telephone"><span><?php /* @escapeNotVerified */ echo __('Phone Number') ?></span></label> - <div class="control"> - <input type="text" name="shipping[telephone]" value="<?php echo $block->escapeHtml($block->getAddress()->getTelephone()) ?>" title="<?php /* @escapeNotVerified */ echo __('Telephone') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('telephone') ?>" id="shipping:telephone" /> - </div> - </div> - <div class="field fax"> - <label class="label" for="shipping:fax"><span><?php /* @escapeNotVerified */ echo __('Fax') ?></span></label> - <div class="control"> - <input type="text" name="shipping[fax]" value="<?php echo $block->escapeHtml($block->getAddress()->getFax()) ?>" title="<?php /* @escapeNotVerified */ echo __('Fax') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('fax') ?>" id="shipping:fax" /> - </div> - </div> - - <?php if ($block->isCustomerLoggedIn() && $block->customerHasAddresses()):?> - <div class="field choice save"> - <input type="checkbox" name="shipping[save_in_address_book]" value="1" title="<?php /* @escapeNotVerified */ echo __('Save in address book') ?>" id="shipping:save_in_address_book" <?php if ($block->getAddress()->getSaveInAddressBook()):?> checked="checked"<?php endif;?> class="checkbox" /> - <label class="label" for="shipping:save_in_address_book"><span><?php /* @escapeNotVerified */ echo __('Save in address book') ?></span></label> - </div> - <?php else:?> - <input type="hidden" name="shipping[save_in_address_book]" value="1" /> - <?php endif;?> - </fieldset> - <div class="choice field"> - <input type="checkbox" name="shipping[same_as_billing]" id="shipping:same_as_billing" value="1"<?php if ($block->getAddress()->getSameAsBilling()): ?> checked="checked"<?php endif; ?> class="checkbox" /> - <label class="label" for="shipping:same_as_billing"><span><?php /* @escapeNotVerified */ echo __('Use Billing Address') ?></span></label> - </div> - <div class="actions-toolbar" id="shipping-buttons-container"> - <div class="primary"> - <button data-role="opc-continue" type="button" class="action continue primary"><span><?php /* @escapeNotVerified */ echo __('Continue') ?></span></button> - </div> - <div class="secondary"><a href="#" class="action back"><span><?php /* @escapeNotVerified */ echo __('Back') ?></span></a></div> - </div> -</form> -<script type="text/x-magento-init"> - { - "#shipping\\:country_id": { - "regionUpdater": { - "optionalRegionAllowed": <?php /* @escapeNotVerified */ echo($block->getConfig('general/region/display_all') ? 'true' : 'false'); ?>, - "regionListId": "#shipping\\:region_id", - "regionInputId": "#shipping\\:region", - "postcodeId": "#shipping\\:postcode", - "regionJson": <?php /* @escapeNotVerified */ echo $this->helper('Magento\Directory\Helper\Data')->getRegionJson() ?>, - "defaultRegion": "<?php /* @escapeNotVerified */ echo $block->getAddress()->getRegionId() ?>", - "countriesWithOptionalZip": <?php /* @escapeNotVerified */ echo $this->helper('Magento\Directory\Helper\Data')->getCountriesWithOptionalZip(true) ?> - } - } - } -</script> diff --git a/app/code/Magento/Checkout/view/frontend/templates/onepage/shipping_method.phtml b/app/code/Magento/Checkout/view/frontend/templates/onepage/shipping_method.phtml deleted file mode 100644 index 4ab0004006b422c96f48ffd63410853abd473a8c..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/view/frontend/templates/onepage/shipping_method.phtml +++ /dev/null @@ -1,24 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -// @codingStandardsIgnoreFile - -/** - * @removeCandidate - */ -?> -<form class="form methods-shipping" id="co-shipping-method-form"> - <div id="checkout-shipping-method-load"></div> - <div id="onepage-checkout-shipping-method-additional-load"> - <?php echo $block->getChildHtml('additional') ?> - </div> - <div class="actions-toolbar" id="shipping-method-buttons-container"> - <div class="primary"> - <button data-role="opc-continue" type="button" class="button action continue primary"><span><?php /* @escapeNotVerified */ echo __('Continue') ?></span></button> - </div> - <div class="secondary"><a class="action back" href="#"><span><?php /* @escapeNotVerified */ echo __('Back') ?></span></a></div> - </div> -</form> diff --git a/app/code/Magento/Checkout/view/frontend/templates/onepage/shipping_method/additional.phtml b/app/code/Magento/Checkout/view/frontend/templates/onepage/shipping_method/additional.phtml deleted file mode 100644 index ac87ff9ce6691d7e0062c81b1fa59d59aa817df2..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/view/frontend/templates/onepage/shipping_method/additional.phtml +++ /dev/null @@ -1,15 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -// @codingStandardsIgnoreFile - -/** - * @removeCandidate - */ -?> -<?php if (!$block->getQuote()->isVirtual()): ?> - <?php /* @escapeNotVerified */ echo $this->helper('Magento\GiftMessage\Helper\Message')->getInline('onepage_checkout', $block->getQuote(), $block->getDontDisplayContainer()) ?> -<?php endif; ?> diff --git a/app/code/Magento/Checkout/view/frontend/templates/onepage/shipping_method/available.phtml b/app/code/Magento/Checkout/view/frontend/templates/onepage/shipping_method/available.phtml deleted file mode 100644 index f2b37b4be7c835b7ec4fe521af4b907e35678510..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/view/frontend/templates/onepage/shipping_method/available.phtml +++ /dev/null @@ -1,50 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -// @codingStandardsIgnoreFile - -/** - * @removeCandidate - */ -?> -<?php /** @var $block \Magento\Checkout\Block\Onepage\Shipping\Method\Available */ ?> -<?php $_shippingRateGroups = $block->getShippingRates(); ?> -<?php if (!$_shippingRateGroups): ?> - <p><?php /* @escapeNotVerified */ echo __('Sorry, no quotes are available for this order right now.') ?></p> -<?php else: ?> - <dl class="items methods-shipping"> - <?php $shippingCodePrice = []; ?> - <?php $_sole = count($_shippingRateGroups) == 1; foreach ($_shippingRateGroups as $code => $_rates): ?> - <dt class="item-title <?php /* @escapeNotVerified */ echo $code ?>"><?php echo $block->escapeHtml($block->getCarrierName($code)) ?></dt> - <dd class="item-content <?php /* @escapeNotVerified */ echo $code ?>"> - <fieldset class="fieldset"> - <legend class="legend"><span><?php echo $block->escapeHtml($block->getCarrierName($code)) ?></span></legend><br> - <?php $_sole = $_sole && count($_rates) == 1; foreach ($_rates as $_rate): ?> - <?php $shippingCodePrice[] = '"'.$_rate->getCode().'":'.(float)$_rate->getPrice(); ?> - <div class="field choice"> - <?php if ($_rate->getErrorMessage()): ?> - <div class="message error"><div><?php echo $block->escapeHtml($_rate->getErrorMessage()) ?></div></div> - <?php else: ?> - <?php if ($_sole) : ?> - <span class="no-display"><input name="shipping_method" type="radio" value="<?php /* @escapeNotVerified */ echo $_rate->getCode() ?>" id="s_method_<?php /* @escapeNotVerified */ echo $_rate->getCode() ?>" checked="checked" /></span> - <?php else: ?> - <div class="control"> - <input name="shipping_method" type="radio" value="<?php /* @escapeNotVerified */ echo $_rate->getCode() ?>" id="s_method_<?php /* @escapeNotVerified */ echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$block->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/> - </div> - <?php endif; ?> - <label class="label" for="s_method_<?php /* @escapeNotVerified */ echo $_rate->getCode() ?>"><span><?php echo $block->escapeHtml($_rate->getMethodTitle()) ?> - <?php echo $block->getShippingPriceHtml($_rate); ?> - </span> - </label> - <?php endif ?> - </div> - <?php endforeach; ?> - </fieldset> - </dd> - <?php endforeach; ?> - </dl> - <div class="no-display" data-shipping-code-price='{<?php /* @escapeNotVerified */ echo implode(",",$shippingCodePrice); ?>}'></div> -<?php endif; ?> diff --git a/app/code/Magento/Checkout/view/frontend/web/js/opc-billing-info.js b/app/code/Magento/Checkout/view/frontend/web/js/opc-billing-info.js deleted file mode 100644 index 5ed385463d8bca9873012ce9effe69244762c47a..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/view/frontend/web/js/opc-billing-info.js +++ /dev/null @@ -1,57 +0,0 @@ -/** - * @category one page checkout second step - * @package mage - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -/*jshint browser:true jquery:true*/ -/*global alert*/ -/** - * @removeCandidate - */ -define([ - "jquery", - "jquery/ui", - "Magento_Checkout/js/opc-checkout-method", - "mage/validation" -], function($){ - 'use strict'; - - // Extension for mage.opcheckout - second section(Billing Information) in one page checkout accordion - $.widget('mage.opcBillingInfo', $.mage.opcCheckoutMethod, { - options: { - billing: { - form: '#co-billing-form', - continueSelector: '#opc-billing [data-role=opc-continue]', - addressDropdownSelector: '#billing\\:address-select', - newAddressFormSelector: '#billing-new-address-form', - emailAddressName: 'billing[email]' - } - }, - - _create: function() { - this._super(); - var events = {}; - events['change ' + this.options.billing.addressDropdownSelector] = function(e) { - this.element.find(this.options.billing.newAddressFormSelector).toggle(!$(e.target).val()); - }; - events['click ' + this.options.billing.continueSelector] = function() { - if ($(this.options.billing.form).validation && $(this.options.billing.form).validation('isValid')) { - this._billingSave(); - } - }; - this._on(events); - - this.element.find(this.options.billing.form).validation(); - } , - - _billingSave: function() { - this._ajaxContinue(this.options.billing.saveUrl, $(this.options.billing.form).serialize(), false, function() { - //Trigger indicating billing save. eg. GiftMessage listens to this to inject gift options - this.element.trigger('billingSave'); - }); - } - }); - - return $.mage.opcBillingInfo; -}); \ No newline at end of file diff --git a/app/code/Magento/Checkout/view/frontend/web/js/opc-checkout-method.js b/app/code/Magento/Checkout/view/frontend/web/js/opc-checkout-method.js deleted file mode 100644 index 0f92f6ea63362f1de7e995e7db9ee721d012b15c..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/view/frontend/web/js/opc-checkout-method.js +++ /dev/null @@ -1,291 +0,0 @@ -/** - * @category one page checkout first step - * @package mage - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -/*jshint browser:true jquery:true*/ -/*global alert*/ -/** - * @removeCandidate - */ -define([ - "jquery", - "accordion", - 'Magento_Ui/js/modal/alert', - "jquery/ui", - "mage/validation/validation", - "mage/translate" -], function($, accordion, alert){ - 'use strict'; - - // Base widget, handle ajax events and first section(Checkout Method) in one page checkout accordion - $.widget('mage.opcCheckoutMethod', { - options: { - checkout: { - loginGuestSelector: '[data-role=checkout-method-guest]', - loginRegisterSelector: '[data-role=checkout-method-register]', - loginFormSelector: 'form[data-role=login]', - continueSelector: '#opc-login [data-role=opc-continue]', - registerCustomerPasswordSelector: '#co-billing-form .field.password,#co-billing-form .field.confirm', - captchaGuestCheckoutSelector: '#co-billing-form [role="guest_checkout"]', - registerDuringCheckoutSelector: '#co-billing-form [role="register_during_checkout"]', - suggestRegistration: false - }, - pageMessages: '#maincontent .messages .message', - sectionSelectorPrefix: 'opc-', - billingSection: 'billing', - ajaxLoaderPlaceButton: false, - updateSelectorPrefix: '#checkout-', - updateSelectorSuffix: '-load', - backSelector: '.action.back', - minBalance: 0.0001, - methodsListContainer: 'dl', - methodContainer: 'dt', - methodDescription : 'dd ul', - methodOn: 'dt input:radio' - }, - - _create: function() { - var self = this; - - this._initAccordion(); - - this.sectionActiveClass = this.element.accordion("option","openedState"); - this.contentSelector = this.element.accordion("option","content"); - this.checkoutPrice = this.options.quoteBaseGrandTotal; - - if (this.options.checkout.suggestRegistration) { - $(this.options.checkout.loginGuestSelector).prop('checked', false); - $(this.options.checkout.loginRegisterSelector).prop('checked', true); - } - this._handleSteps(); - var events = {}; - events['click ' + this.options.checkout.continueSelector] = function(e) { - this._continue($(e.currentTarget)); - }; - events['click ' + this.options.backSelector] = function(event) { - event.preventDefault(); - var prev = self.steps.index($('li.' + self.sectionActiveClass)) -1 ; - this._activateSection(prev); - }; - events['click ' + '[data-action=checkout-method-login]'] = function(event) { - if($(self.options.checkout.loginFormSelector).validation('isValid')){ - self.element.find('.section').filter('.' + self.sectionActiveClass).children(self.contentSelector).trigger("processStart"); - event.preventDefault(); - setTimeout(function(){ - $(self.options.checkout.loginFormSelector).submit(); - }, 300); - } - }; - - $(document).on({ - 'ajaxError': this._ajaxError.bind(this) - }); - - $.extend(events, { - showAjaxLoader: '_ajaxSend', - hideAjaxLoader: '_ajaxComplete', - gotoSection: function(e, section) { - self.element.find('.section').filter('.' + self.sectionActiveClass).children(self.contentSelector).trigger("processStop"); - var toActivate = this.steps.index($('#' + self.options.sectionSelectorPrefix + section)); - this._activateSection(toActivate); - } - }); - this._on(events); - - this._on($(this.options.checkoutProgressContainer), { - 'click [data-goto-section]' : function(e) { - var gotoSection = $(e.target).data('goto-section'); - self.element.find('.section').filter('.' + self.sectionActiveClass).children(self.contentSelector).trigger("processStop"); - var toActivate = this.steps.index($('#' + self.options.sectionSelectorPrefix + gotoSection)); - this._activateSection(toActivate); - return false; - } - }); - }, - - _initAccordion: function(){ - var config = this.element.data('accordion'); - - accordion(config, this.element[0]); - }, - - /** - * Get the checkout steps, disable steps but first, adding callback on before opening section to - * disable all next steps - * @private - */ - _handleSteps: function() { - var self = this; - this.steps = $(this.element).children('[id^=' + this.options.sectionSelectorPrefix + ']'); - this.element.accordion("disable"); - this._activateSection(0); - $.each(this.steps,function() { - $(this).on("beforeOpen",function() { - $(this).nextAll('[id^=' + self.options.sectionSelectorPrefix + ']').collapsible("disable"); - $(this).prevAll('[id^=' + self.options.sectionSelectorPrefix + ']').collapsible("enable"); - }); - }); - }, - - /** - * Activate section - * @param index the index of section you want to open - * @private - */ - _activateSection: function(index) { - this.element.accordion("enable",index); - this.element.accordion("activate",index); - }, - - /** - * Callback function for before ajax send event(global) - * @private - */ - _ajaxSend: function() { - this.element.find('.section').filter('.' + this.sectionActiveClass).children(this.contentSelector).trigger("processStart"); - }, - - /** - * Callback function for ajax complete event(global) - * @private - */ - _ajaxComplete: function() { - this.element.find('.section').filter('.' + this.sectionActiveClass).children(this.contentSelector).trigger("processStop"); - }, - - /** - * ajax error for all onepage checkout ajax calls - * @private - */ - _ajaxError: function() { - window.location.href = this.options.failureUrl; - }, - - /** - * callback function when continue button is clicked - * @private - * @param elem - continue button - * @return {Boolean} - */ - _continue: function(elem) { - var json = elem.data('checkout'), - checkout = this.options.checkout, - guestChecked = $( checkout.loginGuestSelector ).is( ':checked' ), - registerChecked = $( checkout.loginRegisterSelector ).is( ':checked' ), - method = 'register', - isRegistration = true; - - //Remove page messages - $(this.options.pageMessages).remove(); - - if (json.isGuestCheckoutAllowed) { - - if( !guestChecked && !registerChecked ){ - alert({ - content: $.mage.__('Please create an account or check out as a guest.') - }); - - return false; - } - - if( guestChecked ){ - method = 'guest'; - isRegistration = false; - } - - this._ajaxContinue( - checkout.saveUrl, - { method: method }, - this.options.billingSection - ); - - this.element.find(checkout.registerCustomerPasswordSelector).toggle(isRegistration); - this.element.find(checkout.captchaGuestCheckoutSelector).toggle(!isRegistration); - this.element.find(checkout.registerDuringCheckoutSelector).toggle(isRegistration); - } - else if( json.registrationUrl ){ - window.location = json.registrationUrl; - } - - this.element.trigger('login'); - }, - - /** - * Ajax call to save checkout info to backend and enable next section in accordion - * @private - * @param url - ajax url - * @param data - post data for ajax call - * @param gotoSection - the section needs to show after ajax call - * @param successCallback - custom callback function in ajax success - */ - _ajaxContinue: function(url, data, gotoSection, successCallback) { - $.ajax({ - url: url, - type: 'post', - context: this, - data: data, - dataType: 'json', - beforeSend: this._ajaxSend, - complete: this._ajaxComplete, - success: function (response) { - if (successCallback) { - successCallback.call(this, response); - } - if ($.type(response) === 'object' && !$.isEmptyObject(response)) { - if (response.error) { - var msg = response.message || response.error_messages || response.error; - - if (msg) { - if (Array.isArray(msg)) { - msg = msg.reduce(function (str, chunk) { - str += '\n' + chunk; - return str; - }, ''); - } - - $(this.options.countrySelector).trigger('change'); - - alert({ - content: msg - }); - } - - return; - } - if (response.redirect) { - $.mage.redirect(response.redirect); - return false; - } - else if (response.success) { - $.mage.redirect(this.options.review.successUrl); - return false; - } - if (response.update_section) { - if (response.update_section.name === 'payment-method' && response.update_section.html.indexOf('data-checkout-price')) { - this.element.find(this.options.payment.form).find('[data-checkout-price]').remove(); - } - $(this.options.updateSelectorPrefix + response.update_section.name + this.options.updateSelectorSuffix) - .html($(response.update_section.html)).trigger('contentUpdated'); - } - if (response.update_progress) { - $(this.options.checkoutProgressContainer).html($(response.update_progress.html)).trigger('progressUpdated'); - } - if (response.duplicateBillingInfo) { - $(this.options.shipping.copyBillingSelector).prop('checked', true).trigger('click'); - $(this.options.shipping.addressDropdownSelector).val($(this.options.billing.addressDropdownSelector).val()).change(); - } - if (response.goto_section) { - this.element.trigger('gotoSection', response.goto_section); - } - } else { - this.element.trigger('gotoSection', gotoSection); - } - } - }); - } - }); - - return $.mage.opcCheckoutMethod; -}); diff --git a/app/code/Magento/Checkout/view/frontend/web/js/opc-order-review.js b/app/code/Magento/Checkout/view/frontend/web/js/opc-order-review.js deleted file mode 100644 index 83313faeebf5c513acfc11577db030f644b15500..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/view/frontend/web/js/opc-order-review.js +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @category one page checkout last step - * @package mage - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -/*jshint browser:true jquery:true*/ -/*global alert*/ -/** - * @removeCandidate - */ -define([ - "jquery", - "jquery/ui", - "Magento_Checkout/js/opc-payment-info" -], function($){ - 'use strict'; - - // Extension for mage.opcheckout - last section(Order Review) in one page checkout accordion - $.widget('mage.opcOrderReview', $.mage.opcPaymentInfo, { - options: { - review: { - continueSelector: '#opc-review [data-role=review-save]', - container: '#opc-review', - agreementGroupSelector: '#checkout-agreements' - } - }, - - _create: function() { - this._super(); - var events = {}; - events['click ' + this.options.review.continueSelector] = this._saveOrder; - events['saveOrder' + this.options.review.container] = this._saveOrder; - this._on(events); - }, - - _saveOrder: function() { - var agreementFormsGroup = $(this.options.review.agreementGroupSelector), - paymentForm = $(this.options.payment.form); - var isAgreementValid = true; - agreementFormsGroup.find('form').each( - function(){ - isAgreementValid = $(this).validation() && $(this).validation('isValid') && isAgreementValid; - } - ); - - if (isAgreementValid && - paymentForm.validation && - paymentForm.validation('isValid')) { - var serializedAgreement = ''; - agreementFormsGroup.find('form').each(function(){serializedAgreement += '&' + $(this).serialize();}); - this._ajaxContinue( - this.options.review.saveUrl, - paymentForm.serialize() + serializedAgreement); - } - } - }); - - return $.mage.opcOrderReview; -}); diff --git a/app/code/Magento/Checkout/view/frontend/web/js/opc-payment-info.js b/app/code/Magento/Checkout/view/frontend/web/js/opc-payment-info.js deleted file mode 100644 index bfa87548aea2a170d7372bbc547266c482e9d7f6..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/view/frontend/web/js/opc-payment-info.js +++ /dev/null @@ -1,178 +0,0 @@ -/** - * @category one page checkout fifth step - * @package mage - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -/*jshint browser:true*/ -/*global alert*/ -/** - * @removeCandidate - */ -define([ - 'jquery', - 'mage/template', - 'Magento_Ui/js/modal/alert', - 'jquery/ui', - 'mage/translate', - 'Magento_Checkout/js/opc-shipping-method' -], function ($, mageTemplate, alert) { - 'use strict'; - - // Extension for mage.opcheckout - fifth section(Payment Information) in one page checkout accordion - $.widget('mage.opcPaymentInfo', $.mage.opcShippingMethod, { - options: { - payment: { - form: '#co-payment-form', - continueSelector: '#payment [data-role=opc-continue]', - methodsContainer: '#checkout-payment-method-load', - freeInput: { - tmpl: '<input id="hidden-free" type="hidden" name="payment[method]" value="free">', - selector: '#hidden-free' - } - } - }, - - _create: function () { - this._super(); - - var events = {}; - - this.freeInputTmpl = mageTemplate(this.options.payment.freeInput.tmpl); - - events['click ' + this.options.payment.continueSelector] = function () { - if (this._validatePaymentMethod() && - $(this.options.payment.form).validation && - $(this.options.payment.form).validation('isValid')) { - this._ajaxContinue(this.options.payment.saveUrl, $(this.options.payment.form).serialize()); - } - }; - - events['contentUpdated ' + this.options.payment.form] = function () { - $(this.options.payment.form).find('dd [name^="payment["]').prop('disabled', true); - var checkoutPrice = this.element.find(this.options.payment.form).find('[data-checkout-price]').data('checkout-price'); - - if ($.isNumeric(checkoutPrice)) { - this.checkoutPrice = checkoutPrice; - } - - if (this.checkoutPrice < this.options.minBalance) { - this._disablePaymentMethods(); - } else { - this._enablePaymentMethods(); - } - }; - - events['click ' + this.options.payment.form + ' dt input:radio'] = '_paymentMethodHandler'; - - $.extend(events, { - updateCheckoutPrice: function (event, data) { - if (data.price) { - this.checkoutPrice += data.price; - } - - if (data.totalPrice) { - data.totalPrice = this.checkoutPrice; - } - - if (this.checkoutPrice < this.options.minBalance) { - // Add free input field, hide and disable unchecked checkbox payment method and all radio button payment methods - this._disablePaymentMethods(); - } else { - // Remove free input field, show all payment method - this._enablePaymentMethods(); - } - } - }); - - this._on(events); - - this.element.find(this.options.payment.form).validation({ - errorPlacement: function (error, element) { - if (element.attr('data-validate') && element.attr('data-validate').indexOf('validate-cc-ukss') >= 0) { - element.parents('form').find('[data-validation-msg="validate-cc-ukss"]').html(error); - } else { - element.after(error); - } - } - }); - }, - - /** - * Display payment details when payment method radio button is checked - * @private - * @param {EventObject} e - */ - _paymentMethodHandler: function (e) { - var _this = $(e.target), - parentsDl = _this.closest(this.options.methodsListContainer); - parentsDl.find(this.options.methodOn).prop('checked', false); - _this.prop('checked', true); - parentsDl.find(this.options.methodDescription).hide().find('[name^="payment["]').prop('disabled', true); - _this.parent().nextUntil(this.options.methodContainer).find(this.options.methodDescription).show().find('[name^="payment["]').prop('disabled', false); - }, - - /** - * make sure one payment method is selected - * @private - * @return {Boolean} - */ - _validatePaymentMethod: function () { - var methods = this.element.find('[name^="payment["]'); - - if (methods.length === 0) { - alert({ - content: $.mage.__('We can\'t complete your order because you don\'t have a payment method set up.') - }); - - return false; - } - - if (this.checkoutPrice < this.options.minBalances) { - return true; - } else if (methods.filter('input:radio:checked').length) { - return true; - } - - alert({ - content: $.mage.__('Please choose a payment method.') - }); - - return false; - }, - - /** - * Disable and enable payment methods - * @private - */ - _disablePaymentMethods: function () { - var paymentForm = $(this.options.payment.form), - tmpl = this.freeInputTmpl({ - data: {} - }); - - paymentForm.find('input[name="payment[method]"]').prop('disabled', true); - paymentForm.find(this.options.payment.methodsContainer).find('[name^="payment["]').prop('disabled', true); - paymentForm.find('input[id^="use"][name^="payment[use"]:not(:checked)').prop('disabled', true).parent(); - paymentForm.find(this.options.payment.freeInput.selector).remove(); - - $(tmpl).appendTo(paymentForm); - }, - - /** - * Enable and enable payment methods - * @private - */ - _enablePaymentMethods: function () { - var paymentForm = $(this.options.payment.form); - - paymentForm.find('input[name="payment[method]"]').prop('disabled', false); - paymentForm.find('input[name="payment[method]"]:checked').trigger('click'); - paymentForm.find(this.options.payment.methodsContainer).show(); - paymentForm.find('input[id^="use"][name^="payment[use"]:not(:checked)').prop('disabled', false).parent().show(); - paymentForm.find(this.options.payment.freeInput.selector).remove(); - } - }); - - return $.mage.opcPaymentInfo; -}); diff --git a/app/code/Magento/Checkout/view/frontend/web/js/opc-shipping-info.js b/app/code/Magento/Checkout/view/frontend/web/js/opc-shipping-info.js deleted file mode 100644 index bf3ef59bcf42938b341150c75d6df91d497be10f..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/view/frontend/web/js/opc-shipping-info.js +++ /dev/null @@ -1,81 +0,0 @@ -/** - * @category one page checkout third step - * @package mage - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -/*jshint browser:true jquery:true*/ -/*global alert*/ -/** - * @removeCandidate - */ -define([ - "jquery", - "jquery/ui", - "Magento_Checkout/js/opc-billing-info", - "mage/validation" -], function($){ - 'use strict'; - - // Extension for mage.opcheckout - third section(Shipping Information) in one page checkout accordion - $.widget('mage.opcShippingInfo', $.mage.opcBillingInfo, { - options: { - shipping: { - form: '#co-shipping-form', - continueSelector:'#shipping [data-role=opc-continue]', - addressDropdownSelector: '#shipping\\:address-select', - newAddressFormSelector: '#shipping-new-address-form', - copyBillingSelector: '#shipping\\:same_as_billing', - countrySelector: '#shipping\\:country_id' - } - }, - - _create: function() { - this._super(); - var events = {}; - var onInputPropChange = function() { - $(this.options.shipping.copyBillingSelector).prop('checked', false); - }; - events['change ' + this.options.shipping.addressDropdownSelector] = function(e) { - $(this.options.shipping.newAddressFormSelector).toggle(!$(e.target).val()); - onInputPropChange.call(this); - }; - // for guest checkout - events['input ' + this.options.shipping.form + ' :input[name]'] = onInputPropChange; - events['propertychange ' + this.options.shipping.form + ' :input[name]'] = onInputPropChange; - events['click ' + this.options.shipping.copyBillingSelector] = function(e) { - if ($(e.target).is(':checked')) { - this._billingToShipping(); - } - }; - events['click ' + this.options.shipping.continueSelector] = function() { - if ($(this.options.shipping.form).validation && $(this.options.shipping.form).validation('isValid')) { - this._ajaxContinue(this.options.shipping.saveUrl, $(this.options.shipping.form).serialize(), false, function() { - //Trigger indicating shipping save. eg. GiftMessage listens to this to inject gift options - this.element.trigger('shippingSave'); - }); - } - }; - this._on(events); - - this.element.find(this.options.shipping.form).validation(); - }, - - /** - * Copy billing address info to shipping address - * @private - */ - _billingToShipping: function() { - $(':input[name]', this.options.billing.form).each($.proxy(function(key, value) { - var fieldObj = $(value.id.replace('billing:', '#shipping\\:')); - fieldObj.val($(value).val()); - if (fieldObj.is("select")) { - fieldObj.trigger('change'); - } - }, this)); - $(this.options.shipping.copyBillingSelector).prop('checked', true); - } - }); - - return $.mage.opcShippingInfo; -}); \ No newline at end of file diff --git a/app/code/Magento/Checkout/view/frontend/web/js/opc-shipping-method.js b/app/code/Magento/Checkout/view/frontend/web/js/opc-shipping-method.js deleted file mode 100644 index 505db47ab57901c4dcc73330ed27ebf66d0a4968..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/view/frontend/web/js/opc-shipping-method.js +++ /dev/null @@ -1,85 +0,0 @@ -/** - * @category one page checkout fourth step - * @package mage - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -/*jshint browser:true jquery:true*/ -/*global alert*/ -/** - * @removeCandidate - */ -define([ - "jquery", - 'Magento_Ui/js/modal/alert', - "jquery/ui", - "Magento_Checkout/js/opc-shipping-info", - "mage/validation", - "mage/translate" -], function($, alert){ - 'use strict'; - - // Extension for mage.opcheckout - fourth section(Shipping Method) in one page checkout accordion - $.widget('mage.opcShippingMethod', $.mage.opcShippingInfo, { - options: { - shippingMethod: { - form: '#co-shipping-method-form', - continueSelector: '#opc-shipping_method [data-role=opc-continue]' - } - }, - - _create: function() { - this._super(); - var events = {}; - events['click ' + this.options.shippingMethod.continueSelector] = function() { - if (this._validateShippingMethod()&& - $(this.options.shippingMethod.form).validation && - $(this.options.shippingMethod.form).validation('isValid')) { - this._ajaxContinue(this.options.shippingMethod.saveUrl, $(this.options.shippingMethod.form).serialize()); - } - }; - $.extend(events, { - 'click input[name=shipping_method]': function(e) { - var selectedPrice = this.shippingCodePrice[$(e.target).val()] || 0, - oldPrice = this.shippingCodePrice[this.currentShippingMethod] || 0; - this.checkoutPrice = this.checkoutPrice - oldPrice + selectedPrice; - this.currentShippingMethod = $(e.target).val(); - }, - 'contentUpdated': function() { - this.currentShippingMethod = this.element.find('input[name="shipping_method"]:checked').val(); - this.shippingCodePrice = this.element.find('[data-shipping-code-price]').data('shipping-code-price'); - } - }); - this._on(events); - - this.element.find(this.options.shippingMethod.form).validation(); - }, - - /** - * Make sure at least one shipping method is selected - * @return {Boolean} - * @private - */ - _validateShippingMethod: function() { - var methods = this.element.find('[name="shipping_method"]'); - if (methods.length === 0) { - alert({ - content: $.mage.__('We can\'t ship to this address. Please enter another address or edit this one.') - }); - - return false; - } - - if (methods.filter(':checked').length) { - return true; - } - alert({ - content:$.mage.__('Please specify a shipping method.') - }); - - return false; - } - }); - - return $.mage.opcShippingMethod; -}); \ No newline at end of file diff --git a/app/code/Magento/Checkout/view/frontend/web/js/opcheckout.js b/app/code/Magento/Checkout/view/frontend/web/js/opcheckout.js deleted file mode 100644 index 570dd9edf2d892eb39266dc467fc85f2861c84fc..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/view/frontend/web/js/opcheckout.js +++ /dev/null @@ -1,645 +0,0 @@ -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -/*jshint browser:true*/ -/*global alert*/ -/** - * @removeCandidate - */ -define([ - 'jquery', - 'mage/template', - 'Magento_Ui/js/modal/alert', - 'jquery/ui', - 'mage/validation', - 'mage/translate' -], function ($, mageTemplate, alert) { - 'use strict'; - - // Base widget, handle ajax events and first section(Checkout Method) in one page checkout accordion - $.widget('mage.opcheckout', { - options: { - checkout: { - loginGuestSelector: '#login\\:guest', - loginRegisterSelector: '#login\\:register', - loginFormSelector: '#login-form', - continueSelector: '#onepage-guest-register-button', - registerCustomerPasswordSelector: '#co-billing-form .field.password,#co-billing-form .field.confirm', - suggestRegistration: false - }, - sectionSelectorPrefix: '#opc-', - billingSection: 'billing', - ajaxLoaderPlaceButton: false, - updateSelectorPrefix: '#checkout-', - updateSelectorSuffix: '-load', - backSelector: '.action.back', - minBalance: 0.0001, - methodsListContainer: 'dl', - methodContainer: 'dt', - methodDescription: 'dd ul', - methodOn: 'dt input:radio' - }, - - _create: function () { - var events = {}; - - this.checkoutPrice = this.options.quoteBaseGrandTotal; - - if (this.options.checkout.suggestRegistration) { - $(this.options.checkout.loginGuestSelector).prop('checked', false); - $(this.options.checkout.loginRegisterSelector).prop('checked', true); - } - - events['click ' + this.options.checkout.continueSelector] = function (e) { - this._continue($(e.currentTarget)); - }; - - events['click ' + this.options.backSelector] = function () { - this.element.trigger('enableSection', { - selector: '#' + this.element.find('.active').prev().attr('id') - }); - }; - - $(document).on({ - 'ajaxError': this._ajaxError.bind(this) - }); - - $.extend(events, { - showAjaxLoader: '_ajaxSend', - hideAjaxLoader: '_ajaxComplete', - gotoSection: function (e, section) { - this._ajaxUpdateProgress(section); - this.element.trigger('enableSection', { - selector: this.options.sectionSelectorPrefix + section - }); - }, - 'click [data-action=login-form-submit]': function () { - $(this.options.checkout.loginFormSelector).submit(); - } - }); - - this._on(events); - - this._on($(this.options.checkoutProgressContainer), { - 'click [data-goto-section]': function (e) { - var gotoSection = $(e.target).data('goto-section'); - - this._ajaxUpdateProgress(gotoSection); - - this.element.trigger('enableSection', { - selector: this.options.sectionSelectorPrefix + gotoSection - }); - - return false; - } - }); - }, - - /** - * Callback function for before ajax send event(global) - * @private - */ - _ajaxSend: function () { - var loader; - - this.element.addClass('loading'); - - loader = this.element.find('.please-wait').show(); - - if (this.options.ajaxLoaderPlaceButton) { - loader.siblings('.button').hide(); - } - }, - - /** - * Callback function for ajax complete event(global) - * @private - */ - _ajaxComplete: function () { - this.element.removeClass('loading'); - this.element.find('.please-wait').hide(); - - if (this.options.ajaxLoaderPlaceButton) { - this.element.find('.button').show(); - } - }, - - /** - * ajax error for all onepage checkout ajax calls - * @private - */ - _ajaxError: function () { - window.location.href = this.options.failureUrl; - }, - - /** - * callback function when continue button is clicked - * @private - * @param elem - continue button - * @return {Boolean} - */ - _continue: function (elem) { - var json = elem.data('checkout'); - - if (json.isGuestCheckoutAllowed) { - if ($(this.options.checkout.loginGuestSelector).is(':checked')) { - this._ajaxContinue(this.options.checkout.saveUrl, { - method: 'guest' - }, this.options.billingSection); - - this.element.find(this.options.checkout.registerCustomerPasswordSelector).hide(); - } else if ($(this.options.checkout.loginRegisterSelector).is(':checked')) { - this._ajaxContinue(this.options.checkout.saveUrl, { - method: 'register' - }, this.options.billingSection); - - this.element.find(this.options.checkout.registerCustomerPasswordSelector).show(); - } else { - alert({ - content: $.mage.__('Please create an account or check out as a guest.') - }); - - return false; - } - } else { - if (json.registrationUrl) { - window.location.href = json.registrationUrl; - } - } - - this.element.trigger('login'); - }, - - /** - * Ajax call to save checkout info to backend and enable next section in accordion - * @private - * @param url - ajax url - * @param data - post data for ajax call - * @param gotoSection - the section needs to show after ajax call - * @param successCallback - custom callback function in ajax success - */ - _ajaxContinue: function (url, data, gotoSection, successCallback) { - $.ajax({ - url: url, - type: 'post', - context: this, - data: data, - dataType: 'json', - beforeSend: this._ajaxSend, - complete: this._ajaxComplete, - success: function (response) { - if (successCallback) { - successCallback.call(this, response); - } - - if ($.type(response) === 'object' && !$.isEmptyObject(response)) { - if (response.error) { - var msg = response.message || response.error_messages; - - if (msg) { - if ($.type(msg) === 'array') { - msg = msg.join("\n"); - } - - $(this.options.countrySelector).trigger('change'); - - alert({ - content: msg - }); - } else { - alert({ - content: response.error - }); - } - - return; - } - - if (response.redirect) { - $.mage.redirect(response.redirect); - - return false; - } else if (response.success) { - $.mage.redirect(this.options.review.successUrl); - - return false; - } - - if (response.update_section) { - if (response.update_section.name === 'payment-method' && response.update_section.html.indexOf('data-checkout-price')) { - this.element.find(this.options.payment.form).find('[data-checkout-price]').remove(); - } - $(this.options.updateSelectorPrefix + response.update_section.name + this.options.updateSelectorSuffix) - .html($(response.update_section.html)).trigger('contentUpdated'); - } - - if (response.duplicateBillingInfo) { - $(this.options.shipping.copyBillingSelector).prop('checked', true).trigger('click'); - $(this.options.shipping.addressDropdownSelector).val($(this.options.billing.addressDropdownSelector).val()).change(); - } - - if (response.goto_section) { - this.element.trigger('gotoSection', response.goto_section); - } - } else { - this.element.trigger('gotoSection', gotoSection); - } - } - }); - }, - - /** - * Update progress sidebar content - * @private - * @param {*} toStep - */ - _ajaxUpdateProgress: function (toStep) { - if (toStep) { - $.ajax({ - url: this.options.progressUrl, - type: 'get', - async: false, - cache: false, - context: this, - data: toStep ? { - toStep: toStep - } : null, - success: function (response) { - $(this.options.checkoutProgressContainer).html(response); - } - }); - } - } - }); - - // Extension for mage.opcheckout - second section(Billing Information) in one page checkout accordion - $.widget('mage.opcheckout', $.mage.opcheckout, { - options: { - billing: { - addressDropdownSelector: '#billing\\:address-select', - newAddressFormSelector: '#billing-new-address-form', - continueSelector: '#billing-buttons-container .button', - form: '#co-billing-form' - } - }, - - _create: function () { - var events; - - this._super(); - - events = {}; - - events['change ' + this.options.billing.addressDropdownSelector] = function (e) { - this.element.find(this.options.billing.newAddressFormSelector).toggle(!$(e.target).val()); - }; - - events['click ' + this.options.billing.continueSelector] = function () { - if ($(this.options.billing.form).validation && $(this.options.billing.form).validation('isValid')) { - this._billingSave(); - } - }; - - this._on(events); - - this.element.find(this.options.billing.form).validation(); - }, - - _billingSave: function () { - this._ajaxContinue(this.options.billing.saveUrl, $(this.options.billing.form).serialize(), false, function () { - //Trigger indicating billing save. eg. GiftMessage listens to this to inject gift options - this.element.trigger('billingSave'); - }); - } - }); - - // Extension for mage.opcheckout - third section(Shipping Information) in one page checkout accordion - $.widget('mage.opcheckout', $.mage.opcheckout, { - options: { - shipping: { - form: '#co-shipping-form', - addressDropdownSelector: '#shipping\\:address-select', - newAddressFormSelector: '#shipping-new-address-form', - copyBillingSelector: '#shipping\\:same_as_billing', - countrySelector: '#shipping\\:country_id', - continueSelector: '#shipping-buttons-container .button' - } - }, - - _create: function () { - var events, - onInputPropChange; - - this._super(); - - events = {}; - - onInputPropChange = function () { - $(this.options.shipping.copyBillingSelector).prop('checked', false); - }; - - events['change ' + this.options.shipping.addressDropdownSelector] = function (e) { - $(this.options.shipping.newAddressFormSelector).toggle(!$(e.target).val()); - onInputPropChange.call(this); - }; - - // for guest checkout - events['input ' + this.options.shipping.form + ' :input[name]'] = onInputPropChange; - - events['propertychange ' + this.options.shipping.form + ' :input[name]'] = onInputPropChange; - - events['click ' + this.options.shipping.copyBillingSelector] = function (e) { - if ($(e.target).is(':checked')) { - this._billingToShipping(); - } - }; - - events['click ' + this.options.shipping.continueSelector] = function () { - if ($(this.options.shipping.form).validation && $(this.options.shipping.form).validation('isValid')) { - this._ajaxContinue(this.options.shipping.saveUrl, $(this.options.shipping.form).serialize(), false, function () { - //Trigger indicating shipping save. eg. GiftMessage listens to this to inject gift options - this.element.trigger('shippingSave'); - }); - } - }; - - this._on(events); - - this.element.find(this.options.shipping.form).validation(); - }, - - /** - * Copy billing address info to shipping address - * @private - */ - _billingToShipping: function () { - $(':input[name]', this.options.billing.form).each($.proxy(function (key, value) { - var fieldObj = $(value.id.replace('billing:', '#shipping\\:')); - - fieldObj.val($(value).val()); - - if (fieldObj.is('select')) { - fieldObj.trigger('change'); - } - }, this)); - - $(this.options.shipping.copyBillingSelector).prop('checked', true); - } - }); - - // Extension for mage.opcheckout - fourth section(Shipping Method) in one page checkout accordion - $.widget('mage.opcheckout', $.mage.opcheckout, { - options: { - shippingMethod: { - continueSelector: '#shipping-method-buttons-container .button', - form: '#co-shipping-method-form' - } - }, - - _create: function () { - this._super(); - var events = {}; - events['click ' + this.options.shippingMethod.continueSelector] = function () { - if (this._validateShippingMethod() && - $(this.options.shippingMethod.form).validation && - $(this.options.shippingMethod.form).validation('isValid')) { - this._ajaxContinue(this.options.shippingMethod.saveUrl, $(this.options.shippingMethod.form).serialize()); - } - }; - $.extend(events, { - 'click input[name=shipping_method]': function (e) { - var selectedPrice = this.shippingCodePrice[$(e.target).val()] || 0, - oldPrice = this.shippingCodePrice[this.currentShippingMethod] || 0; - this.checkoutPrice = this.checkoutPrice - oldPrice + selectedPrice; - this.currentShippingMethod = $(e.target).val(); - }, - 'contentUpdated': function () { - this.currentShippingMethod = this.element.find('input[name="shipping_method"]:checked').val(); - this.shippingCodePrice = this.element.find('[data-shipping-code-price]').data('shipping-code-price'); - } - }); - this._on(events); - - this.element.find(this.options.shippingMethod.form).validation(); - }, - - /** - * Make sure at least one shipping method is selected - * @return {Boolean} - * @private - */ - _validateShippingMethod: function () { - var methods = this.element.find('[name="shipping_method"]'); - - if (methods.length === 0) { - alert({ - content: $.mage.__('We can\'t ship to this address. Please choose another address or edit the current one.') - }); - - return false; - } - - if (methods.filter(':checked').length) { - return true; - } - - alert({ - content: $.mage.__('Please specify a shipping method.') - }); - - return false; - } - }); - - // Extension for mage.opcheckout - fifth section(Payment Information) in one page checkout accordion - $.widget('mage.opcheckout', $.mage.opcheckout, { - options: { - payment: { - continueSelector: '#payment-buttons-container .button', - form: '#co-payment-form', - methodsContainer: '#checkout-payment-method-load', - freeInput: { - tmpl: '<input id="hidden-free" type="hidden" name="payment[method]" value="free">', - selector: '#hidden-free' - } - } - }, - - _create: function () { - var events; - - this._super(); - - this.freeInputTmpl = mageTemplate(this.options.payment.freeInput.tmpl); - - events = {}; - - events['click ' + this.options.payment.continueSelector] = function () { - if (this._validatePaymentMethod() && - $(this.options.payment.form).validation && - $(this.options.payment.form).validation('isValid')) { - this._ajaxContinue(this.options.payment.saveUrl, $(this.options.payment.form).serialize()); - } - }; - - events['contentUpdated ' + this.options.payment.form] = function () { - var checkoutPrice; - - $(this.options.payment.form).find('dd [name^="payment["]').prop('disabled', true); - - checkoutPrice = this.element.find(this.options.payment.form).find('[data-checkout-price]').data('checkout-price'); - - if ($.isNumeric(checkoutPrice)) { - this.checkoutPrice = checkoutPrice; - } - - if (this.checkoutPrice < this.options.minBalance) { - this._disablePaymentMethods(); - } else { - this._enablePaymentMethods(); - } - }; - - events['click ' + this.options.payment.form + ' dt input:radio'] = '_paymentMethodHandler'; - - $.extend(events, { - updateCheckoutPrice: function (event, data) { - if (data.price) { - this.checkoutPrice += data.price; - } - - if (data.totalPrice) { - data.totalPrice = this.checkoutPrice; - } - - if (this.checkoutPrice < this.options.minBalance) { - // Add free input field, hide and disable unchecked checkbox payment method and all radio button payment methods - this._disablePaymentMethods(); - } else { - // Remove free input field, show all payment method - this._enablePaymentMethods(); - } - } - }); - - this._on(events); - - this.element.find(this.options.payment.form).validation({ - errorPlacement: function (error, element) { - if (element.attr('data-validate') && element.attr('data-validate').indexOf('validate-cc-ukss') >= 0) { - element.parents('form').find('[data-validation-msg="validate-cc-ukss"]').html(error); - } else { - element.after(error); - } - } - }); - }, - - /** - * Display payment details when payment method radio button is checked - * @private - * @param {EventObject} e - */ - _paymentMethodHandler: function (e) { - var _this = $(e.target), - parentsDl = _this.closest(this.options.methodsListContainer); - parentsDl.find(this.options.methodOn).prop('checked', false); - _this.prop('checked', true); - parentsDl.find(this.options.methodDescription).hide().find('[name^="payment["]').prop('disabled', true); - _this.closest(this.options.methodContainer) - .nextUntil(this.options.methodContainer) - .find(this.options.methodDescription).show().find('[name^="payment["]').prop('disabled', false); - }, - - /** - * make sure one payment method is selected - * @private - * @return {Boolean} - */ - _validatePaymentMethod: function () { - var methods = this.element.find('[name^="payment["]'); - - if (methods.length === 0) { - alert({ - content: $.mage.__('We can\'t complete your order because you don\'t have a payment method set up.') - }); - - return false; - } - - if (this.checkoutPrice < this.options.minBalance) { - return true; - } else if (methods.filter('input:radio:checked').length) { - return true; - } - - alert({ - content: $.mage.__('Please choose a payment method.') - }); - - return false; - }, - - /** - * Disable and enable payment methods - * @private - */ - _disablePaymentMethods: function () { - var paymentForm = $(this.options.payment.form), - tmpl = this.freeInputTmpl({ - data: {} - }); - - paymentForm.find('input[name="payment[method]"]').prop('disabled', true); - paymentForm.find(this.options.payment.methodsContainer).find('[name^="payment["]').prop('disabled', true); - paymentForm.find('input[id^="use"][name^="payment[use"]:not(:checked)').prop('disabled', true).parent(); - paymentForm.find(this.options.payment.freeInput.selector).remove(); - - $(tmpl).appendTo(paymentForm); - }, - - /** - * Enable and enable payment methods - * @private - */ - _enablePaymentMethods: function () { - var paymentForm = $(this.options.payment.form); - paymentForm.find('input[name="payment[method]"]').prop('disabled', false); - paymentForm.find('input[name="payment[method]"]:checked').trigger('click'); - paymentForm.find(this.options.payment.methodsContainer).show(); - paymentForm.find('input[id^="use"][name^="payment[use"]:not(:checked)').prop('disabled', false).parent().show(); - paymentForm.find(this.options.payment.freeInput.selector).remove(); - } - }); - - // Extension for mage.opcheckout - last section(Order Review) in one page checkout accordion - $.widget('mage.opcheckout', $.mage.opcheckout, { - options: { - review: { - continueSelector: '#review-buttons-container .button', - container: '#opc-review', - agreementFormSelector: '#checkout-agreements input[type="checkbox"]' - } - }, - - _create: function () { - this._super(); - var events = {}; - events['click ' + this.options.review.continueSelector] = this._saveOrder; - events['saveOrder' + this.options.review.container] = this._saveOrder; - this._on(events); - }, - - _saveOrder: function () { - if ($(this.options.payment.form).validation && - $(this.options.payment.form).validation('isValid')) { - this._ajaxContinue( - this.options.review.saveUrl, - $(this.options.payment.form).serialize() + '&' + $(this.options.review.agreementFormSelector).serialize()); - } - } - }); - - return $.mage.opcheckout; -}); diff --git a/app/code/Magento/Checkout/view/frontend/web/js/payment-authentication.js b/app/code/Magento/Checkout/view/frontend/web/js/payment-authentication.js deleted file mode 100644 index 8b03193bb79c95626391cfb4d75691def2f3a1cd..0000000000000000000000000000000000000000 --- a/app/code/Magento/Checkout/view/frontend/web/js/payment-authentication.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -/*jshint jquery:true*/ -/** - * @removeCandidate - */ -define([ - "jquery", - "jquery/ui" -], function($){ - "use strict"; - - $.widget('mage.paymentAuthentication', { - options : { - bodySelector: '[data-container="body"]' - }, - - _create: function () { - // add a trigger on the body for payment authentication state changes - this.element.closest(this.options.bodySelector).on("paymentAuthentication", $.proxy(this._paymentmentAthenticationTrigger, this)); - }, - - /** - * This method processes the paymentAuthentication actions. - */ - _paymentmentAthenticationTrigger: function (event, data) { - if (data.state === 'start') { - this.element.hide(); - } else { - this.element.show(); - } - } - }); - - return $.mage.paymentAuthentication; -}); \ No newline at end of file diff --git a/app/code/Magento/Checkout/view/frontend/web/js/proceed-to-checkout.js b/app/code/Magento/Checkout/view/frontend/web/js/proceed-to-checkout.js index 7a6b4e88be10c65b823c7616ac0e46a3ed5720a1..7754719a506ff406fb18b2b6f3a92aff3366073c 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/proceed-to-checkout.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/proceed-to-checkout.js @@ -8,15 +8,19 @@ define([ 'Magento_Customer/js/model/authentication-popup', 'Magento_Customer/js/customer-data' ], - function($, authenticationPopup, customerData) { + function ($, authenticationPopup, customerData) { + 'use strict'; + return function (config, element) { - $(element).click(function(event) { - event.preventDefault(); + $(element).click(function (event) { var cart = customerData.get('cart'), customer = customerData.get('customer'); + event.preventDefault(); + if (!customer().firstname && !cart().isGuestCheckoutAllowed) { authenticationPopup.showModal(); + return false; } location.href = config.checkoutUrl; diff --git a/app/code/Magento/Deploy/Model/Deployer.php b/app/code/Magento/Deploy/Model/Deployer.php index cada5a4549aee90b4f18f6df5a2588dd37d82c25..60480c220e23ccc1762243ab61075bf7fb7aec7b 100644 --- a/app/code/Magento/Deploy/Model/Deployer.php +++ b/app/code/Magento/Deploy/Model/Deployer.php @@ -6,6 +6,7 @@ namespace Magento\Deploy\Model; +use Magento\Framework\View\Asset\PreProcessor\AlternativeSourceInterface; use Magento\Framework\App\ObjectManagerFactory; use Magento\Framework\App\View\Deployment\Version; use Magento\Framework\App\View\Asset\Publisher; @@ -19,6 +20,7 @@ use Symfony\Component\Console\Output\OutputInterface; * A service for deploying Magento static view files for production mode * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ class Deployer { @@ -66,10 +68,18 @@ class Deployer protected $jsTranslationConfig; /** + * @var AlternativeSourceInterface[] + */ + private $alternativeSources; + + /** + * Constructor + * * @param Files $filesUtil * @param OutputInterface $output * @param Version\StorageInterface $versionStorage * @param JsTranslationConfig $jsTranslationConfig + * @param AlternativeSourceInterface[] $alternativeSources * @param bool $isDryRun */ public function __construct( @@ -77,6 +87,7 @@ class Deployer OutputInterface $output, Version\StorageInterface $versionStorage, JsTranslationConfig $jsTranslationConfig, + array $alternativeSources, $isDryRun = false ) { $this->filesUtil = $filesUtil; @@ -85,6 +96,13 @@ class Deployer $this->isDryRun = $isDryRun; $this->jsTranslationConfig = $jsTranslationConfig; $this->parentTheme = []; + + array_map( + function (AlternativeSourceInterface $alternative) { + }, + $alternativeSources + ); + $this->alternativeSources = $alternativeSources; } /** @@ -124,6 +142,7 @@ class Deployer 'design' => $design, ] ); + /** @var \Magento\RequireJs\Model\FileManager $fileManager */ $fileManager = $this->objectManager->create( 'Magento\RequireJs\Model\FileManager', [ @@ -148,11 +167,17 @@ class Deployer $this->findAncestors($area . Theme::THEME_PATH_SEPARATOR . $themePath) )) ) { - $this->deployFile($filePath, $area, $themePath, $locale, $module); + $compiledFile = $this->deployFile($filePath, $area, $themePath, $locale, $module); + if ($compiledFile !== '') { + $this->deployFile($compiledFile, $area, $themePath, $locale, $module); + } } } foreach ($libFiles as $filePath) { - $this->deployFile($filePath, $area, $themePath, $locale, null); + $compiledFile = $this->deployFile($filePath, $area, $themePath, $locale, null); + if ($compiledFile !== '') { + $this->deployFile($compiledFile, $area, $themePath, $locale, null); + } } if ($this->jsTranslationConfig->dictionaryEnabled()) { $this->deployFile( @@ -169,7 +194,7 @@ class Deployer } } } - $this->output->writeln("=== Minify templates ==="); + $this->output->writeln('=== Minify templates ==='); $this->count = 0; foreach ($this->filesUtil->getPhtmlFiles(false, false) as $template) { $this->htmlMinifier->minify($template); @@ -268,15 +293,25 @@ class Deployer * @param string $themePath * @param string $locale * @param string $module - * @return void + * @return string + * @throws \InvalidArgumentException + * * @SuppressWarnings(PHPMD.NPathComplexity) */ private function deployFile($filePath, $area, $themePath, $locale, $module) { - $requestedPath = $filePath; - if (substr($filePath, -5) == '.less') { - $requestedPath = preg_replace('/.less$/', '.css', $filePath); + $compiledFile = ''; + $extension = pathinfo($filePath, PATHINFO_EXTENSION); + + foreach ($this->alternativeSources as $name => $alternative) { + if (in_array($extension, $alternative->getAlternativesExtensionsNames(), true) + && strpos(basename($filePath), '_') !== 0 + ) { + $compiledFile = substr($filePath, 0, strlen($filePath) - strlen($extension) - 1); + $compiledFile = $compiledFile . '.' . $name; + } } + $logMessage = "Processing file '$filePath' for area '$area', theme '$themePath', locale '$locale'"; if ($module) { $logMessage .= ", module '$module'"; @@ -288,7 +323,7 @@ class Deployer try { $asset = $this->assetRepo->createAsset( - $requestedPath, + $filePath, ['area' => $area, 'theme' => $themePath, 'locale' => $locale, 'module' => $module] ); if ($this->output->isVeryVerbose()) { @@ -303,18 +338,13 @@ class Deployer $this->bundleManager->addAsset($asset); } $this->count++; - } catch (\Less_Exception_Compiler $e) { - $this->verboseLog( - "\tNotice: Could not parse LESS file '$filePath'. " - . "This may indicate that the file is incomplete, but this is acceptable. " - . "The file '$filePath' will be combined with another LESS file." - ); - $this->verboseLog("\tCompiler error: " . $e->getMessage()); } catch (\Exception $e) { - $this->output->writeln($e->getMessage() . " ($logMessage)"); + $this->output->write('.'); $this->verboseLog($e->getTraceAsString()); $this->errorCount++; } + + return $compiledFile; } /** diff --git a/app/code/Magento/Deploy/etc/di.xml b/app/code/Magento/Deploy/etc/di.xml index 9d0ed7220c62a84f0dec3c4baab07c7c49e11131..59fb508c691b53a6137a129bbcc2292acf752a3d 100644 --- a/app/code/Magento/Deploy/etc/di.xml +++ b/app/code/Magento/Deploy/etc/di.xml @@ -6,6 +6,13 @@ */ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> + <type name="Magento\Deploy\Model\Deployer"> + <arguments> + <argument name="alternativeSources" xsi:type="array"> + <item name="css" xsi:type="object">AlternativeSourceProcessors</item> + </argument> + </arguments> + </type> <type name="Magento\Framework\Console\CommandList"> <arguments> <argument name="commands" xsi:type="array"> diff --git a/app/code/Magento/Developer/Console/Command/CssDeployCommand.php b/app/code/Magento/Developer/Console/Command/CssDeployCommand.php index 4abf04b34f01f82ef58b214bf442202634949664..ac651b633d026790bfe6d6d3a50283303e00eaa1 100644 --- a/app/code/Magento/Developer/Console/Command/CssDeployCommand.php +++ b/app/code/Magento/Developer/Console/Command/CssDeployCommand.php @@ -6,6 +6,7 @@ namespace Magento\Developer\Console\Command; +use Magento\Framework\View\Asset\PreProcessor\Pool; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; @@ -17,7 +18,6 @@ use Magento\Framework\App\State; use Magento\Framework\View\Asset\Repository; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\App\ObjectManager\ConfigLoader; -use Magento\Framework\View\Asset\SourceFileGeneratorPool; use Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Validator\Locale; @@ -73,11 +73,6 @@ class CssDeployCommand extends Command */ private $state; - /** - * @var SourceFileGeneratorPool - */ - private $sourceFileGeneratorPool; - /** * @var Source */ @@ -98,6 +93,11 @@ class CssDeployCommand extends Command */ private $validator; + /** + * @var Pool + */ + private $pool; + /** * Inject dependencies * @@ -106,10 +106,10 @@ class CssDeployCommand extends Command * @param ConfigLoader $configLoader * @param State $state * @param Source $assetSource - * @param SourceFileGeneratorPool $sourceFileGeneratorPoll * @param ChainFactoryInterface $chainFactory * @param Filesystem $filesystem * @param Locale $validator + * @param Pool $pool */ public function __construct( ObjectManagerInterface $objectManager, @@ -117,22 +117,22 @@ class CssDeployCommand extends Command ConfigLoader $configLoader, State $state, Source $assetSource, - SourceFileGeneratorPool $sourceFileGeneratorPoll, ChainFactoryInterface $chainFactory, Filesystem $filesystem, - Locale $validator + Locale $validator, + Pool $pool ) { $this->state = $state; $this->objectManager = $objectManager; $this->configLoader = $configLoader; $this->assetRepo = $assetRepo; - $this->sourceFileGeneratorPool = $sourceFileGeneratorPoll; $this->assetSource = $assetSource; $this->chainFactory = $chainFactory; $this->filesystem = $filesystem; $this->validator = $validator; parent::__construct(); + $this->pool = $pool; } /** @@ -203,8 +203,6 @@ class CssDeployCommand extends Command $this->state->setAreaCode($area); $this->objectManager->configure($this->configLoader->load($area)); - $sourceFileGenerator = $this->sourceFileGeneratorPool->create($type); - foreach ($input->getArgument(self::FILE_ARGUMENT) as $file) { $file .= '.' . $type; @@ -233,14 +231,11 @@ class CssDeployCommand extends Command ] ); - $processedCoreFile = $sourceFileGenerator->generateFileTree($chain); - + $this->pool->process($chain); $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW); - $source = $rootDir->getRelativePath($processedCoreFile); - $destination = $asset->getPath(); - $rootDir->copyFile($source, $destination, $targetDir); + $targetDir->writeFile($chain->getAsset()->getPath(), $chain->getContent()); - $output->writeln("<info>Successfully processed dynamic stylesheet into CSS</info>"); + $output->writeln('<info>Successfully processed dynamic stylesheet into CSS</info>'); } } } diff --git a/app/code/Magento/Developer/Test/Unit/Console/Command/CssDeployCommandTest.php b/app/code/Magento/Developer/Test/Unit/Console/Command/CssDeployCommandTest.php index d274aa003133d2bd6a8bebc061113cb6e94cfd5d..0d930989e424eefbcd192c0c3ca33322c13ba06a 100644 --- a/app/code/Magento/Developer/Test/Unit/Console/Command/CssDeployCommandTest.php +++ b/app/code/Magento/Developer/Test/Unit/Console/Command/CssDeployCommandTest.php @@ -7,17 +7,20 @@ namespace Magento\Developer\Test\Unit\Console\Command; use Magento\Framework\Filesystem; +use Magento\Framework\View\Asset\PreProcessor\Pool; use Magento\Framework\View\Asset\Source; use Magento\Framework\App\State; use Magento\Framework\View\Asset\Repository; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\App\ObjectManager\ConfigLoader; -use Magento\Framework\View\Asset\SourceFileGeneratorPool; use Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface; use Magento\Developer\Console\Command\CssDeployCommand; use Symfony\Component\Console\Tester\CommandTester; use Magento\Framework\Validator\Locale; +/** + * Class CssDeployCommandTest + */ class CssDeployCommandTest extends \PHPUnit_Framework_TestCase { /** @@ -45,11 +48,6 @@ class CssDeployCommandTest extends \PHPUnit_Framework_TestCase */ private $state; - /** - * @var SourceFileGeneratorPool|\PHPUnit_Framework_MockObject_MockObject - */ - private $sourceFileGeneratorPool; - /** * @var Source|\PHPUnit_Framework_MockObject_MockObject */ @@ -70,6 +68,11 @@ class CssDeployCommandTest extends \PHPUnit_Framework_TestCase */ private $validator; + /** + * @var Pool|\PHPUnit_Framework_MockObject_MockObject + */ + private $poolMock; + public function setUp() { $this->objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); @@ -77,18 +80,14 @@ class CssDeployCommandTest extends \PHPUnit_Framework_TestCase $this->configLoader = $this->getMock('Magento\Framework\App\ObjectManager\ConfigLoader', [], [], '', false); $this->state = $this->getMock('Magento\Framework\App\State', [], [], '', false); $this->assetSource = $this->getMock('Magento\Framework\View\Asset\Source', [], [], '', false); - $this->sourceFileGeneratorPool = $this->getMock( - 'Magento\Framework\View\Asset\SourceFileGeneratorPool', - [], - [], - '', - false - ); $this->chainFactory = $this->getMockForAbstractClass( 'Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface' ); $this->filesystem = $this->getMock('Magento\Framework\Filesystem', [], [], '', false); $this->validator = $this->getMock('Magento\Framework\Validator\Locale', [], [], '', false); + $this->poolMock = $this->getMockBuilder('Magento\Framework\View\Asset\PreProcessor\Pool') + ->disableOriginalConstructor() + ->getMock(); $this->command = new CssDeployCommand( $this->objectManager, @@ -96,10 +95,10 @@ class CssDeployCommandTest extends \PHPUnit_Framework_TestCase $this->configLoader, $this->state, $this->assetSource, - $this->sourceFileGeneratorPool, $this->chainFactory, $this->filesystem, - $this->validator + $this->validator, + $this->poolMock ); } @@ -109,10 +108,6 @@ class CssDeployCommandTest extends \PHPUnit_Framework_TestCase $this->configLoader->expects($this->once())->method('load')->with('frontend')->willReturn([]); $this->objectManager->expects($this->once())->method('configure'); - $this->sourceFileGeneratorPool->expects($this->once()) - ->method('create') - ->with('less') - ->willReturn($this->getMock('Magento\Framework\View\Asset\SourceFileGeneratorInterface')); $asset = $this->getMockForAbstractClass('Magento\Framework\View\Asset\LocalInterface'); $asset->expects($this->once())->method('getContentType')->willReturn('type'); $this->assetRepo->expects($this->once()) @@ -128,6 +123,10 @@ class CssDeployCommandTest extends \PHPUnit_Framework_TestCase ->willReturn($asset); $this->assetSource->expects($this->once())->method('findSource')->willReturn('/dev/null'); + $chainMock = $this->getMock('Magento\Framework\View\Asset\PreProcessor\Chain', [], [], '', false); + $assetMock = $this->getMockBuilder('Magento\Framework\View\Asset\LocalInterface') + ->getMockForAbstractClass(); + $this->chainFactory->expects($this->once()) ->method('create') ->with( @@ -137,8 +136,11 @@ class CssDeployCommandTest extends \PHPUnit_Framework_TestCase 'origContentType' => 'type', 'origAssetPath' => 'relative/path', ] - ) - ->willReturn($this->getMock('Magento\Framework\View\Asset\PreProcessor\Chain', [], [], '', false)); + )->willReturn($chainMock); + + $chainMock->expects(self::once()) + ->method('getAsset') + ->willReturn($assetMock); $rootDir = $this->getMock('\Magento\Framework\Filesystem\Directory\WriteInterface', [], [], '', false); $this->filesystem->expects($this->at(0))->method('getDirectoryWrite')->willReturn($rootDir); diff --git a/app/code/Magento/Developer/etc/di.xml b/app/code/Magento/Developer/etc/di.xml index c43c9e06ca2cfe9e1eee412b80729f12d1079df7..a208ec7c5de01f26250b2a93d5d571732899c2d6 100644 --- a/app/code/Magento/Developer/etc/di.xml +++ b/app/code/Magento/Developer/etc/di.xml @@ -8,7 +8,7 @@ <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Framework\View\Asset\PreProcessor\ChainFactoryInterface" type="Magento\Developer\Model\View\Asset\PreProcessor\DeveloperChainFactory"/> <preference for="Magento\Framework\Css\PreProcessor\ErrorHandlerInterface" type="Magento\Framework\Css\PreProcessor\ErrorHandler" /> - <preference for="Magento\Framework\Css\PreProcessor\AdapterInterface" type="Magento\Framework\Css\PreProcessor\Adapter\Less\Oyejorge" /> + <preference for="Magento\Framework\View\Asset\PreProcessor\Helper\SortInterface" type="Magento\Framework\View\Asset\PreProcessor\Helper\Sort"/> <type name="Magento\Framework\View\Result\Page"> <arguments> @@ -45,52 +45,58 @@ </arguments> </virtualType> + <virtualType name="viewFileFallbackResolver" type="Magento\Framework\View\Design\FileResolution\Fallback\Resolver\Alternative"/> - - <virtualType name="viewFileFallbackResolver" type="Magento\Framework\View\Design\FileResolution\Fallback\Resolver\Alternative"> + <virtualType name="AlternativeSourceProcessors" type="Magento\Framework\View\Asset\PreProcessor\AlternativeSource"> <arguments> - <argument name="alternativeExtensions" xsi:type="array"> - <item name="css" xsi:type="array"> - <item name="less" xsi:type="string">less</item> + <argument name="lockName" xsi:type="string">alternative-source-css</argument> + <argument name="lockerProcess" xsi:type="object">Magento\Framework\View\Asset\LockerProcess</argument> + <argument name="alternatives" xsi:type="array"> + <item name="less" xsi:type="array"> + <item name="class" xsi:type="string">Magento\Framework\Css\PreProcessor\Adapter\Less\Processor</item> </item> </argument> </arguments> </virtualType> + <type name="Magento\Framework\View\Asset\PreProcessor\Pool"> <arguments> - <argument name="preProcessors" xsi:type="array"> + <argument name="defaultPreprocessor" xsi:type="string">Magento\Framework\View\Asset\PreProcessor\Passthrough</argument> + <argument name="preprocessors" xsi:type="array"> <item name="less" xsi:type="array"> - <item name="css" xsi:type="array"> - <item name="less" xsi:type="string">Magento\Framework\Css\PreProcessor\Less</item> - <item name="variable_notation" xsi:type="string">Magento\Framework\View\Asset\PreProcessor\VariableNotation</item> - <item name="module_notation" xsi:type="string">Magento\Framework\View\Asset\PreProcessor\ModuleNotation</item> - <item name="css_min" xsi:type="string">cssMinificationProcessor</item> + <item name="magento_import" xsi:type="array"> + <item name="class" xsi:type="string">Magento\Framework\Css\PreProcessor\Instruction\MagentoImport</item> </item> - <item name="less" xsi:type="array"> - <item name="magento_import" xsi:type="string">Magento\Framework\Css\PreProcessor\Instruction\MagentoImport</item> - <item name="import" xsi:type="string">Magento\Framework\Css\PreProcessor\Instruction\Import</item> + <item name="import" xsi:type="array"> + <item name="after" xsi:type="string">magento_import</item> + <item name="class" xsi:type="string">Magento\Framework\Css\PreProcessor\Instruction\Import</item> </item> </item> <item name="css" xsi:type="array"> - <item name="css" xsi:type="array"> - <item name="variable_notation" xsi:type="string">Magento\Framework\View\Asset\PreProcessor\VariableNotation</item> - <item name="module_notation" xsi:type="string">Magento\Framework\View\Asset\PreProcessor\ModuleNotation</item> - <item name="css_min" xsi:type="string">cssMinificationProcessor</item> + <item name="alternativeSource" xsi:type="array"> + <item name="class" xsi:type="string">AlternativeSourceProcessors</item> + </item> + <item name="variable_notation" xsi:type="array"> + <item name="after" xsi:type="string">alternativeSource</item> + <item name="class" xsi:type="string">Magento\Framework\View\Asset\PreProcessor\VariableNotation</item> + </item> + <item name="module_notation" xsi:type="array"> + <item name="after" xsi:type="string">variable_notation</item> + <item name="class" xsi:type="string">Magento\Framework\View\Asset\PreProcessor\ModuleNotation</item> + </item> + <item name="css_min" xsi:type="array"> + <item name="after" xsi:type="string">module_notation</item> + <item name="class" xsi:type="string">cssMinificationProcessor</item> </item> </item> <item name="js" xsi:type="array"> - <item name="js" xsi:type="array"> - <item name="js_min" xsi:type="string">jsMinificationProcessor</item> + <item name="js_min" xsi:type="array"> + <item name="class" xsi:type="string">jsMinificationProcessor</item> </item> </item> </argument> </arguments> </type> - <type name="Magento\Framework\Css\PreProcessor\Less"> - <arguments> - <argument name="adapter" xsi:type="object">Magento\Framework\Css\PreProcessor\Adapter\Less\Oyejorge</argument> - </arguments> - </type> <type name="Magento\Framework\Css\PreProcessor\Instruction\MagentoImport"> <arguments> @@ -126,22 +132,4 @@ <argument name="subDir" xsi:type="string">web</argument> </arguments> </virtualType> - - <type name="Magento\Framework\View\Asset\SourceFileGeneratorPool"> - <arguments> - <argument name="fileGeneratorTypes" xsi:type="array"> - <item name="less" xsi:type="object">fileAssemblerFileGenerator</item> - </argument> - </arguments> - </type> - <virtualType name="fileAssemblerFileGenerator" type="Magento\Framework\Css\PreProcessor\FileGenerator"> - <arguments> - <argument name="relatedGenerator" xsi:type="object">fileAssemblerRelatedFilesGenerator</argument> - </arguments> - </virtualType> - <virtualType name="fileAssemblerRelatedFilesGenerator" type="Magento\Developer\Model\Css\PreProcessor\FileGenerator\PublicationDecorator"> - <arguments> - <argument name="publisher" xsi:type="object">developerPublisher</argument> - </arguments> - </virtualType> </config> diff --git a/app/code/Magento/Email/Model/Template/Filter.php b/app/code/Magento/Email/Model/Template/Filter.php index ebe3d0d8e2974409158217668265124e261bc860..a3cb0a5999688c6ad09a2175663835b3333eea50 100644 --- a/app/code/Magento/Email/Model/Template/Filter.php +++ b/app/code/Magento/Email/Model/Template/Filter.php @@ -5,6 +5,8 @@ */ namespace Magento\Email\Model\Template; +use Magento\Framework\View\Asset\ContentProcessorInterface; + /** * Core Email Template Filter Model * @@ -64,7 +66,7 @@ class Filter extends \Magento\Framework\Filter\Template * * @var int */ - protected $_storeId = null; + protected $_storeId; /** * @var array @@ -89,7 +91,7 @@ class Filter extends \Magento\Framework\Filter\Template /** * @var \Magento\Framework\Escaper */ - protected $_escaper = null; + protected $_escaper; /** * Core store config @@ -787,7 +789,7 @@ class Filter extends \Magento\Framework\Filter\Template $css = $this->getCssFilesContent([$params['file']]); - if (strpos($css, \Magento\Framework\Css\PreProcessor\AdapterInterface::ERROR_MESSAGE_PREFIX) !== false) { + if (strpos($css, ContentProcessorInterface::ERROR_MESSAGE_PREFIX) !== false) { // Return compilation error wrapped in CSS comment return '/*' . PHP_EOL . $css . PHP_EOL . '*/'; } elseif (!empty($css)) { @@ -908,7 +910,7 @@ class Filter extends \Magento\Framework\Filter\Template if ($html && $cssToInline) { try { // Don't try to compile CSS that has compilation errors - if (strpos($cssToInline, \Magento\Framework\Css\PreProcessor\AdapterInterface::ERROR_MESSAGE_PREFIX) + if (strpos($cssToInline, ContentProcessorInterface::ERROR_MESSAGE_PREFIX) !== false ) { throw new \Magento\Framework\Exception\MailException( diff --git a/app/code/Magento/Email/Test/Unit/Model/Template/FilterTest.php b/app/code/Magento/Email/Test/Unit/Model/Template/FilterTest.php index a21a6dbd30bf1b2c72d2c81b412d2c3bd9d321ab..cd7b55f4499e7a59564dfb73c94bfe0538b61d5f 100644 --- a/app/code/Magento/Email/Test/Unit/Model/Template/FilterTest.php +++ b/app/code/Magento/Email/Test/Unit/Model/Template/FilterTest.php @@ -282,7 +282,7 @@ class FilterTest extends \PHPUnit_Framework_TestCase ], 'CSS with error does not get inlined' => [ '<html><p></p></html>', - \Magento\Framework\Css\PreProcessor\AdapterInterface::ERROR_MESSAGE_PREFIX, + \Magento\Framework\View\Asset\ContentProcessorInterface::ERROR_MESSAGE_PREFIX, ['<html><p></p></html>'], ], 'Ensure disableStyleBlocksParsing option is working' => [ diff --git a/app/code/Magento/Multishipping/view/frontend/requirejs-config.js b/app/code/Magento/Multishipping/view/frontend/requirejs-config.js index 034ecbd8057cc90818703b5c87aca8e3aeec4078..dbbc46fd928660b3293d2fcd4d2f9a2c270ecb59 100644 --- a/app/code/Magento/Multishipping/view/frontend/requirejs-config.js +++ b/app/code/Magento/Multishipping/view/frontend/requirejs-config.js @@ -7,7 +7,8 @@ var config = { map: { '*': { multiShipping: 'Magento_Multishipping/js/multi-shipping', - orderOverview: 'Magento_Multishipping/js/overview' + orderOverview: 'Magento_Multishipping/js/overview', + payment: 'Magento_Multishipping/js/payment' } } }; \ No newline at end of file diff --git a/app/code/Magento/Checkout/view/frontend/web/js/payment.js b/app/code/Magento/Multishipping/view/frontend/web/js/payment.js similarity index 99% rename from app/code/Magento/Checkout/view/frontend/web/js/payment.js rename to app/code/Magento/Multishipping/view/frontend/web/js/payment.js index 1442bb787605236b3b40abfe430e9b98af6afd24..8baea212f57c07b5449d38b38987010f0f72f790 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/payment.js +++ b/app/code/Magento/Multishipping/view/frontend/web/js/payment.js @@ -4,9 +4,7 @@ */ /*jshint browser:true*/ /*global alert*/ -/** - * @removeCandidate - */ + define([ 'jquery', 'mage/template', diff --git a/app/code/Magento/Payment/Gateway/Command/CommandPool.php b/app/code/Magento/Payment/Gateway/Command/CommandPool.php index 6b1014d5aa76d9fefb8a1efb80583147067f2853..d1fc52a72378248b3a9cc87da3fd36d133924d93 100644 --- a/app/code/Magento/Payment/Gateway/Command/CommandPool.php +++ b/app/code/Magento/Payment/Gateway/Command/CommandPool.php @@ -18,17 +18,17 @@ class CommandPool implements CommandPoolInterface private $commands; /** - * @param array $commands * @param TMapFactory $tmapFactory + * @param array $commands */ public function __construct( - array $commands, - TMapFactory $tmapFactory + TMapFactory $tmapFactory, + array $commands = [] ) { $this->commands = $tmapFactory->create( [ 'array' => $commands, - 'type' => 'Magento\Payment\Gateway\CommandInterface' + 'type' => CommandInterface::class ] ); } diff --git a/app/code/Magento/Payment/Gateway/Config/ValueHandlerPool.php b/app/code/Magento/Payment/Gateway/Config/ValueHandlerPool.php index 0364336a2ea5e42df84c190359218276bd2aa168..b23964b064274e9e4d475c46a23d3448ff32024a 100644 --- a/app/code/Magento/Payment/Gateway/Config/ValueHandlerPool.php +++ b/app/code/Magento/Payment/Gateway/Config/ValueHandlerPool.php @@ -21,12 +21,12 @@ class ValueHandlerPool implements \Magento\Payment\Gateway\Config\ValueHandlerPo private $handlers; /** - * @param array $handlers * @param TMapFactory $tmapFactory + * @param array $handlers */ public function __construct( - array $handlers, - TMapFactory $tmapFactory + TMapFactory $tmapFactory, + array $handlers ) { if (!isset($handlers[self::DEFAULT_HANDLER])) { throw new \LogicException('Default handler should be provided.'); @@ -35,7 +35,7 @@ class ValueHandlerPool implements \Magento\Payment\Gateway\Config\ValueHandlerPo $this->handlers = $tmapFactory->create( [ 'array' => $handlers, - 'type' => 'Magento\Payment\Gateway\Config\ValueHandlerInterface' + 'type' => ValueHandlerInterface::class ] ); } diff --git a/app/code/Magento/Payment/Gateway/Request/BuilderComposite.php b/app/code/Magento/Payment/Gateway/Request/BuilderComposite.php index 66584773b638dfdc05a233ff4db10a7b1272794f..43f39b2932b40b81f06b0788f7b22827fda9f2fc 100644 --- a/app/code/Magento/Payment/Gateway/Request/BuilderComposite.php +++ b/app/code/Magento/Payment/Gateway/Request/BuilderComposite.php @@ -19,17 +19,17 @@ class BuilderComposite implements BuilderInterface private $builders; /** - * @param array $builders * @param TMapFactory $tmapFactory + * @param array $builders */ public function __construct( - array $builders, - TMapFactory $tmapFactory + TMapFactory $tmapFactory, + array $builders = [] ) { $this->builders = $tmapFactory->create( [ 'array' => $builders, - 'type' => 'Magento\Payment\Gateway\Request\BuilderInterface' + 'type' => BuilderInterface::class ] ); } diff --git a/app/code/Magento/Payment/Gateway/Response/HandlerChain.php b/app/code/Magento/Payment/Gateway/Response/HandlerChain.php index 1425514e7e3fb87054fdb09690d49d53c0b52a72..6a45311d5eb897b0ec15794cccc838995b747c04 100644 --- a/app/code/Magento/Payment/Gateway/Response/HandlerChain.php +++ b/app/code/Magento/Payment/Gateway/Response/HandlerChain.php @@ -16,17 +16,17 @@ class HandlerChain implements HandlerInterface private $handlers; /** - * @param array $handlers * @param TMapFactory $tmapFactory + * @param array $handlers */ public function __construct( - array $handlers, - TMapFactory $tmapFactory + TMapFactory $tmapFactory, + array $handlers = [] ) { $this->handlers = $tmapFactory->create( [ 'array' => $handlers, - 'type' => 'Magento\Payment\Gateway\Response\HandlerInterface' + 'type' => HandlerInterface::class ] ); } diff --git a/app/code/Magento/Payment/Gateway/Validator/ValidatorComposite.php b/app/code/Magento/Payment/Gateway/Validator/ValidatorComposite.php index 6e7c5c8c0ab5cecf0031ebc87519306289ea40e2..b36ceed14bdfa991d9fad107e120bb4b312a5316 100644 --- a/app/code/Magento/Payment/Gateway/Validator/ValidatorComposite.php +++ b/app/code/Magento/Payment/Gateway/Validator/ValidatorComposite.php @@ -18,18 +18,18 @@ class ValidatorComposite extends AbstractValidator /** * @param ResultInterfaceFactory $resultFactory - * @param array $validators * @param TMapFactory $tmapFactory + * @param array $validators */ public function __construct( ResultInterfaceFactory $resultFactory, - array $validators, - TMapFactory $tmapFactory + TMapFactory $tmapFactory, + array $validators = [] ) { $this->validators = $tmapFactory->create( [ 'array' => $validators, - 'type' => 'Magento\Payment\Gateway\Validator\ValidatorInterface' + 'type' => ValidatorInterface::class ] ); parent::__construct($resultFactory); diff --git a/app/code/Magento/Payment/Gateway/Validator/ValidatorPool.php b/app/code/Magento/Payment/Gateway/Validator/ValidatorPool.php index e2b746ea7334f480ef5fa3a83358081cea3289db..6697dd86c3d883ae85293b0307435820fb069e0e 100644 --- a/app/code/Magento/Payment/Gateway/Validator/ValidatorPool.php +++ b/app/code/Magento/Payment/Gateway/Validator/ValidatorPool.php @@ -17,17 +17,17 @@ class ValidatorPool implements \Magento\Payment\Gateway\Validator\ValidatorPoolI private $validators; /** - * @param array $validators * @param TMapFactory $tmapFactory + * @param array $validators */ public function __construct( - array $validators, - TMapFactory $tmapFactory + TMapFactory $tmapFactory, + array $validators = [] ) { $this->validators = $tmapFactory->create( [ 'array' => $validators, - 'type' => 'Magento\Payment\Gateway\Validator\ValidatorInterface' + 'type' => ValidatorInterface::class ] ); } diff --git a/app/code/Magento/Payment/Model/Method/Logger.php b/app/code/Magento/Payment/Model/Method/Logger.php index 7e7331b77df73d9f87624d733167eed0b9cdff08..47c91a25968ccb5560280e78659eebd892787308 100644 --- a/app/code/Magento/Payment/Model/Method/Logger.php +++ b/app/code/Magento/Payment/Model/Method/Logger.php @@ -41,21 +41,21 @@ class Logger /** * Logs payment related information used for debug * - * @param array $debugData - * @param array|null $debugReplaceKeys - * @param bool|null $debugFlag + * @param array $data + * @param array|null $maskKeys + * @param bool|null $forceDebug * @return void */ - public function debug(array $debugData, array $debugReplaceKeys = null, $debugFlag = null) + public function debug(array $data, array $maskKeys = null, $forceDebug = null) { - $debugReplaceKeys = $debugReplaceKeys !== null ? $debugReplaceKeys : $this->getDebugReplaceFields(); - $debugFlag = $debugFlag !== null ? $debugFlag : $this->isDebugOn(); - if ($debugFlag === true && !empty($debugData) && !empty($debugReplaceKeys)) { - $debugData = $this->filterDebugData( - $debugData, - $debugReplaceKeys + $maskKeys = $maskKeys !== null ? $maskKeys : $this->getDebugReplaceFields(); + $debugOn = $forceDebug !== null ? $forceDebug : $this->isDebugOn(); + if ($debugOn === true) { + $data = $this->filterDebugData( + $data, + $maskKeys ); - $this->logger->debug(var_export($debugData, true)); + $this->logger->debug(var_export($data, true)); } } @@ -66,7 +66,7 @@ class Logger */ private function getDebugReplaceFields() { - if ($this->config->getValue('debugReplaceKeys')) { + if ($this->config and $this->config->getValue('debugReplaceKeys')) { return explode(',', $this->config->getValue('debugReplaceKeys')); } return []; @@ -79,7 +79,7 @@ class Logger */ private function isDebugOn() { - return (bool)$this->config->getValue('debug'); + return $this->config and (bool)$this->config->getValue('debug'); } /** diff --git a/app/code/Magento/Payment/Test/Unit/Gateway/Command/CommandPoolTest.php b/app/code/Magento/Payment/Test/Unit/Gateway/Command/CommandPoolTest.php index 92394d8bb330ed66ed9fb6dc98f49666fb725155..7ab96f4474e497d197f4c91298e2e44430e5ccef 100644 --- a/app/code/Magento/Payment/Test/Unit/Gateway/Command/CommandPoolTest.php +++ b/app/code/Magento/Payment/Test/Unit/Gateway/Command/CommandPoolTest.php @@ -6,6 +6,7 @@ namespace Magento\Payment\Test\Unit\Gateway\Command; use Magento\Payment\Gateway\Command\CommandPool; +use Magento\Payment\Gateway\CommandInterface; class CommandPoolTest extends \PHPUnit_Framework_TestCase { @@ -26,7 +27,7 @@ class CommandPoolTest extends \PHPUnit_Framework_TestCase ->with( [ 'array' => ['Magento\Payment\Gateway\CommandInterface'], - 'type' => 'Magento\Payment\Gateway\CommandInterface' + 'type' => CommandInterface::class ] ) ->willReturn($tMap); @@ -39,7 +40,7 @@ class CommandPoolTest extends \PHPUnit_Framework_TestCase ->with('command') ->willReturn($commandI); - $pool = new CommandPool(['Magento\Payment\Gateway\CommandInterface'], $tMapFactory); + $pool = new CommandPool($tMapFactory, ['Magento\Payment\Gateway\CommandInterface']); static::assertSame($commandI, $pool->get('command')); } @@ -61,7 +62,7 @@ class CommandPoolTest extends \PHPUnit_Framework_TestCase ->with( [ 'array' => [], - 'type' => 'Magento\Payment\Gateway\CommandInterface' + 'type' => CommandInterface::class ] ) ->willReturn($tMap); @@ -70,7 +71,7 @@ class CommandPoolTest extends \PHPUnit_Framework_TestCase ->with('command') ->willReturn(false); - $pool = new CommandPool([], $tMapFactory); + $pool = new CommandPool($tMapFactory, []); $pool->get('command'); } } diff --git a/app/code/Magento/Payment/Test/Unit/Gateway/Config/ValueHandlerPoolTest.php b/app/code/Magento/Payment/Test/Unit/Gateway/Config/ValueHandlerPoolTest.php index 266128b42f6f9ee21b26c83e5e3caf0187163998..cac2d6c1c9d21b030c57b9cde07b8452b7b47e4b 100644 --- a/app/code/Magento/Payment/Test/Unit/Gateway/Config/ValueHandlerPoolTest.php +++ b/app/code/Magento/Payment/Test/Unit/Gateway/Config/ValueHandlerPoolTest.php @@ -5,6 +5,7 @@ */ namespace Magento\Payment\Test\Unit\Gateway\Config; +use Magento\Payment\Gateway\Config\ValueHandlerInterface; use Magento\Payment\Gateway\Config\ValueHandlerPool; class ValueHandlerPoolTest extends \PHPUnit_Framework_TestCase @@ -19,7 +20,7 @@ class ValueHandlerPoolTest extends \PHPUnit_Framework_TestCase $tMapFactory->expects(static::never()) ->method('create'); - new ValueHandlerPool([], $tMapFactory); + new ValueHandlerPool($tMapFactory, []); } public function testGet() @@ -46,7 +47,7 @@ class ValueHandlerPoolTest extends \PHPUnit_Framework_TestCase ValueHandlerPool::DEFAULT_HANDLER => 'Magento\Payment\Gateway\Config\ValueHandlerInterface', 'some_value' => 'Magento\Payment\Gateway\Config\ValueHandlerInterface' ], - 'type' => 'Magento\Payment\Gateway\Config\ValueHandlerInterface' + 'type' => ValueHandlerInterface::class ] ) ->willReturn($tMap); @@ -68,11 +69,11 @@ class ValueHandlerPoolTest extends \PHPUnit_Framework_TestCase ); $pool = new ValueHandlerPool( + $tMapFactory, [ ValueHandlerPool::DEFAULT_HANDLER => 'Magento\Payment\Gateway\Config\ValueHandlerInterface', 'some_value' => 'Magento\Payment\Gateway\Config\ValueHandlerInterface' - ], - $tMapFactory + ] ); static::assertSame($someValueHandler, $pool->get('some_value')); static::assertSame($defaultHandler, $pool->get(ValueHandlerPool::DEFAULT_HANDLER)); diff --git a/app/code/Magento/Payment/Test/Unit/Gateway/Request/BuilderCompositeTest.php b/app/code/Magento/Payment/Test/Unit/Gateway/Request/BuilderCompositeTest.php index e1e5ea547456a76f23629322b483718b5cf98e61..2c31c318db6780e30a087305e770fad38e181436 100644 --- a/app/code/Magento/Payment/Test/Unit/Gateway/Request/BuilderCompositeTest.php +++ b/app/code/Magento/Payment/Test/Unit/Gateway/Request/BuilderCompositeTest.php @@ -6,6 +6,7 @@ namespace Magento\Payment\Test\Unit\Gateway\Request; use Magento\Payment\Gateway\Request\BuilderComposite; +use Magento\Payment\Gateway\Request\BuilderInterface; class BuilderCompositeTest extends \PHPUnit_Framework_TestCase { @@ -24,7 +25,7 @@ class BuilderCompositeTest extends \PHPUnit_Framework_TestCase ->with( [ 'array' => [], - 'type' => 'Magento\Payment\Gateway\Request\BuilderInterface' + 'type' => BuilderInterface::class ] ) ->willReturn($tMap); @@ -32,7 +33,7 @@ class BuilderCompositeTest extends \PHPUnit_Framework_TestCase ->method('getIterator') ->willReturn(new \ArrayIterator([])); - $builder = new BuilderComposite([], $tMapFactory); + $builder = new BuilderComposite($tMapFactory, []); static::assertEquals([], $builder->build([])); } @@ -47,6 +48,7 @@ class BuilderCompositeTest extends \PHPUnit_Framework_TestCase 'item' => 'gas cooker', 'quantity' => 1 ]; + $tMapFactory = $this->getMockBuilder('Magento\Framework\ObjectManager\TMapFactory') ->disableOriginalConstructor() ->setMethods(['create']) @@ -96,7 +98,7 @@ class BuilderCompositeTest extends \PHPUnit_Framework_TestCase 'product' => 'Magento\Payment\Gateway\Request\BuilderInterface', 'magento' => 'Magento\Payment\Gateway\Request\BuilderInterface' ], - 'type' => 'Magento\Payment\Gateway\Request\BuilderInterface' + 'type' => BuilderInterface::class ] ) ->willReturn($tMap); @@ -105,12 +107,12 @@ class BuilderCompositeTest extends \PHPUnit_Framework_TestCase ->willReturn(new \ArrayIterator([$customerBuilder, $productBuilder, $magentoBuilder])); $builder = new BuilderComposite( + $tMapFactory, [ 'customer' => 'Magento\Payment\Gateway\Request\BuilderInterface', 'product' => 'Magento\Payment\Gateway\Request\BuilderInterface', 'magento' => 'Magento\Payment\Gateway\Request\BuilderInterface' - ], - $tMapFactory + ] ); static::assertEquals($expectedRequest, $builder->build([])); diff --git a/app/code/Magento/Payment/Test/Unit/Gateway/Response/HandlerChainTest.php b/app/code/Magento/Payment/Test/Unit/Gateway/Response/HandlerChainTest.php index c65a826a2624d79adff61fac919ce47385fac6ac..78891068b4cc07fd7a10aa9d80d333f65012cc83 100644 --- a/app/code/Magento/Payment/Test/Unit/Gateway/Response/HandlerChainTest.php +++ b/app/code/Magento/Payment/Test/Unit/Gateway/Response/HandlerChainTest.php @@ -6,6 +6,7 @@ namespace Magento\Payment\Test\Unit\Gateway\Response; use Magento\Payment\Gateway\Response\HandlerChain; +use Magento\Payment\Gateway\Response\HandlerInterface; class HandlerChainTest extends \PHPUnit_Framework_TestCase { @@ -31,7 +32,7 @@ class HandlerChainTest extends \PHPUnit_Framework_TestCase 'handler1' => 'Magento\Payment\Gateway\Response\HandlerInterface', 'handler2' => 'Magento\Payment\Gateway\Response\HandlerInterface' ], - 'type' => 'Magento\Payment\Gateway\Response\HandlerInterface' + 'type' => HandlerInterface::class ] ) ->willReturn($tMap); @@ -49,11 +50,11 @@ class HandlerChainTest extends \PHPUnit_Framework_TestCase ->with($handlingSubject, $response); $chain = new HandlerChain( + $tMapFactory, [ 'handler1' => 'Magento\Payment\Gateway\Response\HandlerInterface', 'handler2' => 'Magento\Payment\Gateway\Response\HandlerInterface' - ], - $tMapFactory + ] ); $chain->handle($handlingSubject, $response); } diff --git a/app/code/Magento/Payment/Test/Unit/Gateway/Validator/ValidatorCompositeTest.php b/app/code/Magento/Payment/Test/Unit/Gateway/Validator/ValidatorCompositeTest.php index 8528b65ac6cecf91bd5603009334a0b47f216137..27b589b02900d45d480fc32db141e075251dad92 100644 --- a/app/code/Magento/Payment/Test/Unit/Gateway/Validator/ValidatorCompositeTest.php +++ b/app/code/Magento/Payment/Test/Unit/Gateway/Validator/ValidatorCompositeTest.php @@ -6,6 +6,7 @@ namespace Magento\Payment\Test\Unit\Gateway\Validator; use Magento\Payment\Gateway\Validator\ValidatorComposite; +use Magento\Payment\Gateway\Validator\ValidatorInterface; class ValidatorCompositeTest extends \PHPUnit_Framework_TestCase { @@ -32,7 +33,7 @@ class ValidatorCompositeTest extends \PHPUnit_Framework_TestCase 'validator1' => 'Magento\Payment\Gateway\Validator\ValidatorInterface', 'validator2' => 'Magento\Payment\Gateway\Validator\ValidatorInterface' ], - 'type' => 'Magento\Payment\Gateway\Validator\ValidatorInterface' + 'type' => ValidatorInterface::class ] ) ->willReturn($tMap); @@ -82,11 +83,11 @@ class ValidatorCompositeTest extends \PHPUnit_Framework_TestCase $validatorComposite = new ValidatorComposite( $resultFactory, + $tMapFactory, [ 'validator1' => 'Magento\Payment\Gateway\Validator\ValidatorInterface', 'validator2' => 'Magento\Payment\Gateway\Validator\ValidatorInterface' - ], - $tMapFactory + ] ); static::assertSame($compositeResult, $validatorComposite->validate($validationSubject)); } diff --git a/app/code/Magento/Payment/Test/Unit/Gateway/Validator/ValidatorPoolTest.php b/app/code/Magento/Payment/Test/Unit/Gateway/Validator/ValidatorPoolTest.php index becc387fab2d91b86cc6ba3b13954c8c0c29ae05..dc6ed060ab7bf2d86895d15b27a04e2d7638efcd 100644 --- a/app/code/Magento/Payment/Test/Unit/Gateway/Validator/ValidatorPoolTest.php +++ b/app/code/Magento/Payment/Test/Unit/Gateway/Validator/ValidatorPoolTest.php @@ -5,6 +5,7 @@ */ namespace Magento\Payment\Test\Unit\Gateway\Validator; +use Magento\Payment\Gateway\Validator\ValidatorInterface; use Magento\Payment\Gateway\Validator\ValidatorPool; class ValidatorPoolTest extends \PHPUnit_Framework_TestCase @@ -26,7 +27,7 @@ class ValidatorPoolTest extends \PHPUnit_Framework_TestCase ->with( [ 'array' => ['validator' => 'Magento\Payment\Gateway\Validator\ValidatorInterface'], - 'type' => 'Magento\Payment\Gateway\Validator\ValidatorInterface' + 'type' => ValidatorInterface::class ] ) ->willReturn($tMap); @@ -40,8 +41,8 @@ class ValidatorPoolTest extends \PHPUnit_Framework_TestCase ->willReturn($commandI); $pool = new ValidatorPool( - ['validator' => 'Magento\Payment\Gateway\Validator\ValidatorInterface'], - $tMapFactory + $tMapFactory, + ['validator' => 'Magento\Payment\Gateway\Validator\ValidatorInterface'] ); static::assertSame($commandI, $pool->get('validator')); @@ -64,7 +65,7 @@ class ValidatorPoolTest extends \PHPUnit_Framework_TestCase ->with( [ 'array' => [], - 'type' => 'Magento\Payment\Gateway\Validator\ValidatorInterface' + 'type' => ValidatorInterface::class ] ) ->willReturn($tMap); @@ -73,7 +74,7 @@ class ValidatorPoolTest extends \PHPUnit_Framework_TestCase ->with('validator') ->willReturn(false); - $pool = new ValidatorPool([], $tMapFactory); + $pool = new ValidatorPool($tMapFactory, []); $pool->get('validator'); } } diff --git a/app/code/Magento/Payment/Test/Unit/Model/Method/LoggerTest.php b/app/code/Magento/Payment/Test/Unit/Model/Method/LoggerTest.php index b56caf5903208f67a51713cef223b8602387a608..36cd63d8c6db69461de3d1a11b25f942cb36e505 100644 --- a/app/code/Magento/Payment/Test/Unit/Model/Method/LoggerTest.php +++ b/app/code/Magento/Payment/Test/Unit/Model/Method/LoggerTest.php @@ -45,6 +45,20 @@ class LoggerTest extends \PHPUnit_Framework_TestCase $this->logger->debug($debugData, $debugReplaceKeys, true); } + public function testDebugOnNoReplaceKeys() + { + $debugData = + [ + 'request' => ['data1' => '123', 'data2' => '123'] + ]; + + $this->loggerMock->expects(static::once()) + ->method('debug') + ->with(var_export($debugData, true)); + + $this->logger->debug($debugData, [], true); + } + public function testDebugOff() { $debugData = diff --git a/app/code/Magento/Paypal/Block/Express/Review/Billing.php b/app/code/Magento/Paypal/Block/Express/Review/Billing.php index c613b56c40f0eb285d1b4b63d00c98daec0bb9f4..445582f9dbd6b7024d8f7c1ebaecd998c3486b9c 100644 --- a/app/code/Magento/Paypal/Block/Express/Review/Billing.php +++ b/app/code/Magento/Paypal/Block/Express/Review/Billing.php @@ -9,8 +9,222 @@ */ namespace Magento\Paypal\Block\Express\Review; -class Billing extends \Magento\Checkout\Block\Onepage\Billing +use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Quote\Model\Quote; + +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ +class Billing extends \Magento\Framework\View\Element\Template { + /** + * Sales Quote Billing Address instance + * + * @var \Magento\Quote\Model\Quote\Address + */ + protected $address; + + /** + * Customer Taxvat Widget block + * + * @var \Magento\Customer\Block\Widget\Taxvat + */ + protected $taxvat; + + /** + * @var \Magento\Quote\Model\Quote\AddressFactory + */ + protected $addressFactory; + + /** + * @var \Magento\Customer\Api\Data\CustomerInterface + */ + protected $customer; + + /** + * @var Quote + */ + protected $quote; + + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutSession; + + /** + * @var \Magento\Customer\Model\Session + */ + protected $customerSession; + + /** + * @var CustomerRepositoryInterface + */ + protected $customerRepository; + + /** + * @var \Magento\Framework\App\Http\Context + */ + protected $httpContext; + + /** + * @var \Magento\Directory\Model\ResourceModel\Country\CollectionFactory + */ + protected $countryCollectionFactory; + + /** + * @param \Magento\Framework\View\Element\Template\Context $context + * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Checkout\Model\Session $resourceSession + * @param \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory + * @param CustomerRepositoryInterface $customerRepository + * @param \Magento\Framework\App\Http\Context $httpContext + * @param Quote\AddressFactory $addressFactory + * @param array $data + */ + public function __construct( + \Magento\Framework\View\Element\Template\Context $context, + \Magento\Customer\Model\Session $customerSession, + \Magento\Checkout\Model\Session $resourceSession, + \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory, + CustomerRepositoryInterface $customerRepository, + \Magento\Framework\App\Http\Context $httpContext, + \Magento\Quote\Model\Quote\AddressFactory $addressFactory, + array $data = [] + ) { + $this->addressFactory = $addressFactory; + $this->_isScopePrivate = true; + $this->httpContext = $httpContext; + $this->customerRepository = $customerRepository; + $this->checkoutSession = $resourceSession; + $this->customerSession = $customerSession; + $this->countryCollectionFactory = $countryCollectionFactory; + parent::__construct($context, $data); + } + + /** + * Initialize billing address step + * + * @return void + */ + protected function _construct() + { + $this->getCheckout()->setStepData( + 'billing', + ['label' => __('Billing Information'), 'is_show' => true] + ); + + if ($this->isCustomerLoggedIn()) { + $this->getCheckout()->setStepData('billing', 'allow', true); + } + parent::_construct(); + } + + /** + * @return bool + */ + public function isUseBillingAddressForShipping() + { + if ($this->getQuote()->getIsVirtual() || !$this->getQuote()->getShippingAddress()->getSameAsBilling()) { + return false; + } + return true; + } + + /** + * Return country collection + * + * @return \Magento\Directory\Model\ResourceModel\Country\Collection + */ + public function getCountries() + { + return $this->countryCollectionFactory->create()->loadByStore(); + } + + /** + * Return checkout method + * + * @return string + */ + public function getMethod() + { + return $this->getQuote()->getCheckoutMethod(); + } + + /** + * Return Customer Address First Name + * If Sales Quote Address First Name is not defined - return Customer First Name + * + * @return string + */ + public function getFirstname() + { + return $this->getAddress()->getFirstname(); + } + + /** + * Return Customer Address Last Name + * If Sales Quote Address Last Name is not defined - return Customer Last Name + * + * @return string + */ + public function getLastname() + { + return $this->getAddress()->getLastname(); + } + + /** + * Check is Quote items can ship to + * + * @return bool + */ + public function canShip() + { + return !$this->getQuote()->isVirtual(); + } + + /** + * @return void + */ + public function getSaveUrl() + { + } + + /** + * Get Customer Taxvat Widget block + * + * @return \Magento\Customer\Block\Widget\Taxvat + */ + protected function _getTaxvat() + { + if (!$this->taxvat) { + $this->taxvat = $this->getLayout()->createBlock('Magento\Customer\Block\Widget\Taxvat'); + } + + return $this->taxvat; + } + + /** + * Check whether taxvat is enabled + * + * @return bool + */ + public function isTaxvatEnabled() + { + return $this->_getTaxvat()->isEnabled(); + } + + /** + * @return string + */ + public function getTaxvatHtml() + { + return $this->_getTaxvat() + ->setTaxvat($this->getQuote()->getCustomerTaxvat()) + ->setFieldIdFormat('billing:%s') + ->setFieldNameFormat('billing[%s]') + ->toHtml(); + } + /** * Return Sales Quote Address model * @@ -18,20 +232,75 @@ class Billing extends \Magento\Checkout\Block\Onepage\Billing */ public function getAddress() { - if ($this->_address === null) { + if ($this->address === null) { if ($this->isCustomerLoggedIn() || $this->getQuote()->getBillingAddress()) { - $this->_address = $this->getQuote()->getBillingAddress(); - if (!$this->_address->getFirstname()) { - $this->_address->setFirstname($this->getQuote()->getCustomer()->getFirstname()); + $this->address = $this->getQuote()->getBillingAddress(); + if (!$this->address->getFirstname()) { + $this->address->setFirstname($this->getQuote()->getCustomer()->getFirstname()); } - if (!$this->_address->getLastname()) { - $this->_address->setLastname($this->getQuote()->getCustomer()->getLastname()); + if (!$this->address->getLastname()) { + $this->address->setLastname($this->getQuote()->getCustomer()->getLastname()); } } else { - $this->_address = $this->_addressFactory->create(); + $this->address = $this->addressFactory->create(); } } - return $this->_address; + return $this->address; + } + + /** + * Get config + * + * @param string $path + * @return string|null + */ + public function getConfig($path) + { + return $this->_scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); + } + + /** + * Get logged in customer + * + * @return \Magento\Customer\Api\Data\CustomerInterface + */ + protected function _getCustomer() + { + if (empty($this->customer)) { + $this->customer = $this->customerRepository->getById($this->customerSession->getCustomerId()); + } + return $this->customer; + } + + /** + * Retrieve checkout session model + * + * @return \Magento\Checkout\Model\Session + */ + public function getCheckout() + { + return $this->checkoutSession; + } + + /** + * Retrieve sales quote model + * + * @return Quote + */ + public function getQuote() + { + if (empty($this->quote)) { + $this->quote = $this->getCheckout()->getQuote(); + } + return $this->quote; + } + + /** + * @return bool + */ + public function isCustomerLoggedIn() + { + return $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH); } } diff --git a/app/code/Magento/Paypal/Block/Express/Review/Shipping.php b/app/code/Magento/Paypal/Block/Express/Review/Shipping.php index 97fe0a20e9c3f045da8a8c29c830f5b97691a8f5..e49171238ceedc62304d95b5e2e0e7a00f6f5053 100644 --- a/app/code/Magento/Paypal/Block/Express/Review/Shipping.php +++ b/app/code/Magento/Paypal/Block/Express/Review/Shipping.php @@ -9,8 +9,115 @@ */ namespace Magento\Paypal\Block\Express\Review; -class Shipping extends \Magento\Checkout\Block\Onepage\Shipping +use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Quote\Model\Quote; + +class Shipping extends \Magento\Framework\View\Element\Template { + /** + * Sales Quote Shipping Address instance + * + * @var \Magento\Quote\Model\Quote\Address + */ + protected $address = null; + + /** + * @var \Magento\Quote\Model\Quote\AddressFactory + */ + protected $addressFactory; + + /** + * @var \Magento\Customer\Api\Data\CustomerInterface + */ + protected $customer; + + /** + * @var Quote + */ + protected $quote; + + /** + * @var \Magento\Checkout\Model\Session + */ + protected $checkoutSession; + + /** + * @var CustomerRepositoryInterface + */ + protected $customerRepository; + + /** + * @var \Magento\Framework\App\Http\Context + */ + protected $httpContext; + + /** + * @var \Magento\Customer\Model\Session + */ + protected $customerSession; + + /** + * @param \Magento\Framework\View\Element\Template\Context $context + * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Checkout\Model\Session $resourceSession + * @param CustomerRepositoryInterface $customerRepository + * @param \Magento\Framework\App\Http\Context $httpContext + * @param \Magento\Quote\Model\Quote\AddressFactory $addressFactory + * @param array $data + */ + public function __construct( + \Magento\Framework\View\Element\Template\Context $context, + \Magento\Customer\Model\Session $customerSession, + \Magento\Checkout\Model\Session $resourceSession, + CustomerRepositoryInterface $customerRepository, + \Magento\Framework\App\Http\Context $httpContext, + \Magento\Quote\Model\Quote\AddressFactory $addressFactory, + array $data = [] + ) { + $this->addressFactory = $addressFactory; + $this->_isScopePrivate = true; + $this->httpContext = $httpContext; + $this->customerRepository = $customerRepository; + $this->checkoutSession = $resourceSession; + $this->customerSession = $customerSession; + parent::__construct($context, $data); + } + + /** + * Initialize shipping address step + * + * @return void + */ + protected function _construct() + { + $this->checkoutSession->setStepData( + 'shipping', + ['label' => __('Shipping Information'), 'is_show' => $this->isShow()] + ); + + parent::_construct(); + } + + /** + * Return checkout method + * + * @return string + */ + public function getMethod() + { + return $this->getQuote()->getCheckoutMethod(); + } + + /** + * Retrieve is allow and show block + * + * @return bool + */ + public function isShow() + { + return !$this->getQuote()->isVirtual(); + } + /** * Return Sales Quote Address model (shipping address) * @@ -18,14 +125,59 @@ class Shipping extends \Magento\Checkout\Block\Onepage\Shipping */ public function getAddress() { - if ($this->_address === null) { + if ($this->address === null) { if ($this->isCustomerLoggedIn() || $this->getQuote()->getShippingAddress()) { - $this->_address = $this->getQuote()->getShippingAddress(); + $this->address = $this->getQuote()->getShippingAddress(); } else { - $this->_address = $this->_addressFactory->create(); + $this->address = $this->addressFactory->create(); } } - return $this->_address; + return $this->address; + } + + /** + * Get config + * + * @param string $path + * @return string|null + */ + public function getConfig($path) + { + return $this->_scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); + } + + /** + * Get logged in customer + * + * @return \Magento\Customer\Api\Data\CustomerInterface + */ + protected function _getCustomer() + { + if (empty($this->customer)) { + $this->customer = $this->customerRepository->getById($this->customerSession->getCustomerId()); + } + return $this->customer; + } + + /** + * Retrieve sales quote model + * + * @return Quote + */ + public function getQuote() + { + if (empty($this->quote)) { + $this->quote = $this->checkoutSession->getQuote(); + } + return $this->quote; + } + + /** + * @return bool + */ + public function isCustomerLoggedIn() + { + return $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH); } } diff --git a/app/code/Magento/Paypal/view/frontend/layout/paypal_express_review.xml b/app/code/Magento/Paypal/view/frontend/layout/paypal_express_review.xml index 60e525f463b8f15ad65139be01d9d31017061bd1..695adda9167dd09b65ff1ecc400ed0dcf6e4a951 100644 --- a/app/code/Magento/Paypal/view/frontend/layout/paypal_express_review.xml +++ b/app/code/Magento/Paypal/view/frontend/layout/paypal_express_review.xml @@ -24,7 +24,7 @@ <block class="Magento\Framework\View\Element\Text\ListText" name="paypal.additional.actions"/> <block class="Magento\Paypal\Block\Express\Review\Details" name="paypal.express.review.details" as="details" template="express/review/details.phtml"> <block class="Magento\Framework\View\Element\RendererList" name="checkout.onepage.review.item.renderers" as="renderer.list"/> - <block class="Magento\Checkout\Block\Cart\Totals" name="paypal.express.review.details.totals" as="totals" template="onepage/review/totals.phtml"/> + <block class="Magento\Checkout\Block\Cart\Totals" name="paypal.express.review.details.totals" as="totals" template="checkout/onepage/review/totals.phtml"/> </block> <block class="Magento\CheckoutAgreements\Block\Agreements" name="paypal.express.review.details.agreements" as="agreements" template="Magento_CheckoutAgreements::additional_agreements.phtml"/> </block> diff --git a/app/code/Magento/Paypal/view/frontend/layout/paypal_express_review_details.xml b/app/code/Magento/Paypal/view/frontend/layout/paypal_express_review_details.xml index 01be224c3d0f1d5c88ddce44ae8a42d1a24e8d9a..6594f0a472a8a64261dcf93a9759d7b5dc5361ca 100644 --- a/app/code/Magento/Paypal/view/frontend/layout/paypal_express_review_details.xml +++ b/app/code/Magento/Paypal/view/frontend/layout/paypal_express_review_details.xml @@ -10,7 +10,7 @@ <container name="root"> <block class="Magento\Paypal\Block\Express\Review\Details" name="page.block" template="express/review/details.phtml"> <block class="Magento\Framework\View\Element\RendererList" name="checkout.onepage.review.item.renderers" as="renderer.list"/> - <block class="Magento\Checkout\Block\Cart\Totals" name="paypal.express.review.details.totals" as="totals" template="onepage/review/totals.phtml"/> + <block class="Magento\Checkout\Block\Cart\Totals" name="paypal.express.review.details.totals" as="totals" template="checkout/onepage/review/totals.phtml"/> </block> </container> </layout> diff --git a/app/code/Magento/Paypal/view/frontend/layout/paypal_payflowexpress_review.xml b/app/code/Magento/Paypal/view/frontend/layout/paypal_payflowexpress_review.xml index e41ab21bced7420064dde9f1340cb62e6a2279c6..7fb0e07142bea9020e7d4c361b5e682de0a0c0b4 100644 --- a/app/code/Magento/Paypal/view/frontend/layout/paypal_payflowexpress_review.xml +++ b/app/code/Magento/Paypal/view/frontend/layout/paypal_payflowexpress_review.xml @@ -27,7 +27,7 @@ <block class="Magento\Framework\View\Element\Text\ListText" name="paypal.additional.actions"/> <block class="Magento\Paypal\Block\Express\Review\Details" name="paypal.express.review.details" as="details" template="express/review/details.phtml"> <block class="Magento\Framework\View\Element\RendererList" name="checkout.onepage.review.item.renderers" as="renderer.list"/> - <block class="Magento\Checkout\Block\Cart\Totals" name="paypal.express.review.details.totals" as="totals" template="onepage/review/totals.phtml"/> + <block class="Magento\Checkout\Block\Cart\Totals" name="paypal.express.review.details.totals" as="totals" template="checkout/onepage/review/totals.phtml"/> </block> <block class="Magento\CheckoutAgreements\Block\Agreements" name="paypal.express.review.details.agreements" as="agreements" template="Magento_CheckoutAgreements::additional_agreements.phtml"/> </block> diff --git a/app/code/Magento/Paypal/view/frontend/requirejs-config.js b/app/code/Magento/Paypal/view/frontend/requirejs-config.js index 49f8f54129f620c79eeee168324edeca563a4822..8e6be0da47bd15ba3550a7f04c4668a7165bbc1a 100644 --- a/app/code/Magento/Paypal/view/frontend/requirejs-config.js +++ b/app/code/Magento/Paypal/view/frontend/requirejs-config.js @@ -6,7 +6,6 @@ var config = { map: { '*': { - opcheckoutPaypalIframe: 'Magento_Paypal/js/opcheckout', orderReview: 'Magento_Paypal/order-review', paypalCheckout: 'Magento_Paypal/js/paypal-checkout' } diff --git a/app/code/Magento/Checkout/view/frontend/templates/onepage/review/totals.phtml b/app/code/Magento/Paypal/view/frontend/templates/checkout/onepage/review/totals.phtml similarity index 97% rename from app/code/Magento/Checkout/view/frontend/templates/onepage/review/totals.phtml rename to app/code/Magento/Paypal/view/frontend/templates/checkout/onepage/review/totals.phtml index ab70dbab565d4019eb9edbca45eef9ad0a9c6f4e..94aca67913e6b768bfb4200c35327d0315da7fb4 100644 --- a/app/code/Magento/Checkout/view/frontend/templates/onepage/review/totals.phtml +++ b/app/code/Magento/Paypal/view/frontend/templates/checkout/onepage/review/totals.phtml @@ -9,10 +9,6 @@ /** * @see \Magento\Checkout\Block\Cart\Totals */ - -/** - * @removeCandidate - */ ?> <?php if ($block->getTotals()): ?> <?php $_colspan = 3; ?> diff --git a/app/code/Magento/Paypal/view/frontend/templates/onepage.phtml b/app/code/Magento/Paypal/view/frontend/templates/onepage.phtml deleted file mode 100644 index 140ad1a72e4841b5cf65c1ca7d7e981ef15b7c81..0000000000000000000000000000000000000000 --- a/app/code/Magento/Paypal/view/frontend/templates/onepage.phtml +++ /dev/null @@ -1,13 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -?> -<script type="text/x-magento-init"> - { - "#checkoutSteps": { - "opcheckoutPaypalIframe": {} - } - } -</script> \ No newline at end of file diff --git a/app/code/Magento/Paypal/view/frontend/web/js/opcheckout.js b/app/code/Magento/Paypal/view/frontend/web/js/opcheckout.js deleted file mode 100644 index 416a455c511cb87b9732543fe64ed9c92bdb8d73..0000000000000000000000000000000000000000 --- a/app/code/Magento/Paypal/view/frontend/web/js/opcheckout.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -/*jshint browser:true jquery:true*/ -define([ - "jquery", - "Magento_Checkout/js/opc-order-review", - "jquery/ui" -], function($, opcOrderReview){ - "use strict"; - - $.widget('mage.opcheckoutPaypalIframe', opcOrderReview, { - options: { - review: { - submitContainer: '#checkout-review-submit' - } - }, - - _create: function() { - var events = {}; - events['contentUpdated' + this.options.review.container] = function() { - var paypalIframe = this.element.find(this.options.review.container) - .find('[data-container="paypal-iframe"]'); - if (paypalIframe.length) { - paypalIframe.show(); - $(this.options.review.submitContainer).hide(); - } - }; - this._on(events); - } - }); - - return $.mage.opcheckoutPaypalIframe; -}); \ No newline at end of file diff --git a/app/code/Magento/Translation/etc/di.xml b/app/code/Magento/Translation/etc/di.xml index 4f8ccfd64333bf850bda4fd9653131f23ddb5100..05c7f766a452e694c648138db45d7835b9721dd2 100644 --- a/app/code/Magento/Translation/etc/di.xml +++ b/app/code/Magento/Translation/etc/di.xml @@ -63,22 +63,24 @@ </argument> </arguments> </type> + <type name="Magento\Framework\View\Asset\PreProcessor\Pool"> <arguments> - <argument name="preProcessors" xsi:type="array"> + <argument name="preprocessors" xsi:type="array"> <item name="js" xsi:type="array"> - <item name="js" xsi:type="array"> - <item name="js_translation" xsi:type="string">Magento\Translation\Model\Js\PreProcessor</item> + <item name="js_translation" xsi:type="array"> + <item name="class" xsi:type="string">Magento\Translation\Model\Js\PreProcessor</item> </item> </item> <item name="json" xsi:type="array"> - <item name="json" xsi:type="array"> - <item name="json_generation" xsi:type="string">Magento\Translation\Model\Json\PreProcessor</item> + <item name="json_generation" xsi:type="array"> + <item name="class" xsi:type="string">Magento\Translation\Model\Json\PreProcessor</item> </item> </item> </argument> </arguments> </type> + <type name="Magento\Framework\Console\CommandList"> <arguments> <argument name="commands" xsi:type="array"> diff --git a/dev/tests/integration/testsuite/Magento/Checkout/Block/Onepage/Payment/MethodsTest.php b/dev/tests/integration/testsuite/Magento/Checkout/Block/Onepage/Payment/MethodsTest.php deleted file mode 100644 index 8e9cd3f440d6c2634e201e33df39a75608548b9a..0000000000000000000000000000000000000000 --- a/dev/tests/integration/testsuite/Magento/Checkout/Block/Onepage/Payment/MethodsTest.php +++ /dev/null @@ -1,52 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -/** - * Test class for \Magento\Checkout\Block\Onepage\Payment\Methods - */ -namespace Magento\Checkout\Block\Onepage\Payment; - -class MethodsTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var \Magento\Checkout\Block\Onepage\Payment\Methods - */ - protected $_block; - - protected function setUp() - { - parent::setUp(); - $this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - 'Magento\Framework\View\LayoutInterface' - )->createBlock( - 'Magento\Checkout\Block\Onepage\Payment\Methods' - ); - } - - /** - * @magentoAppArea frontend - */ - public function testGetMethodTitleAndMethodLabelAfterHtml() - { - $expectedTitle = 'Free Method'; - $expectedLabel = 'Label After Html'; - $method = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - 'Magento\Payment\Model\Method\Free' - ); - - $block = $this->_block->getLayout()->createBlock('Magento\Framework\View\Element\Text') - ->setMethodTitle($expectedTitle) - ->setMethodLabelAfterHtml($expectedLabel); - - $this->assertEquals('No Payment Information Required', $this->_block->getMethodTitle($method)); - $this->_block->setChild('payment.method.free', $block); - $actualTitle = $this->_block->getMethodTitle($method); - $actualLabel = $this->_block->getMethodLabelAfterHtml($method); - - $this->assertEquals($expectedTitle, $actualTitle); - $this->assertEquals($expectedLabel, $actualLabel); - } -} diff --git a/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php b/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php index fbc90ac30f4c6da05143fd0391520237c2aaf580..ed282c1793d1c2d7836bee5daab7d28d371fe8c3 100644 --- a/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php +++ b/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php @@ -19,7 +19,7 @@ class FilterTest extends \PHPUnit_Framework_TestCase /** * @var \Magento\Email\Model\Template\Filter */ - protected $model = null; + protected $model; /** * @var \Magento\TestFramework\ObjectManager @@ -270,7 +270,7 @@ class FilterTest extends \PHPUnit_Framework_TestCase 'File with compilation error results in error message' => [ TemplateTypesInterface::TYPE_HTML, 'file="css/file-with-error.css"', - \Magento\Framework\Css\PreProcessor\AdapterInterface::ERROR_MESSAGE_PREFIX, + \Magento\Framework\View\Asset\ContentProcessorInterface::ERROR_MESSAGE_PREFIX, ], ]; } @@ -356,7 +356,7 @@ class FilterTest extends \PHPUnit_Framework_TestCase ], 'Developer mode - File with compilation error results in error message' => [ '<html><p></p> {{inlinecss file="css/file-with-error.css"}}</html>', - \Magento\Framework\Css\PreProcessor\AdapterInterface::ERROR_MESSAGE_PREFIX, + \Magento\Framework\View\Asset\ContentProcessorInterface::ERROR_MESSAGE_PREFIX, false, ], ]; diff --git a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/OyejorgeTest.php b/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/OyejorgeTest.php deleted file mode 100644 index 399f0b7a44bfda7cde4a3623a6042edc372d3c71..0000000000000000000000000000000000000000 --- a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/OyejorgeTest.php +++ /dev/null @@ -1,62 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Css\PreProcessor\Adapter\Less; - -use Magento\Framework\App\State; - -/** - * Oyejorge adapter model - */ -class OyejorgeTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var Oyejorge - */ - protected $model; - - /** - * @var \Magento\Framework\App\State - */ - protected $state; - - public function setUp() - { - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - $this->model = $objectManager->create('Magento\Framework\Css\PreProcessor\Adapter\Less\Oyejorge'); - $this->state = $objectManager->get('Magento\Framework\App\State'); - } - - public function testProcess() - { - $sourceFilePath = realpath(__DIR__ . '/_files/oyejorge.less'); - $expectedCss = ($this->state->getMode() === State::MODE_DEVELOPER) - ? file_get_contents(__DIR__ . '/_files/oyejorge_dev.css') - : file_get_contents(__DIR__ . '/_files/oyejorge.css'); - $actualCss = ($this->model->process($sourceFilePath)); - - $this->assertEquals($this->cutCopyrights($expectedCss), $actualCss); - } - - /** - * Cuts copyrights from css source - * - * @param string $cssSource - * @return string - */ - private function cutCopyrights($cssSource) - { - $copyright = <<<'TAG' -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - - -TAG; - return (string)str_replace($copyright, '', $cssSource); - - } -} diff --git a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/cache/lib/nested/import.less b/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/cache/lib/nested/import.less deleted file mode 100644 index 0b6a8af1a5130a6d19a8d976dff524408c5b15bf..0000000000000000000000000000000000000000 --- a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/cache/lib/nested/import.less +++ /dev/null @@ -1,6 +0,0 @@ -// /** -// * Copyright © 2015 Magento. All rights reserved. -// * See COPYING.txt for license details. -// */ - -h1 { background-color: red; } diff --git a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/cache/lib/oyejorge.less b/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/cache/lib/oyejorge.less deleted file mode 100644 index c71bb050df796ac1f963b2bd62a024c020f8c0c8..0000000000000000000000000000000000000000 --- a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/cache/lib/oyejorge.less +++ /dev/null @@ -1,6 +0,0 @@ -// /** -// * Copyright © 2015 Magento. All rights reserved. -// * See COPYING.txt for license details. -// */ - -@import "nested/import.less"; diff --git a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/nested/import.less b/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/nested/import.less deleted file mode 100644 index 2e284b2e8eb87a22b92b769e67086265962d3822..0000000000000000000000000000000000000000 --- a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/nested/import.less +++ /dev/null @@ -1,6 +0,0 @@ -// /** -// * Copyright © 2015 Magento. All rights reserved. -// * See COPYING.txt for license details. -// */ - -@body-bg-img: url(Magento_Theme::validation_advice_bg.gif); diff --git a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/oyejorge.css b/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/oyejorge.css deleted file mode 100644 index bcf1aa406b5edaa5723cf3584be8e8896fb7cbf8..0000000000000000000000000000000000000000 --- a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/oyejorge.css +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -#header{color: #4d926f}h2{color: #4d926f}#header{-webkit-border-radius: 5px;-moz-border-radius: 5px;-ms-border-radius: 5px;-o-border-radius: 5px;border-radius: 5px}#footer{-webkit-border-radius: 10px;-moz-border-radius: 10px;-ms-border-radius: 10px;-o-border-radius: 10px;border-radius: 10px}#header h1{font-size: 26px;font-weight: bold}#header p{font-size: 12px}#header p a{text-decoration: none}#header p a:hover{border-width: 1px}#header{color: #333;border-left: 1px;border-right: 2px}#footer{color: #141;border-color: #7d2717}body{background-image: url(Magento_Theme::validation_advice_bg.gif)} \ No newline at end of file diff --git a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/oyejorge.less b/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/oyejorge.less deleted file mode 100644 index 58914770c2f5de25e75cfd0fc38524fd61d31959..0000000000000000000000000000000000000000 --- a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/oyejorge.less +++ /dev/null @@ -1,74 +0,0 @@ -// /** -// * Copyright © 2015 Magento. All rights reserved. -// * See COPYING.txt for license details. -// */ - -// Variables - -@color: #4D926F; - -#header { - color: @color; -} - -h2 { - color: @color; -} - -// Mixins - -.rounded-corners (@radius: 5px) { - -webkit-border-radius: @radius; - -moz-border-radius: @radius; - -ms-border-radius: @radius; - -o-border-radius: @radius; - border-radius: @radius; -} - -#header { - .rounded-corners; -} - -#footer { - .rounded-corners(10px); -} - -// Nested Rules - -#header { - h1 { - font-size: 26px; - font-weight: bold; - } - p { font-size: 12px; - a { - text-decoration: none; - &:hover { - border-width: 1px; - } - } - } -} - -// Functions & Operations - -@the-border: 1px; -@base-color: #111; -@red: #842210; - -#header { - color: (@base-color * 3); - border-left: @the-border; - border-right: (@the-border * 2); -} - -#footer { - color: (@base-color + #003300); - border-color: desaturate(@red, 10%); -} - -@import "nested/import.less"; - -body { - background-image: @body-bg-img; -} diff --git a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/oyejorge_dev.css b/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/oyejorge_dev.css deleted file mode 100644 index 0e70c6da760dbc6c5b39775e940f619daa8910db..0000000000000000000000000000000000000000 --- a/dev/tests/integration/testsuite/Magento/Framework/Css/PreProcessor/Adapter/Less/_files/oyejorge_dev.css +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -#header { - color: #4d926f; -} -h2 { - color: #4d926f; -} -#header { - -webkit-border-radius: 5px; - -moz-border-radius: 5px; - -ms-border-radius: 5px; - -o-border-radius: 5px; - border-radius: 5px; -} -#footer { - -webkit-border-radius: 10px; - -moz-border-radius: 10px; - -ms-border-radius: 10px; - -o-border-radius: 10px; - border-radius: 10px; -} -#header h1 { - font-size: 26px; - font-weight: bold; -} -#header p { - font-size: 12px; -} -#header p a { - text-decoration: none; -} -#header p a:hover { - border-width: 1px; -} -#header { - color: #333333; - border-left: 1px; - border-right: 2px; -} -#footer { - color: #114411; - border-color: #7d2717; -} -body { - background-image: url(Magento_Theme::validation_advice_bg.gif); -} diff --git a/dev/tests/integration/testsuite/Magento/Checkout/Block/Onepage/BillingTest.php b/dev/tests/integration/testsuite/Magento/Paypal/Block/Express/Review/BillingTest.php similarity index 84% rename from dev/tests/integration/testsuite/Magento/Checkout/Block/Onepage/BillingTest.php rename to dev/tests/integration/testsuite/Magento/Paypal/Block/Express/Review/BillingTest.php index 86ac63afe57145019c36e4f111e5e398d0c12260..c256479cc7c833efa628eb58bc084554b87d2ce3 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/Block/Onepage/BillingTest.php +++ b/dev/tests/integration/testsuite/Magento/Paypal/Block/Express/Review/BillingTest.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Checkout\Block\Onepage; +namespace Magento\Paypal\Block\Express\Review; use Magento\Customer\Model\Context; use Magento\TestFramework\Helper\Bootstrap; @@ -13,7 +13,7 @@ use Magento\TestFramework\Helper\Bootstrap; */ class BillingTest extends \PHPUnit_Framework_TestCase { - /** @var \Magento\Checkout\Block\Onepage\Billing */ + /** @var \Magento\Paypal\Block\Express\Review\Billing */ protected $_block; /** @var \Magento\Customer\Api\AddressRepositoryInterface */ @@ -67,9 +67,9 @@ class BillingTest extends \PHPUnit_Framework_TestCase ->setValue(Context::CONTEXT_AUTH, true, false); $this->_block = $objectManager->get('Magento\Framework\View\LayoutInterface') ->createBlock( - 'Magento\Checkout\Block\Onepage\Billing', + 'Magento\Paypal\Block\Express\Review\Billing', '', - ['customerSession' => $customerSession, 'checkoutSession' => $checkoutSession] + ['customerSession' => $customerSession, 'resourceSession' => $checkoutSession] ); } @@ -136,19 +136,4 @@ class BillingTest extends \PHPUnit_Framework_TestCase $this->assertEquals(self::SAMPLE_FIRST_NAME, $this->_block->getFirstname()); $this->assertEquals(self::SAMPLE_LAST_NAME, $this->_block->getLastname()); } - - /** - * @magentoDataFixture Magento/Customer/_files/customer.php - * @magentoDataFixture Magento/Customer/_files/customer_address.php - */ - public function testGetAddressesHtmlSelect() - { - Bootstrap::getObjectManager()->get('Magento\Customer\Model\Session')->setCustomerId(1); - // @codingStandardsIgnoreStart - $expected = <<<OUTPUT -<select name="billing_address_id" id="billing:address-select" class="address-select" title="" ><option value="1" selected="selected" >John Smith, Green str, 67, CityM, Alabama 75477, United States</option><option value="" >New Address</option></select> -OUTPUT; - // @codingStandardsIgnoreEnd - $this->assertEquals($expected, $this->_block->getAddressesHtmlSelect('billing')); - } } diff --git a/dev/tests/static/testsuite/Magento/Test/Js/_files/blacklist/magento.txt b/dev/tests/static/testsuite/Magento/Test/Js/_files/blacklist/magento.txt index 70168b63a4efb5f06f978a00c9896b0c1a6d5f12..7497804d68237b137475036e394951135630508e 100644 --- a/dev/tests/static/testsuite/Magento/Test/Js/_files/blacklist/magento.txt +++ b/dev/tests/static/testsuite/Magento/Test/Js/_files/blacklist/magento.txt @@ -105,15 +105,6 @@ app/code/Magento/Checkout/view/frontend/web/js/model/sidebar.js app/code/Magento/Checkout/view/frontend/web/js/model/step-navigator.js app/code/Magento/Checkout/view/frontend/web/js/model/totals.js app/code/Magento/Checkout/view/frontend/web/js/model/url-builder.js -app/code/Magento/Checkout/view/frontend/web/js/opc-billing-info.js -app/code/Magento/Checkout/view/frontend/web/js/opc-checkout-method.js -app/code/Magento/Checkout/view/frontend/web/js/opc-order-review.js -app/code/Magento/Checkout/view/frontend/web/js/opc-payment-info.js -app/code/Magento/Checkout/view/frontend/web/js/opc-shipping-info.js -app/code/Magento/Checkout/view/frontend/web/js/opc-shipping-method.js -app/code/Magento/Checkout/view/frontend/web/js/opcheckout.js -app/code/Magento/Checkout/view/frontend/web/js/payment-authentication.js -app/code/Magento/Checkout/view/frontend/web/js/payment.js app/code/Magento/Checkout/view/frontend/web/js/proceed-to-checkout.js app/code/Magento/Checkout/view/frontend/web/js/region-updater.js app/code/Magento/Checkout/view/frontend/web/js/shopping-cart.js @@ -219,6 +210,7 @@ app/code/Magento/Msrp/view/frontend/requirejs-config.js app/code/Magento/Multishipping/view/frontend/requirejs-config.js app/code/Magento/Multishipping/view/frontend/web/js/multi-shipping.js app/code/Magento/Multishipping/view/frontend/web/js/overview.js +app/code/Magento/Multishipping/view/frontend/web/js/payment.js app/code/Magento/OfflinePayments/view/frontend/web/js/view/payment/method-renderer/banktransfer-method.js app/code/Magento/OfflinePayments/view/frontend/web/js/view/payment/method-renderer/cashondelivery-method.js app/code/Magento/OfflinePayments/view/frontend/web/js/view/payment/method-renderer/checkmo-method.js @@ -688,15 +680,6 @@ vendor/magento/module-checkout/view/frontend/web/js/model/step-loader.js vendor/magento/module-checkout/view/frontend/web/js/model/step-navigator.js vendor/magento/module-checkout/view/frontend/web/js/model/totals.js vendor/magento/module-checkout/view/frontend/web/js/model/url-builder.js -vendor/magento/module-checkout/view/frontend/web/js/opc-billing-info.js -vendor/magento/module-checkout/view/frontend/web/js/opc-checkout-method.js -vendor/magento/module-checkout/view/frontend/web/js/opc-order-review.js -vendor/magento/module-checkout/view/frontend/web/js/opc-payment-info.js -vendor/magento/module-checkout/view/frontend/web/js/opc-shipping-info.js -vendor/magento/module-checkout/view/frontend/web/js/opc-shipping-method.js -vendor/magento/module-checkout/view/frontend/web/js/opcheckout.js -vendor/magento/module-checkout/view/frontend/web/js/payment-authentication.js -vendor/magento/module-checkout/view/frontend/web/js/payment.js vendor/magento/module-checkout/view/frontend/web/js/proceed-to-checkout.js vendor/magento/module-checkout/view/frontend/web/js/region-updater.js vendor/magento/module-checkout/view/frontend/web/js/shopping-cart.js diff --git a/dev/tests/static/testsuite/Magento/Test/Js/_files/jshint/blacklist/core.txt b/dev/tests/static/testsuite/Magento/Test/Js/_files/jshint/blacklist/core.txt index 9699f47c4bcccc9dd1009437092117fae86c0f25..2cb2aca38f906e767c139a830976538f18f337cc 100644 --- a/dev/tests/static/testsuite/Magento/Test/Js/_files/jshint/blacklist/core.txt +++ b/dev/tests/static/testsuite/Magento/Test/Js/_files/jshint/blacklist/core.txt @@ -4,7 +4,6 @@ module Magento_Catalog view/adminhtml/web/catalog/category/edit.js module Magento_Catalog view/adminhtml/web/catalog/product.js module Magento_Catalog view/adminhtml/web/catalog/product/composite/configure.js module Magento_Checkout view/frontend/web/js/opcheckout.js -module Magento_Checkout view/frontend/web/js/payment.js module Magento_Rule view/adminhtml/web/rules.js module Magento_Sales view/adminhtml/web/order/create/giftmessage.js module Magento_Sales view/adminhtml/web/order/create/scripts.js diff --git a/lib/internal/Magento/Framework/Css/PreProcessor/Adapter/Less/Oyejorge.php b/lib/internal/Magento/Framework/Css/PreProcessor/Adapter/Less/Oyejorge.php deleted file mode 100644 index eed8d0555341be43c29d3fe7f05452b08ebd7783..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Css/PreProcessor/Adapter/Less/Oyejorge.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Css\PreProcessor\Adapter\Less; - -use Magento\Framework\App\State; - -/** - * Oyejorge adapter model - */ -class Oyejorge implements \Magento\Framework\Css\PreProcessor\AdapterInterface -{ - /** - * @var \Psr\Log\LoggerInterface - */ - protected $logger; - - /** - * @var \Magento\Framework\App\State - */ - protected $appState; - - /** - * @param \Psr\Log\LoggerInterface $logger - * @param State $appState - */ - public function __construct( - \Psr\Log\LoggerInterface $logger, - State $appState - ) { - $this->logger = $logger; - $this->appState = $appState; - } - - /** - * @param string $sourceFilePath - * @return string - */ - public function process($sourceFilePath) - { - $options = ['relativeUrls' => false, 'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER]; - try { - $parser = new \Less_Parser($options); - $parser->parseFile($sourceFilePath, ''); - return $parser->getCss(); - } catch (\Exception $e) { - $errorMessage = self::ERROR_MESSAGE_PREFIX . $e->getMessage(); - $this->logger->critical($errorMessage); - return $errorMessage; - } - } -} diff --git a/lib/internal/Magento/Framework/Css/PreProcessor/Adapter/Less/Processor.php b/lib/internal/Magento/Framework/Css/PreProcessor/Adapter/Less/Processor.php new file mode 100644 index 0000000000000000000000000000000000000000..26cb1ce21d66a979dc2c97ba5db99db8d8d4890d --- /dev/null +++ b/lib/internal/Magento/Framework/Css/PreProcessor/Adapter/Less/Processor.php @@ -0,0 +1,92 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\Css\PreProcessor\Adapter\Less; + +use Psr\Log\LoggerInterface; +use Magento\Framework\App\State; +use Magento\Framework\View\Asset\File; +use Magento\Framework\View\Asset\Source; +use Magento\Framework\Css\PreProcessor\File\Temporary; +use Magento\Framework\View\Asset\ContentProcessorInterface; + +/** + * Class Processor + */ +class Processor implements ContentProcessorInterface +{ + /** + * @var LoggerInterface + */ + private $logger; + + /** + * @var State + */ + private $appState; + + /** + * @var Source + */ + private $assetSource; + + /** + * @var Temporary + */ + private $temporaryFile; + + /** + * Constructor + * + * @param LoggerInterface $logger + * @param State $appState + * @param Source $assetSource + * @param Temporary $temporaryFile + */ + public function __construct( + LoggerInterface $logger, + State $appState, + Source $assetSource, + Temporary $temporaryFile + ) { + $this->logger = $logger; + $this->appState = $appState; + $this->assetSource = $assetSource; + $this->temporaryFile = $temporaryFile; + } + + /** + * @inheritdoc + */ + public function processContent(File $asset) + { + try { + $parser = new \Less_Parser( + [ + 'relativeUrls' => false, + 'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER + ] + ); + + $content = $this->assetSource->getContent($asset); + + if (trim($content) === '') { + return ''; + } + + $tmpFilePath = $this->temporaryFile->createFile($asset->getPath(), $content); + $parser->parseFile($tmpFilePath, ''); + + $content = $parser->getCss(); + + return $content; + } catch (\Exception $e) { + $errorMessage = self::ERROR_MESSAGE_PREFIX . $e->getMessage(); + $this->logger->critical($errorMessage); + + return $errorMessage; + } + } +} diff --git a/lib/internal/Magento/Framework/Css/PreProcessor/AdapterInterface.php b/lib/internal/Magento/Framework/Css/PreProcessor/AdapterInterface.php deleted file mode 100644 index b2b230bc30233add74cc614f0f820a70cd352dc4..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Css/PreProcessor/AdapterInterface.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Css\PreProcessor; - -/** - * Css pre-processor adapter interface - */ -interface AdapterInterface -{ - const ERROR_MESSAGE_PREFIX = 'CSS compilation from source '; - - /** - * @param string $sourceFilePath - * @return string - */ - public function process($sourceFilePath); -} diff --git a/lib/internal/Magento/Framework/Css/PreProcessor/FileGenerator.php b/lib/internal/Magento/Framework/Css/PreProcessor/FileGenerator.php deleted file mode 100644 index ff69af61e354c142422430e601222fbacdfc8173..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Css/PreProcessor/FileGenerator.php +++ /dev/null @@ -1,149 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\Framework\Css\PreProcessor; - -use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\View\Asset\PreProcessor\Chain; -use Magento\Framework\View\Asset\SourceFileGeneratorInterface; - -/** - * Class FileGenerator - * @package Magento\Framework\Css - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) - */ -class FileGenerator implements SourceFileGeneratorInterface -{ - /** - * Max execution (locking) time for generation process (in seconds) - */ - const MAX_LOCK_TIME = 300; - - /** - * Lock file, if exists shows that process is locked - */ - const LOCK_FILE = 'css.lock'; - - /** - * @var \Magento\Framework\Filesystem\Directory\WriteInterface - */ - protected $tmpDirectory; - - /** - * @var \Magento\Framework\View\Asset\Repository - */ - private $assetRepo; - - /** - * @var \Magento\Framework\View\Asset\Source - */ - private $assetSource; - - /** - * @var \Magento\Framework\Css\PreProcessor\Instruction\MagentoImport - */ - private $magentoImportProcessor; - - /** - * @var \Magento\Framework\Css\PreProcessor\Instruction\Import - */ - private $importProcessor; - - /** - * @var FileGenerator\RelatedGenerator - */ - private $relatedGenerator; - - /** - * @var Config - */ - private $config; - - /** - * @var File\Temporary - */ - private $temporaryFile; - - /** - * @param \Magento\Framework\Filesystem $filesystem - * @param \Magento\Framework\View\Asset\Repository $assetRepo - * @param \Magento\Framework\Css\PreProcessor\Instruction\MagentoImport $magentoImportProcessor - * @param \Magento\Framework\Css\PreProcessor\Instruction\Import $importProcessor - * @param \Magento\Framework\View\Asset\Source $assetSource - * @param FileGenerator\RelatedGenerator $relatedGenerator - * @param Config $config - * @param File\Temporary $temporaryFile - */ - public function __construct( - \Magento\Framework\Filesystem $filesystem, - \Magento\Framework\View\Asset\Repository $assetRepo, - \Magento\Framework\Css\PreProcessor\Instruction\MagentoImport $magentoImportProcessor, - \Magento\Framework\Css\PreProcessor\Instruction\Import $importProcessor, - \Magento\Framework\View\Asset\Source $assetSource, - \Magento\Framework\Css\PreProcessor\FileGenerator\RelatedGenerator $relatedGenerator, - Config $config, - File\Temporary $temporaryFile - ) { - $this->tmpDirectory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); - $this->assetRepo = $assetRepo; - $this->assetSource = $assetSource; - - $this->magentoImportProcessor = $magentoImportProcessor; - $this->importProcessor = $importProcessor; - $this->relatedGenerator = $relatedGenerator; - $this->config = $config; - $this->temporaryFile = $temporaryFile; - } - - /** - * Create a tree of self-sustainable files and return the topmost source file, - * ready for passing to 3rd party library - * - * @param Chain $chain - * @return string Absolute path of generated topmost source file - */ - public function generateFileTree(Chain $chain) - { - /** - * wait if generation process has already started - */ - while ($this->isProcessLocked()) { - sleep(1); - } - $lockFilePath = $this->config->getMaterializationRelativePath() . '/' . self::LOCK_FILE; - $this->tmpDirectory->writeFile($lockFilePath, time()); - - $this->magentoImportProcessor->process($chain); - $this->importProcessor->process($chain); - $this->relatedGenerator->generate($this->importProcessor); - - $contentType = $chain->getContentType(); - $relativePath = preg_replace('#\.css$#', '.' . $contentType, $chain->getAsset()->getPath()); - $tmpFilePath = $this->temporaryFile->createFile($relativePath, $chain->getContent()); - - $this->tmpDirectory->delete($lockFilePath); - return $tmpFilePath; - } - - /** - * Check whether generation process has already locked - * - * @return bool - */ - protected function isProcessLocked() - { - $lockFilePath = $this->config->getMaterializationRelativePath() . '/' . self::LOCK_FILE; - if ($this->tmpDirectory->isExist($lockFilePath)) { - $lockTime = time() - (int)$this->tmpDirectory->readFile($lockFilePath); - if ($lockTime >= self::MAX_LOCK_TIME) { - $this->tmpDirectory->delete($lockFilePath); - return false; - } - return true; - } - return false; - } -} diff --git a/lib/internal/Magento/Framework/Css/PreProcessor/Instruction/Import.php b/lib/internal/Magento/Framework/Css/PreProcessor/Instruction/Import.php index 158d022f78a0ef33c07eff29d164294ab2db9c3f..2559c32270373ee30d03ab3a518a632ed27ace52 100644 --- a/lib/internal/Magento/Framework/Css/PreProcessor/Instruction/Import.php +++ b/lib/internal/Magento/Framework/Css/PreProcessor/Instruction/Import.php @@ -11,6 +11,7 @@ namespace Magento\Framework\Css\PreProcessor\Instruction; use Magento\Framework\View\Asset\LocalInterface; use Magento\Framework\View\Asset\NotationResolver; use Magento\Framework\View\Asset\PreProcessorInterface; +use Magento\Framework\Css\PreProcessor\FileGenerator\RelatedGenerator; /** * @import instruction preprocessor @@ -34,11 +35,22 @@ class Import implements PreProcessorInterface protected $relatedFiles = []; /** + * @var RelatedGenerator + */ + private $relatedFileGenerator; + + /** + * Constructor + * * @param NotationResolver\Module $notationResolver + * @param RelatedGenerator $relatedFileGenerator */ - public function __construct(NotationResolver\Module $notationResolver) - { + public function __construct( + NotationResolver\Module $notationResolver, + RelatedGenerator $relatedFileGenerator + ) { $this->notationResolver = $notationResolver; + $this->relatedFileGenerator = $relatedFileGenerator; } /** @@ -54,6 +66,7 @@ class Import implements PreProcessorInterface $content = $this->removeComments($chain->getContent()); $processedContent = preg_replace_callback(self::REPLACE_PATTERN, $replaceCallback, $content); + $this->relatedFileGenerator->generate($this); if ($processedContent !== $content) { $chain->setContent($processedContent); diff --git a/lib/internal/Magento/Framework/Css/PreProcessor/Less.php b/lib/internal/Magento/Framework/Css/PreProcessor/Less.php deleted file mode 100644 index 4bdbbcf31a58e7093b87becf7c5dc9ab0d7cd1c6..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Css/PreProcessor/Less.php +++ /dev/null @@ -1,49 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\Framework\Css\PreProcessor; - -use Magento\Framework\View\Asset\PreProcessorInterface; - -class Less implements PreProcessorInterface -{ - /** - * @var \Magento\Framework\Css\PreProcessor\FileGenerator - */ - protected $fileGenerator; - - /** - * @var AdapterInterface - */ - protected $adapter; - - /** - * @param \Magento\Framework\Css\PreProcessor\FileGenerator $fileGenerator - * @param AdapterInterface $adapter - */ - public function __construct( - \Magento\Framework\Css\PreProcessor\FileGenerator $fileGenerator, - AdapterInterface $adapter - ) { - $this->fileGenerator = $fileGenerator; - $this->adapter = $adapter; - } - - /** - * {@inheritdoc} - */ - public function process(\Magento\Framework\View\Asset\PreProcessor\Chain $chain) - { - $chain->setContentType('less'); - $tmpFile = $this->fileGenerator->generateFileTree($chain); - $cssContent = $this->adapter->process($tmpFile); - $cssTrimmedContent = trim($cssContent); - if (!empty($cssTrimmedContent)) { - $chain->setContent($cssContent); - } - $chain->setContentType('css'); - } -} diff --git a/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/FileGeneratorTest.php b/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/FileGeneratorTest.php deleted file mode 100644 index 4f034c16360776c8e5d7344943725bfba4b4a190..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/FileGeneratorTest.php +++ /dev/null @@ -1,177 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\Framework\Css\Test\Unit\PreProcessor; - -class FileGeneratorTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var \Magento\Framework\Css\PreProcessor\Instruction\Import|\PHPUnit_Framework_MockObject_MockObject - */ - private $import; - - /** - * @var \Magento\Framework\Css\PreProcessor\Instruction\MagentoImport|\PHPUnit_Framework_MockObject_MockObject - */ - private $magentoImport; - - /** - * @var \Magento\Framework\Filesystem\Directory\WriteInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $tmpDirectory; - - /** - * @var \Magento\Framework\Filesystem\Directory\ReadInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $rootDirectory; - - /** - * @var \Magento\Framework\View\Asset\Repository|\PHPUnit_Framework_MockObject_MockObject - */ - private $assetRepo; - - /** - * @var \Magento\Framework\Css\PreProcessor\FileGenerator - */ - private $object; - - /** - * @var \Magento\Framework\Css\PreProcessor\FileGenerator\RelatedGenerator|\PHPUnit_Framework_MockObject_MockObject - */ - private $relatedGenerator; - - /** - * @var \Magento\Framework\Css\PreProcessor\Config|\PHPUnit_Framework_MockObject_MockObject - */ - private $config; - - /** - * @var \Magento\Framework\Css\PreProcessor\File\Temporary|\PHPUnit_Framework_MockObject_MockObject - */ - private $temporaryFile; - - protected function setUp() - { - $this->tmpDirectory = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); - $this->rootDirectory = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\ReadInterface'); - $this->rootDirectory->expects($this->any()) - ->method('getRelativePath') - ->will($this->returnArgument(0)); - $this->rootDirectory->expects($this->any()) - ->method('readFile') - ->will( - $this->returnCallback( - function ($file) { - return "content of '$file'"; - } - ) - ); - $filesystem = $this->getMock('\Magento\Framework\Filesystem', [], [], '', false); - $filesystem->expects($this->once()) - ->method('getDirectoryWrite') - ->will($this->returnValue($this->tmpDirectory)); - $this->assetRepo = $this->getMock('\Magento\Framework\View\Asset\Repository', [], [], '', false); - $this->magentoImport = $this->getMock( - 'Magento\Framework\Css\PreProcessor\Instruction\MagentoImport', - [], - [], - '', - false - ); - $this->import = $this->getMock( - 'Magento\Framework\Css\PreProcessor\Instruction\Import', - [], - [], - '', - false - ); - - $assetSource = $this->getMock( - 'Magento\Framework\View\Asset\Source', - [], - [], - '', - false - ); - - $this->relatedGenerator = $this->getMockBuilder( - 'Magento\Framework\Css\PreProcessor\FileGenerator\RelatedGenerator' - ) - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $this->config = $this->getMockBuilder('Magento\Framework\Css\PreProcessor\Config') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $this->temporaryFile = $this->getMockBuilder('Magento\Framework\Css\PreProcessor\File\Temporary') - ->disableOriginalConstructor() - ->setMethods([]) - ->getMock(); - $this->object = new \Magento\Framework\Css\PreProcessor\FileGenerator( - $filesystem, - $this->assetRepo, - $this->magentoImport, - $this->import, - $assetSource, - $this->relatedGenerator, - $this->config, - $this->temporaryFile - ); - } - - public function testGenerateFileTree() - { - $lessDirectory = 'path/to/less'; - $expectedContent = 'updated content'; - $expectedRelativePath = 'some/file.less'; - $expectedPath = $lessDirectory . '/some/file.less'; - - - $asset = $this->getMock('Magento\Framework\View\Asset\File', [], [], '', false); - $chain = $this->getMock('Magento\Framework\View\Asset\PreProcessor\Chain', [], [], '', false); - - $this->config->expects($this->any()) - ->method('getLessDirectory') - ->willReturn($lessDirectory); - $this->tmpDirectory->expects($this->once()) - ->method('isExist') - ->willReturn(true); - - $this->magentoImport->expects($this->once()) - ->method('process') - ->with($chain); - $this->import->expects($this->once()) - ->method('process') - ->with($chain); - $this->relatedGenerator->expects($this->once()) - ->method('generate') - ->with($this->import); - - $asset->expects($this->once()) - ->method('getPath') - ->will($this->returnValue('some/file.css')); - $chain->expects($this->once()) - ->method('getContent') - ->willReturn($expectedContent); - $chain->expects($this->once()) - ->method('getAsset') - ->willReturn($asset); - $chain->expects($this->once()) - ->method('getContentType') - ->willReturn('less'); - - $this->temporaryFile->expects($this->once()) - ->method('createFile') - ->with( - $expectedRelativePath, - $expectedContent - ) - ->willReturn($expectedPath); - - $this->assertSame($expectedPath, $this->object->generateFileTree($chain)); - } -} diff --git a/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/Instruction/ImportTest.php b/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/Instruction/ImportTest.php index 6be802eaf35dc19ab8238a39fa0856ae4f1eb6c6..b5959faaf5d9e016847f7f2c3c6f729941cd6fc8 100644 --- a/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/Instruction/ImportTest.php +++ b/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/Instruction/ImportTest.php @@ -8,6 +8,12 @@ namespace Magento\Framework\Css\Test\Unit\PreProcessor\Instruction; +use Magento\Framework\Css\PreProcessor\FileGenerator\RelatedGenerator; +use Magento\Framework\Css\PreProcessor\Instruction\Import; + +/** + * Class ImportTest + */ class ImportTest extends \PHPUnit_Framework_TestCase { /** @@ -21,18 +27,29 @@ class ImportTest extends \PHPUnit_Framework_TestCase private $asset; /** - * @var \Magento\Framework\Css\PreProcessor\Instruction\Import + * @var Import */ private $object; + /** + * @var RelatedGenerator + */ + private $relatedFileGeneratorMock; + protected function setUp() { + $this->notationResolver = $this->getMock( '\Magento\Framework\View\Asset\NotationResolver\Module', [], [], '', false ); $this->asset = $this->getMock('\Magento\Framework\View\Asset\File', [], [], '', false); $this->asset->expects($this->any())->method('getContentType')->will($this->returnValue('css')); - $this->object = new \Magento\Framework\Css\PreProcessor\Instruction\Import($this->notationResolver); + + $this->relatedFileGeneratorMock = $this->getMockBuilder(RelatedGenerator::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->object = new Import($this->notationResolver, $this->relatedFileGeneratorMock); } /** diff --git a/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/LessTest.php b/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/LessTest.php deleted file mode 100644 index 4b13f6d09411d4dd948f39e14d5449d374e19b58..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Css/Test/Unit/PreProcessor/LessTest.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Css\Test\Unit\PreProcessor; - -use Magento\Framework\View\Asset\PreProcessor\Chain; - -class LessTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var \Magento\Framework\Css\PreProcessor\FileGenerator|\PHPUnit_Framework_MockObject_MockObject - */ - private $fileGenerator; - - /** - * @var \Magento\Framework\Css\PreProcessor\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $adapter; - - /** - * @var Chain - */ - private $chain; - - /** - * @var \Magento\Framework\Css\PreProcessor\Less - */ - private $object; - - protected function setUp() - { - $this->fileGenerator = $this->getMock('\Magento\Framework\Css\PreProcessor\FileGenerator', [], [], '', false); - $this->adapter = $this->getMockForAbstractClass('\Magento\Framework\Css\PreProcessor\AdapterInterface'); - $asset = $this->getMockForAbstractClass('\Magento\Framework\View\Asset\LocalInterface'); - $asset->expects($this->once())->method('getContentType')->will($this->returnValue('origType')); - $this->chain = new Chain($asset, 'original content', 'origType', 'origPath'); - $this->object = new \Magento\Framework\Css\PreProcessor\Less($this->fileGenerator, $this->adapter); - } - - public function testProcess() - { - $expectedContent = 'updated content'; - $tmpFile = 'tmp/file.ext'; - $this->fileGenerator->expects($this->once()) - ->method('generateFileTree') - ->with($this->chain) - ->will($this->returnValue($tmpFile)); - $this->adapter->expects($this->once()) - ->method('process') - ->with($tmpFile) - ->will($this->returnValue($expectedContent)); - $this->object->process($this->chain); - $this->assertEquals($expectedContent, $this->chain->getContent()); - $this->assertEquals('css', $this->chain->getContentType()); - } -} diff --git a/lib/internal/Magento/Framework/View/Asset/ContentProcessorInterface.php b/lib/internal/Magento/Framework/View/Asset/ContentProcessorInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..a7df2aad78c42c00b8b2c96530f53e796b610ff2 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Asset/ContentProcessorInterface.php @@ -0,0 +1,27 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Asset; + +use Magento\Framework\View\Asset\File; + +/** + * Interface ContentProcessorInterface + */ +interface ContentProcessorInterface +{ + /** + * Error prefix + */ + const ERROR_MESSAGE_PREFIX = 'Compilation from source: '; + + /** + * Process file content + * + * @param File $asset + * @return string + */ + public function processContent(File $asset); +} diff --git a/lib/internal/Magento/Framework/View/Asset/LockerProcess.php b/lib/internal/Magento/Framework/View/Asset/LockerProcess.php new file mode 100644 index 0000000000000000000000000000000000000000..3f07c9b0ab23a1b5292f9f9b6e5ac3d46f5fde22 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Asset/LockerProcess.php @@ -0,0 +1,111 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Asset; + +use Magento\Framework\Filesystem; +use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Exception\FileSystemException; +use Magento\Framework\Filesystem\Directory\WriteInterface; + +/** + * Class LockerProcess + */ +class LockerProcess implements LockerProcessInterface +{ + /** + * File extension lock + */ + const LOCK_EXTENSION = '.lock'; + + /** + * Max execution (locking) time for process (in seconds) + */ + const MAX_LOCK_TIME = 30; + + /** + * @var Filesystem + */ + private $filesystem; + + /** + * @var string + */ + private $lockFilePath; + + /** + * @var WriteInterface + */ + private $tmpDirectory; + + /** + * Constructor + * + * @param Filesystem $filesystem + */ + public function __construct(Filesystem $filesystem) + { + $this->filesystem = $filesystem; + } + + /** + * @inheritdoc + * @throws FileSystemException + */ + public function lockProcess($lockName) + { + $this->tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); + $this->lockFilePath = $this->getFilePath($lockName); + + while ($this->isProcessLocked()) { + sleep(1); + } + + $this->tmpDirectory->writeFile($this->lockFilePath, time()); + + } + + /** + * @inheritdoc + * @throws FileSystemException + */ + public function unlockProcess() + { + $this->tmpDirectory->delete($this->lockFilePath); + } + + /** + * Check whether generation process has already locked + * + * @return bool + * @throws FileSystemException + */ + private function isProcessLocked() + { + if ($this->tmpDirectory->isExist($this->lockFilePath)) { + $lockTime = (int) $this->tmpDirectory->readFile($this->lockFilePath); + if ((time() - $lockTime) >= self::MAX_LOCK_TIME) { + $this->tmpDirectory->delete($this->lockFilePath); + + return false; + } + + return true; + } + + return false; + } + + /** + * Get name of lock file + * + * @param string $name + * @return string + */ + private function getFilePath($name) + { + return DirectoryList::TMP . DIRECTORY_SEPARATOR . $name . self::LOCK_EXTENSION; + } +} diff --git a/lib/internal/Magento/Framework/View/Asset/LockerProcessInterface.php b/lib/internal/Magento/Framework/View/Asset/LockerProcessInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..d719653a5f18d74e6592072e1acf7fa71adb8310 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Asset/LockerProcessInterface.php @@ -0,0 +1,23 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Asset; + +/** + * Interface LockerProcessInterface + */ +interface LockerProcessInterface +{ + /** + * @param string $lockName + * @return void + */ + public function lockProcess($lockName); + + /** + * @return void + */ + public function unlockProcess(); +} diff --git a/lib/internal/Magento/Framework/View/Asset/PreProcessor/AlternativeSource.php b/lib/internal/Magento/Framework/View/Asset/PreProcessor/AlternativeSource.php new file mode 100644 index 0000000000000000000000000000000000000000..d727bd9fa40598dba7c3cf65330c8da88155d361 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Asset/PreProcessor/AlternativeSource.php @@ -0,0 +1,161 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Asset\PreProcessor; + +use Magento\Framework\Filesystem; +use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\View\Asset\File\FallbackContext; +use Magento\Framework\View\Asset\LockerProcessInterface; +use Magento\Framework\View\Asset\ContentProcessorInterface; +use Magento\Framework\View\Asset\PreProcessor\AlternativeSource\AssetBuilder; + +/** + * Class AlternativeSource + */ +class AlternativeSource implements AlternativeSourceInterface +{ + /** + * The key name of the processor class + */ + const PROCESSOR_CLASS = 'class'; + + /** + * @var Helper\SortInterface + */ + private $sorter; + + /** + * @var array + */ + private $alternatives; + + /** + * @var ObjectManagerInterface + */ + private $objectManager; + + /** + * @var array + */ + private $alternativesSorted; + + /** + * @var LockerProcessInterface + */ + private $lockerProcess; + + /** + * @var string + */ + private $lockName; + + /** + * @var AssetBuilder + */ + private $assetBuilder; + + /** + * Constructor + * + * @param ObjectManagerInterface $objectManager + * @param LockerProcessInterface $lockerProcess + * @param Helper\SortInterface $sorter + * @param AssetBuilder $assetBuilder + * @param string $lockName + * @param array $alternatives + */ + public function __construct( + ObjectManagerInterface $objectManager, + LockerProcessInterface $lockerProcess, + Helper\SortInterface $sorter, + AssetBuilder $assetBuilder, + $lockName, + array $alternatives = [] + ) { + $this->objectManager = $objectManager; + $this->lockerProcess = $lockerProcess; + $this->sorter = $sorter; + $this->alternatives = $alternatives; + $this->lockName = $lockName; + $this->assetBuilder = $assetBuilder; + } + + /** + * @inheritdoc + * @throws \UnexpectedValueException + */ + public function process(Chain $chain) + { + $path = $chain->getAsset()->getFilePath(); + $content = $chain->getContent(); + if (trim($content) !== '') { + return; + } + + try { + $this->lockerProcess->lockProcess($this->lockName . sprintf('%x', crc32($path . $content))); + + $module = $chain->getAsset()->getModule(); + + /** @var FallbackContext $context */ + $context = $chain->getAsset()->getContext(); + $chain->setContent($this->processContent($path, $content, $module, $context)); + } finally { + $this->lockerProcess->unlockProcess(); + } + } + + /** + * Preparation of content for the destination file + * + * @param string $path + * @param string $content + * @param string $module + * @param FallbackContext $context + * @return string + * @throws \UnexpectedValueException + */ + private function processContent($path, $content, $module, FallbackContext $context) + { + if ($this->alternativesSorted === null) { + $this->alternativesSorted = $this->sorter->sort($this->alternatives); + } + + foreach ($this->alternativesSorted as $name => $alternative) { + $asset = $this->assetBuilder->setArea($context->getAreaCode()) + ->setTheme($context->getThemePath()) + ->setLocale($context->getLocale()) + ->setModule($module) + ->setPath(preg_replace( + '#\.' . preg_quote(pathinfo($path, PATHINFO_EXTENSION)) . '$#', + '.' . $name, + $path + ))->build(); + + $processor = $this->objectManager->get($alternative[self::PROCESSOR_CLASS]); + if (!$processor instanceof ContentProcessorInterface) { + throw new \UnexpectedValueException( + '"' . $alternative[self::PROCESSOR_CLASS] . '" has to implement the ContentProcessorInterface.' + ); + } + $content = $processor->processContent($asset); + + if (trim($content) !== '') { + return $content; + } + } + + return $content; + } + + /** + * @inheritdoc + */ + public function getAlternativesExtensionsNames() + { + return array_keys($this->alternatives); + } +} diff --git a/lib/internal/Magento/Framework/View/Asset/PreProcessor/AlternativeSource/AssetBuilder.php b/lib/internal/Magento/Framework/View/Asset/PreProcessor/AlternativeSource/AssetBuilder.php new file mode 100644 index 0000000000000000000000000000000000000000..79f13bb5632a44cb8f959d8577f22f600f9c8755 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Asset/PreProcessor/AlternativeSource/AssetBuilder.php @@ -0,0 +1,134 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Asset\PreProcessor\AlternativeSource; + +use Magento\Framework\View\Asset\File; +use Magento\Framework\View\Asset\Repository; + +/** + * Class AssetBuilder + */ +class AssetBuilder +{ + /** + * @var string + */ + private $area; + + /** + * @var string + */ + private $theme; + + /** + * @var string + */ + private $locale; + + /** + * @var string + */ + private $module; + + /** + * @var string + */ + private $path; + + /** + * @var Repository + */ + private $repository; + + /** + * Constructor + * + * @param Repository $repository + */ + public function __construct(Repository $repository) + { + $this->repository = $repository; + } + + /** + * Set area + * + * @param string $area + * @return $this + */ + public function setArea($area) + { + $this->area = $area; + return $this; + } + + /** + * Set theme + * + * @param string $theme + * @return $this + */ + public function setTheme($theme) + { + $this->theme = $theme; + return $this; + } + + /** + * Set locale + * + * @param string $locale + * @return $this + */ + public function setLocale($locale) + { + $this->locale = $locale; + return $this; + } + + /** + * Set module + * + * @param string $module + * @return $this + */ + public function setModule($module) + { + $this->module = $module; + return $this; + } + + /** + * Set path + * + * @param string $path + * @return $this + */ + public function setPath($path) + { + $this->path = $path; + return $this; + } + + /** + * @return File + */ + public function build() + { + $params = [ + 'area' => $this->area, + 'theme' => $this->theme, + 'locale' => $this->locale, + 'module' => $this->module, + ]; + + $asset = $this->repository->createAsset($this->path, $params); + + unset($this->path, $this->module, $this->locale, $this->theme, $this->area); + + return $asset; + } +} diff --git a/lib/internal/Magento/Framework/View/Asset/PreProcessor/AlternativeSourceInterface.php b/lib/internal/Magento/Framework/View/Asset/PreProcessor/AlternativeSourceInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..43a20b74809449bd401fff2e119292a99910b60b --- /dev/null +++ b/lib/internal/Magento/Framework/View/Asset/PreProcessor/AlternativeSourceInterface.php @@ -0,0 +1,21 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Asset\PreProcessor; + +use Magento\Framework\View\Asset\PreProcessorInterface; + +/** + * Interface AlternativeSourceInterface + */ +interface AlternativeSourceInterface extends PreProcessorInterface +{ + /** + * Get extensions names of alternatives + * + * @return string[] + */ + public function getAlternativesExtensionsNames(); +} diff --git a/lib/internal/Magento/Framework/View/Asset/PreProcessor/Helper/Sort.php b/lib/internal/Magento/Framework/View/Asset/PreProcessor/Helper/Sort.php new file mode 100644 index 0000000000000000000000000000000000000000..a2a4c1d8f2b5eca6f53cbdb87634a1a0e11aec4a --- /dev/null +++ b/lib/internal/Magento/Framework/View/Asset/PreProcessor/Helper/Sort.php @@ -0,0 +1,72 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Asset\PreProcessor\Helper; + +use Magento\Framework\Phrase; + +/** + * Class Sort + */ +class Sort implements SortInterface +{ + /** + * Name of directive + */ + const DIRECTIVE = 'after'; + + /** + * Key of name items + */ + const NEXT_KEY = 'next'; + + /** + * @var array + */ + private $result; + + /** + * @var array + */ + private $array; + + /** + * @inheritdoc + */ + public function sort(array $array) + { + $this->result = []; + $this->array = $array; + + $nodes = []; + $structure = []; + foreach ($this->array as $name => $item) { + $nodes[$name] = isset($nodes[$name]) ? $nodes[$name] : [self::NEXT_KEY => null]; + if (isset($item[self::DIRECTIVE])) { + $nodes[$item[self::DIRECTIVE]][self::NEXT_KEY][$name] = &$nodes[$name]; + continue; + } + $structure[$name] = &$nodes[$name]; + } + + $this->fillResult($structure); + + return $this->result; + } + + /** + * @param array $structure + * @return void + */ + private function fillResult(array $structure) + { + foreach ($structure as $name => $item) { + $this->result[$name] = $this->array[$name]; + if (!empty($item[self::NEXT_KEY])) { + $this->fillResult($item[self::NEXT_KEY]); + } + } + } +} diff --git a/lib/internal/Magento/Framework/View/Asset/PreProcessor/Helper/SortInterface.php b/lib/internal/Magento/Framework/View/Asset/PreProcessor/Helper/SortInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..130add1da0108caadbd72af45badbc56e00eb1b6 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Asset/PreProcessor/Helper/SortInterface.php @@ -0,0 +1,23 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Asset\PreProcessor\Helper; + +/** + * Interface SortInterface + */ +interface SortInterface +{ + /** + * Sorting an array by directive + * [ + * 'name-1' => ['after' => 'xxx', 'data' => [...]] + * 'name-2' => ['after' => 'xxx', 'data' => [...]] + * ] + * @param array $array + * @return array + */ + public function sort(array $array); +} diff --git a/lib/internal/Magento/Framework/View/Asset/PreProcessor/Pool.php b/lib/internal/Magento/Framework/View/Asset/PreProcessor/Pool.php index 7a8fee000db446c8348d4442dd86bac57d57192f..ee891d96720762ffa50a6ee4edb57acf0736232a 100644 --- a/lib/internal/Magento/Framework/View/Asset/PreProcessor/Pool.php +++ b/lib/internal/Magento/Framework/View/Asset/PreProcessor/Pool.php @@ -14,24 +14,51 @@ use Magento\Framework\View\Asset\PreProcessorInterface; */ class Pool { + const PREPROCESSOR_CLASS = 'class'; + /** - * @var ObjectManagerInterface + * @var array */ - private $objectManager; + private $preprocessors; /** * @var array */ - private $preProcessorClasses = []; + private $instances; + + /** + * @var Helper\SortInterface + */ + private $sorter; + + /** + * @var string + */ + private $defaultPreprocessor; /** + * @var ObjectManagerInterface + */ + private $objectManager; + + /** + * Constructor + * * @param ObjectManagerInterface $objectManager - * @param array $preProcessors + * @param Helper\SortInterface $sorter + * @param string $defaultPreprocessor + * @param array $preprocessors */ - public function __construct(ObjectManagerInterface $objectManager, array $preProcessors = []) - { + public function __construct( + ObjectManagerInterface $objectManager, + Helper\SortInterface $sorter, + $defaultPreprocessor, + array $preprocessors = [] + ) { + $this->preprocessors = $preprocessors; + $this->sorter = $sorter; + $this->defaultPreprocessor = $defaultPreprocessor; $this->objectManager = $objectManager; - $this->preProcessorClasses = $preProcessors; } /** @@ -42,9 +69,8 @@ class Pool */ public function process(Chain $chain) { - $fromType = $chain->getOrigContentType(); - $toType = $chain->getTargetContentType(); - foreach ($this->getPreProcessors($fromType, $toType) as $preProcessor) { + $type = $chain->getTargetContentType(); + foreach ($this->getPreProcessors($type) as $preProcessor) { $preProcessor->process($chain); } } @@ -52,28 +78,35 @@ class Pool /** * Retrieve preProcessors by types * - * @param string $fromType - * @param string $toType + * @param string $type * @return PreProcessorInterface[] + * @throws \UnexpectedValueException */ - private function getPreProcessors($fromType, $toType) + private function getPreProcessors($type) { - $preProcessors = []; - if (isset($this->preProcessorClasses[$fromType]) && isset($this->preProcessorClasses[$fromType][$toType])) { - $preProcessors = $this->preProcessorClasses[$fromType][$toType]; + if (isset($this->instances[$type])) { + return $this->instances[$type]; + } + + if (isset($this->preprocessors[$type])) { + $preprocessors = $this->sorter->sort($this->preprocessors[$type]); } else { - $preProcessors[] = 'Magento\Framework\View\Asset\PreProcessor\Passthrough'; + $preprocessors = [ + 'default' => [self::PREPROCESSOR_CLASS => $this->defaultPreprocessor] + ]; } - $processorInstances = []; - foreach ($preProcessors as $preProcessor) { - $processorInstance = $this->objectManager->get($preProcessor); - if (!$processorInstance instanceof PreProcessorInterface) { - throw new \UnexpectedValueException("{$preProcessor} has to implement the PreProcessorInterface."); + $this->instances[$type] = []; + foreach ($preprocessors as $preprocessor) { + $instance = $this->objectManager->get($preprocessor[self::PREPROCESSOR_CLASS]); + if (!$instance instanceof PreProcessorInterface) { + throw new \UnexpectedValueException( + '"' . $preprocessor[self::PREPROCESSOR_CLASS] . '" has to implement the PreProcessorInterface.' + ); } - $processorInstances[] = $processorInstance; + $this->instances[$type][] = $instance; } - return $processorInstances; + return $this->instances[$type]; } } diff --git a/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Alternative.php b/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Alternative.php index f943656b1cd92a2a0da9803d84a129a3593b3c6e..c8872027ad2af919f455ca7afd7fe3801e6dc9b6 100644 --- a/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Alternative.php +++ b/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/Resolver/Alternative.php @@ -30,7 +30,7 @@ class Alternative extends Simple public function __construct( Filesystem $filesystem, \Magento\Framework\View\Design\Fallback\RulePool $rulePool, - array $alternativeExtensions + array $alternativeExtensions = [] ) { foreach ($alternativeExtensions as $extension => $newExtensions) { if (!is_string($extension) || !is_array($newExtensions)) { diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/LockerProcessTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Asset/LockerProcessTest.php new file mode 100644 index 0000000000000000000000000000000000000000..8cd6a99610b09619e3d3feb14c779065757e7ffd --- /dev/null +++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/LockerProcessTest.php @@ -0,0 +1,155 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Test\Unit\Asset; + +use Magento\Framework\Filesystem; +use Magento\Framework\View\Asset\LockerProcess; +use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Filesystem\Directory\WriteInterface; + +/** + * Class LockerProcessTest + * + * @see \Magento\Framework\View\Asset\LockerProcess + */ +class LockerProcessTest extends \PHPUnit_Framework_TestCase +{ + const LOCK_NAME = 'test-lock'; + + /** + * @var string + */ + private $fileName; + + /** + * @var LockerProcess + */ + private $lockerProcess; + + /** + * @var Filesystem|\PHPUnit_Framework_MockObject_MockObject + */ + private $filesystemMock; + + /** + * Set up + */ + protected function setUp() + { + $this->fileName = DirectoryList::TMP . DIRECTORY_SEPARATOR . self::LOCK_NAME . LockerProcess::LOCK_EXTENSION; + + $this->filesystemMock = $this->getMockBuilder('Magento\Framework\Filesystem') + ->disableOriginalConstructor() + ->getMock(); + + $this->lockerProcess = new LockerProcess($this->filesystemMock); + } + + /** + * Test for lockProcess method + * + * @param string $method + * + * @dataProvider dataProviderTestLockProcess + */ + public function testLockProcess($method) + { + $this->filesystemMock->expects(self::once()) + ->method('getDirectoryWrite') + ->with(DirectoryList::VAR_DIR) + ->willReturn($this->$method()); + + $this->lockerProcess->lockProcess(self::LOCK_NAME); + } + + /** + * Test for unlockProcess method + */ + public function testUnlockProcess() + { + $this->filesystemMock->expects(self::once()) + ->method('getDirectoryWrite') + ->with(DirectoryList::VAR_DIR) + ->willReturn($this->getTmpDirectoryMockFalse(1)); + + $this->lockerProcess->lockProcess(self::LOCK_NAME); + $this->lockerProcess->unlockProcess(); + } + + /** + * @return array + */ + public function dataProviderTestLockProcess() + { + return [ + ['method' => 'getTmpDirectoryMockTrue'], + ['method' => 'getTmpDirectoryMockFalse'] + ]; + } + + /** + * @return WriteInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected function getTmpDirectoryMockTrue() + { + $tmpDirectoryMock = $this->getTmpDirectoryMock(); + + $tmpDirectoryMock->expects(self::atLeastOnce()) + ->method('isExist') + ->with($this->fileName) + ->willReturn(true); + + $tmpDirectoryMock->expects(self::atLeastOnce()) + ->method('readFile') + ->with($this->fileName) + ->willReturn(time() - 25); + + + $tmpDirectoryMock->expects(self::once()) + ->method('writeFile') + ->with($this->fileName, self::matchesRegularExpression('#\d+#')); + + return $tmpDirectoryMock; + } + + /** + * @param int $exactly + * @return WriteInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected function getTmpDirectoryMockFalse($exactly = 0) + { + $tmpDirectoryMock = $this->getTmpDirectoryMock(); + + $tmpDirectoryMock->expects(self::atLeastOnce()) + ->method('isExist') + ->with($this->fileName) + ->willReturn(false); + + $tmpDirectoryMock->expects(self::never()) + ->method('readFile'); + + $tmpDirectoryMock->expects(self::exactly($exactly)) + ->method('delete') + ->with($this->fileName); + + $tmpDirectoryMock->expects(self::once()) + ->method('writeFile') + ->with($this->fileName, self::matchesRegularExpression('#\d+#')); + + return $tmpDirectoryMock; + } + + /** + * @return WriteInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private function getTmpDirectoryMock() + { + $tmpDirectoryMock = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\WriteInterface') + ->getMockForAbstractClass(); + + return $tmpDirectoryMock; + } +} diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Adapter/Less/ProcessorTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Adapter/Less/ProcessorTest.php new file mode 100644 index 0000000000000000000000000000000000000000..5989389bdd2d50b3d2137e62a84801845ee6a33d --- /dev/null +++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Adapter/Less/ProcessorTest.php @@ -0,0 +1,185 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Test\Unit\Asset\PreProcessor\Adapter\Less; + +use Psr\Log\LoggerInterface; +use Magento\Framework\App\State; +use Magento\Framework\View\Asset\File; +use Magento\Framework\View\Asset\Source; +use Magento\Framework\Css\PreProcessor\File\Temporary; +use Magento\Framework\Css\PreProcessor\Adapter\Less\Processor; + +/** + * Class ProcessorTest + */ +class ProcessorTest extends \PHPUnit_Framework_TestCase +{ + const TEST_CONTENT = 'test-content'; + + const ASSET_PATH = 'test-path'; + + const TMP_PATH_LESS = '_file/test.less'; + + const TMP_PATH_CSS = '_file/test.css'; + + const ERROR_MESSAGE = 'Test exception'; + + /** + * @var Processor + */ + private $processor; + + /** + * @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $loggerMock; + + /** + * @var State|\PHPUnit_Framework_MockObject_MockObject + */ + private $appStateMock; + + /** + * @var Source|\PHPUnit_Framework_MockObject_MockObject + */ + private $assetSourceMock; + + /** + * @var Temporary|\PHPUnit_Framework_MockObject_MockObject + */ + private $temporaryFileMock; + + /** + * Set up + */ + protected function setUp() + { + $this->loggerMock = $this->getMockBuilder('Psr\Log\LoggerInterface') + ->getMockForAbstractClass(); + $this->appStateMock = $this->getMockBuilder('Magento\Framework\App\State') + ->disableOriginalConstructor() + ->getMock(); + $this->assetSourceMock = $this->getMockBuilder('Magento\Framework\View\Asset\Source') + ->disableOriginalConstructor() + ->getMock(); + $this->temporaryFileMock = $this->getMockBuilder('Magento\Framework\Css\PreProcessor\File\Temporary') + ->disableOriginalConstructor() + ->getMock(); + + $this->processor = new Processor( + $this->loggerMock, + $this->appStateMock, + $this->assetSourceMock, + $this->temporaryFileMock + ); + } + + /** + * Test for processContent method (exception) + */ + public function testProcessContentException() + { + $assetMock = $this->getAssetMock(); + + $this->appStateMock->expects(self::once()) + ->method('getMode') + ->willReturn(State::MODE_DEVELOPER); + + $this->assetSourceMock->expects(self::once()) + ->method('getContent') + ->with($assetMock) + ->willThrowException(new \Exception(self::ERROR_MESSAGE)); + + $this->loggerMock->expects(self::once()) + ->method('critical') + ->with(Processor::ERROR_MESSAGE_PREFIX . self::ERROR_MESSAGE); + + $this->temporaryFileMock->expects(self::never()) + ->method('createFile'); + + $assetMock->expects(self::never()) + ->method('getPath'); + + $content = $this->processor->processContent($assetMock); + + self::assertEquals(Processor::ERROR_MESSAGE_PREFIX . self::ERROR_MESSAGE, $content); + } + + /** + * Test for processContent method (empty content) + */ + public function testProcessContentEmpty() + { + $assetMock = $this->getAssetMock(); + + $this->appStateMock->expects(self::once()) + ->method('getMode') + ->willReturn(State::MODE_DEVELOPER); + + $this->assetSourceMock->expects(self::once()) + ->method('getContent') + ->with($assetMock) + ->willReturn(''); + + $this->temporaryFileMock->expects(self::never()) + ->method('createFile'); + + $assetMock->expects(self::never()) + ->method('getPath'); + + $this->loggerMock->expects(self::never()) + ->method('critical'); + + $this->processor->processContent($assetMock); + } + + /** + * Test for processContent method (not empty content) + */ + public function testProcessContentNotEmpty() + { + $assetMock = $this->getAssetMock(); + + $this->appStateMock->expects(self::once()) + ->method('getMode') + ->willReturn(State::MODE_DEVELOPER); + + $this->assetSourceMock->expects(self::once()) + ->method('getContent') + ->with($assetMock) + ->willReturn(self::TEST_CONTENT); + + $this->temporaryFileMock->expects(self::once()) + ->method('createFile') + ->with(self::ASSET_PATH, self::TEST_CONTENT) + ->willReturn(__DIR__ . '/' . self::TMP_PATH_LESS); + + $assetMock->expects(self::once()) + ->method('getPath') + ->willReturn(self::ASSET_PATH); + + $this->loggerMock->expects(self::never()) + ->method('critical'); + + $clearSymbol = ["\n", "\r", "\t", ' ']; + self::assertEquals( + trim(str_replace($clearSymbol, '', file_get_contents(__DIR__ . '/' . self::TMP_PATH_CSS))), + trim(str_replace($clearSymbol, '', $this->processor->processContent($assetMock))) + ); + } + + /** + * @return File|\PHPUnit_Framework_MockObject_MockObject + */ + private function getAssetMock() + { + $assetMock = $this->getMockBuilder('Magento\Framework\View\Asset\File') + ->disableOriginalConstructor() + ->getMock(); + + return $assetMock; + } +} diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Adapter/Less/_file/test.css b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Adapter/Less/_file/test.css new file mode 100644 index 0000000000000000000000000000000000000000..7c30a79a3a75110b9504ce41bbcbc33155284668 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Adapter/Less/_file/test.css @@ -0,0 +1,19 @@ +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +body { + background: #333333; + color: #454545; +} +a { + color: #ff9900; +} +h1, +h2, +h3, +h4, +h5, +h6 { + color: #333333; +} diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Adapter/Less/_file/test.less b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Adapter/Less/_file/test.less new file mode 100644 index 0000000000000000000000000000000000000000..6ecc83aa9dae673f78e64c3c43423b852505e0be --- /dev/null +++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Adapter/Less/_file/test.less @@ -0,0 +1,19 @@ +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +@color-orange: #ff9900; +@color-gray_light: #cccccc; +@color-black_dark: #333333; +@color-black_medium: #454545; + +body { + background: @color-black_dark; + color: @color-black_medium; +} +a { + color:@color-orange; +} +h1, h2, h3, h4, h5, h6 { + color: @color-black_dark; +} \ No newline at end of file diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/AlternativeSourceTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/AlternativeSourceTest.php new file mode 100644 index 0000000000000000000000000000000000000000..2c3591ffbb6f294f5d52757121de9bbb00b2158f --- /dev/null +++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/AlternativeSourceTest.php @@ -0,0 +1,363 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Test\Unit\Asset\PreProcessor; + +use Magento\Framework\Filesystem; +use Magento\Framework\View\Asset\File; +use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\View\Asset\LocalInterface; +use Magento\Framework\View\Asset\PreProcessor\Chain; +use Magento\Framework\View\Asset\File\FallbackContext; +use Magento\Framework\View\Asset\LockerProcessInterface; +use Magento\Framework\View\Asset\ContentProcessorInterface; +use Magento\Framework\View\Asset\PreProcessor\AlternativeSource; +use Magento\Framework\View\Asset\PreProcessor\Helper\SortInterface; +use Magento\Framework\View\Asset\PreProcessor\AlternativeSource\AssetBuilder; + +/** + * Class AlternativeSourceTest + * + * @see \Magento\Framework\View\Asset\PreProcessor\AlternativeSource + */ +class AlternativeSourceTest extends \PHPUnit_Framework_TestCase +{ + const AREA = 'test-area'; + + const THEME = 'test-theme'; + + const LOCALE = 'test-locale'; + + const FILE_PATH = 'test-file'; + + const MODULE = 'test-module'; + + const NEW_CONTENT = 'test-new-content'; + + /** + * @var SortInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $sorterMock; + + /** + * @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $objectManagerMock; + + /** + * @var LockerProcessInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $lockerProcessMock; + + /** + * @var AssetBuilder|\PHPUnit_Framework_MockObject_MockObject + */ + private $assetBuilderMock; + + /** + * @var ContentProcessorInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $alternativeMock; + + /** + * Set up + */ + protected function setUp() + { + $this->sorterMock = $this->getMockBuilder('Magento\Framework\View\Asset\PreProcessor\Helper\SortInterface') + ->getMockForAbstractClass(); + $this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface') + ->getMockForAbstractClass(); + $this->lockerProcessMock = $this->getMockBuilder('Magento\Framework\View\Asset\LockerProcessInterface') + ->getMockForAbstractClass(); + $this->assetBuilderMock = $this->getMockBuilder( + 'Magento\Framework\View\Asset\PreProcessor\AlternativeSource\AssetBuilder' + )->disableOriginalConstructor() + ->getMock(); + $this->alternativeMock = $this->getMockBuilder('Magento\Framework\View\Asset\ContentProcessorInterface') + ->getMockForAbstractClass(); + } + + /** + * Run test for process method (exception) + */ + public function testProcessException() + { + $alternatives = [ + 'processor' => [ + AlternativeSource::PROCESSOR_CLASS => 'stdClass' + ] + ]; + + $this->lockerProcessMock->expects(self::once()) + ->method('lockProcess') + ->with(self::isType('string')); + $this->lockerProcessMock->expects(self::once()) + ->method('unlockProcess'); + + $this->sorterMock->expects(self::once()) + ->method('sort') + ->with($alternatives) + ->willReturn($alternatives); + + $this->assetBuilderMock->expects(self::once()) + ->method('setArea') + ->with(self::AREA) + ->willReturnSelf(); + $this->assetBuilderMock->expects(self::once()) + ->method('setTheme') + ->with(self::THEME) + ->willReturnSelf(); + $this->assetBuilderMock->expects(self::once()) + ->method('setLocale') + ->with(self::LOCALE) + ->willReturnSelf(); + $this->assetBuilderMock->expects(self::once()) + ->method('setModule') + ->with(self::MODULE) + ->willReturnSelf(); + $this->assetBuilderMock->expects(self::once()) + ->method('setPath') + ->with(self::FILE_PATH) + ->willReturnSelf(); + $this->assetBuilderMock->expects(self::once()) + ->method('build') + ->willReturn($this->getAssetNew()); + + $this->objectManagerMock->expects(self::once()) + ->method('get') + ->with('stdClass') + ->willReturn(new \stdClass()); + + $alternativeSource = new AlternativeSource( + $this->objectManagerMock, + $this->lockerProcessMock, + $this->sorterMock, + $this->assetBuilderMock, + 'lock', + $alternatives + ); + try { + $alternativeSource->process($this->getChainMockExpects('', 0)); + } catch (\UnexpectedValueException $e) { + self::assertInstanceOf('\UnexpectedValueException', $e); + } + } + + /** + * Run test for process method + */ + public function testProcess() + { + $alternatives = [ + 'processor' => [ + AlternativeSource::PROCESSOR_CLASS => 'Magento\Framework\View\Asset\ContentProcessorInterface' + ] + ]; + + $this->lockerProcessMock->expects(self::once()) + ->method('lockProcess') + ->with(self::isType('string')); + $this->lockerProcessMock->expects(self::once()) + ->method('unlockProcess'); + + $this->sorterMock->expects(self::once()) + ->method('sort') + ->with($alternatives) + ->willReturn($alternatives); + + $assetMock = $this->getAssetNew(); + + $this->assetBuilderMock->expects(self::once()) + ->method('setArea') + ->with(self::AREA) + ->willReturnSelf(); + $this->assetBuilderMock->expects(self::once()) + ->method('setTheme') + ->with(self::THEME) + ->willReturnSelf(); + $this->assetBuilderMock->expects(self::once()) + ->method('setLocale') + ->with(self::LOCALE) + ->willReturnSelf(); + $this->assetBuilderMock->expects(self::once()) + ->method('setModule') + ->with(self::MODULE) + ->willReturnSelf(); + $this->assetBuilderMock->expects(self::once()) + ->method('setPath') + ->with(self::FILE_PATH) + ->willReturnSelf(); + $this->assetBuilderMock->expects(self::once()) + ->method('build') + ->willReturn($assetMock); + + $this->objectManagerMock->expects(self::once()) + ->method('get') + ->with('Magento\Framework\View\Asset\ContentProcessorInterface') + ->willReturn($this->getProcessorMock($assetMock)); + + $alternativeSource = new AlternativeSource( + $this->objectManagerMock, + $this->lockerProcessMock, + $this->sorterMock, + $this->assetBuilderMock, + 'lock', + $alternatives + ); + + $alternativeSource->process($this->getChainMockExpects()); + } + + /** + * Run test for process method (content not empty) + */ + public function testProcessContentNotEmpty() + { + $chainMock = $this->getChainMock(); + $assetMock = $this->getAssetMock(); + + $chainMock->expects(self::once()) + ->method('getContent') + ->willReturn('test-content'); + + $chainMock->expects(self::once()) + ->method('getAsset') + ->willReturn($assetMock); + + $this->lockerProcessMock->expects(self::never()) + ->method('lockProcess'); + $this->lockerProcessMock->expects(self::never()) + ->method('unlockProcess'); + + $alternativeSource = new AlternativeSource( + $this->objectManagerMock, + $this->lockerProcessMock, + $this->sorterMock, + $this->assetBuilderMock, + 'lock', + [] + ); + + $alternativeSource->process($chainMock); + } + + /** + * @param \PHPUnit_Framework_MockObject_MockObject $asset + * @return ContentProcessorInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private function getProcessorMock($asset) + { + $processorMock = $this->getMockBuilder('Magento\Framework\View\Asset\ContentProcessorInterface') + ->getMockForAbstractClass(); + + $processorMock->expects(self::once()) + ->method('processContent') + ->with($asset) + ->willReturn(self::NEW_CONTENT); + + return $processorMock; + } + + /** + * @return Chain|\PHPUnit_Framework_MockObject_MockObject + */ + private function getChainMock() + { + $chainMock = $this->getMockBuilder('Magento\Framework\View\Asset\PreProcessor\Chain') + ->disableOriginalConstructor() + ->getMock(); + + return $chainMock; + } + + /** + * @param string $content + * @param int $contentExactly + * @return Chain|\PHPUnit_Framework_MockObject_MockObject + */ + private function getChainMockExpects($content = '', $contentExactly = 1) + { + $chainMock = $this->getChainMock(); + + $chainMock->expects(self::once()) + ->method('getContent') + ->willReturn($content); + $chainMock->expects(self::exactly(3)) + ->method('getAsset') + ->willReturn($this->getAssetMockExpects()); + $chainMock->expects(self::exactly($contentExactly)) + ->method('setContent') + ->willReturn(self::NEW_CONTENT); + + return $chainMock; + } + + /** + * @return File|\PHPUnit_Framework_MockObject_MockObject + */ + private function getAssetNew() + { + $assetMock = $this->getMockBuilder('Magento\Framework\View\Asset\File') + ->disableOriginalConstructor() + ->getMock(); + + return $assetMock; + } + + /** + * @return LocalInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private function getAssetMock() + { + $assetMock = $this->getMockBuilder('Magento\Framework\View\Asset\LocalInterface') + ->disableOriginalConstructor() + ->getMock(); + + return $assetMock; + } + + /** + * @return LocalInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private function getAssetMockExpects() + { + $assetMock = $this->getAssetMock(); + + $assetMock->expects(self::once()) + ->method('getContext') + ->willReturn($this->getContextMock()); + $assetMock->expects(self::once()) + ->method('getFilePath') + ->willReturn(self::FILE_PATH); + $assetMock->expects(self::once()) + ->method('getModule') + ->willReturn(self::MODULE); + + return $assetMock; + } + + /** + * @return FallbackContext|\PHPUnit_Framework_MockObject_MockObject + */ + private function getContextMock() + { + $contextMock = $this->getMockBuilder('Magento\Framework\View\Asset\File\FallbackContext') + ->disableOriginalConstructor() + ->getMock(); + + $contextMock->expects(self::once()) + ->method('getAreaCode') + ->willReturn(self::AREA); + $contextMock->expects(self::once()) + ->method('getThemePath') + ->willReturn(self::THEME); + $contextMock->expects(self::once()) + ->method('getLocale') + ->willReturn(self::LOCALE); + + return $contextMock; + } +} diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Helper/SortTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Helper/SortTest.php new file mode 100644 index 0000000000000000000000000000000000000000..35e043143266047e8ec3e579409ab0a1ce1f9713 --- /dev/null +++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/Helper/SortTest.php @@ -0,0 +1,195 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\View\Test\Unit\Asset\PreProcessor\Helper; + +use Magento\Framework\View\Asset\PreProcessor\Helper\Sort; + +/** + * Class SortTest + * + * @see \Magento\Framework\View\Asset\PreProcessor\Helper\Sorter2 + */ +class SortTest extends \PHPUnit_Framework_TestCase +{ + /** + * @param array $arrayData + * @param array $expected + * + * @dataProvider dataProviderTestSorting + */ + public function testSorting(array $arrayData, array $expected, $message) + { + $sorter = new Sort(); + + $result = $sorter->sort($arrayData); + + static::assertEquals($expected, array_keys($result), $message); + } + + /** + * @return array + * + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function dataProviderTestSorting() + { + return [ + [ + 'arrayData' => [ + 'name-1' => [ // 2 + 'after' => 'name-3', + 'processor' => new \stdClass() + ], + 'name-2' => [ // 0 + 'processor' => new \stdClass() + ], + 'name-3' => [ // 1 + 'after' => 'name-2', + 'processor' => new \stdClass() + ], + ], + 'expected' => [ + 'name-2', 'name-3', 'name-1' + ], + 'message' => 'variation-1', + ], + [ + 'arrayData' => [ + 'name-1' => [ // 3 + 'after' => 'name-6', + 'processor' => new \stdClass() + ], + 'name-2' => [ // 1 + 'processor' => new \stdClass() + ], + 'name-3' => [ // 6 + 'after' => 'name-5', + 'processor' => new \stdClass() + ], + 'name-4' => [ // 4 + 'after' => 'name-1', + 'processor' => new \stdClass() + ], + 'name-5' => [ // 5 + 'after' => 'name-4', + 'processor' => new \stdClass() + ], + 'name-6' => [ // 2 + 'after' => 'name-2', + 'processor' => new \stdClass() + ], + ], + 'expected' => [ + 'name-2', 'name-6', 'name-1', 'name-4', 'name-5', 'name-3' + ], + 'message' => 'variation-2', + ], + [ + 'arrayData' => [ + 'name-1' => [ // 3 + 'after' => 'name-6', + 'processor' => new \stdClass() + ], + 'name-3' => [ // 6 + 'after' => 'name-5', + 'processor' => new \stdClass() + ], + 'name-4' => [ // 4 + 'after' => 'name-1', + 'processor' => new \stdClass() + ], + 'name-5' => [ // 5 + 'after' => 'name-4', + 'processor' => new \stdClass() + ], + 'name-6' => [ // 2 + 'after' => 'name-2', + 'processor' => new \stdClass() + ], + 'name-2' => [ // 1 + 'processor' => new \stdClass() + ], + ], + 'expected' => [ + 'name-2', 'name-6', 'name-1', 'name-4', 'name-5', 'name-3' + ], + 'message' => 'variation-3', + ], + [ + 'arrayData' => [ + 'name-1' => [ // 3 + 'after' => 'name-6', + 'processor' => new \stdClass() + ], + 'name-2' => [ // 1 + 'processor' => new \stdClass() + ], + 'name-3' => [ // 6 + 'after' => 'name-5', + 'processor' => new \stdClass() + ], + 'name-4' => [ // 4 + 'after' => 'name-1', + 'processor' => new \stdClass() + ], + 'name-5' => [ // 5 + 'after' => 'name-4', + 'processor' => new \stdClass() + ], + 'name-6' => [ // 2 + 'after' => 'name-2', + 'processor' => new \stdClass() + ], + 'name-7' => [ // end + 'processor' => new \stdClass() + ], + 'name-8' => [ // end + 'processor' => new \stdClass() + ], + ], + 'expected' => [ + 'name-2', 'name-6', 'name-1', 'name-4', 'name-5', 'name-3', 'name-7', 'name-8' + ], + 'message' => 'variation-4', + ], + [ + 'arrayData' => [ + 'name-1' => [ // xxx + 'after' => 'name-6', + 'processor' => new \stdClass() + ], + 'name-2' => [ // 1 + 'processor' => new \stdClass() + ], + 'name-3' => [ // xxx + 'after' => 'name-XXX', + 'processor' => new \stdClass() + ] + ], + 'expected' => ['name-2'], + 'message' => 'variation-5', + ], + [ + 'arrayData' => [ + 'name-1' => [ // xxx + 'after' => 'name-3', + 'processor' => new \stdClass() + ], + 'name-2' => [ // xxx + 'after' => 'name-1', + 'processor' => new \stdClass() + ], + 'name-3' => [ // xxx + 'after' => 'name-2', + 'processor' => new \stdClass() + ] + ], + 'expected' => [], + 'message' => 'variation-6', + ], + ]; + } +} diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/PoolTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/PoolTest.php index eb41418aaefed37555ce5aa5b0114b19dc8a8a23..d7fd211ef79493d7728f4f208a1c4b405dcf4bde 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/PoolTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/PoolTest.php @@ -6,127 +6,181 @@ namespace Magento\Framework\View\Test\Unit\Asset\PreProcessor; -use \Magento\Framework\View\Asset\PreProcessor\Pool; +use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\View\Asset\PreProcessor\Pool; +use Magento\Framework\View\Asset\PreProcessor\Chain; +use Magento\Framework\View\Asset\PreProcessorInterface; +use Magento\Framework\View\Asset\PreProcessor\Helper\SortInterface; +/** + * Class PoolTest + * + * @see \Magento\Framework\View\Asset\PreProcessor\Pool + */ class PoolTest extends \PHPUnit_Framework_TestCase { + const DEFAULT_PREPROCESSOR = 'defaul/preprocessor'; + + const CONTENT_TYPE = 'test-type'; + + const PREPROCESSOR_CLASS = 'Magento\Framework\View\Asset\PreProcessorInterface'; + /** - * @var \Magento\Framework\View\Asset\PreProcessor\Pool + * @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $processorPool; + private $objectManagerMock; /** - * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var SortInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $objectManager; + private $sorterMock; /** - * @var \Magento\Framework\View\Asset\PreProcessor\Chain|\PHPUnit_Framework_MockObject_MockObject + * Set up + * + * @return void */ - protected $processorChain; - - protected function setUp() + public function setUp() { - $this->objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); + $this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface') + ->getMockForAbstractClass(); + $this->sorterMock = $this->getMockBuilder('Magento\Framework\View\Asset\PreProcessor\Helper\SortInterface') + ->getMockForAbstractClass(); + } - $this->processorChain = $this->getMockBuilder('Magento\Framework\View\Asset\PreProcessor\Chain') + /** + * @return Chain|\PHPUnit_Framework_MockObject_MockObject + */ + private function getChainMock($type) + { + /** @var Chain|\PHPUnit_Framework_MockObject_MockObject $chainMock */ + $chainMock = $this->getMockBuilder('Magento\Framework\View\Asset\PreProcessor\Chain') ->disableOriginalConstructor() - ->setMethods([]) ->getMock(); - $this->processorPool = new Pool( - $this->objectManager, - [ - 'less' => [ - 'css' => - [ - 'Magento\Framework\Css\PreProcessor\Less', - 'Magento\Framework\View\Asset\PreProcessor\VariableNotation', - 'Magento\Framework\View\Asset\PreProcessor\ModuleNotation', - ], - 'less' => - [ - 'Magento\Framework\Css\PreProcessor\Instruction\MagentoImport', - 'Magento\Framework\Css\PreProcessor\Instruction\Import', - ], - ], - 'css' => [ - 'css' => [ - 'Magento\Framework\View\Asset\PreProcessor\VariableNotation', - 'Magento\Framework\View\Asset\PreProcessor\ModuleNotation', - ] - ], + $chainMock->expects(self::once()) + ->method('getTargetContentType') + ->willReturn($type); + + return $chainMock; + } + + /** + * @param Chain|\PHPUnit_Framework_MockObject_MockObject $chainMock + * @return PreProcessorInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private function getPreprocessorMock($chainMock) + { + /** @var PreProcessorInterface|\PHPUnit_Framework_MockObject_MockObject $preprocessorMock */ + $preprocessorMock = $this->getMockBuilder(self::PREPROCESSOR_CLASS) + ->getMockForAbstractClass(); + + $preprocessorMock->expects(self::once()) + ->method('process') + ->with($chainMock); + + return $preprocessorMock; + } + + /** + * Run test for process method + */ + public function testProcess() + { + $preprocessors = [ + self::CONTENT_TYPE => [ + 'test' => [ + Pool::PREPROCESSOR_CLASS => self::PREPROCESSOR_CLASS + ] ] + ]; + + $pool = new Pool( + $this->objectManagerMock, + $this->sorterMock, + self::DEFAULT_PREPROCESSOR, + $preprocessors ); + + $this->sorterMock->expects(self::once()) + ->method('sort') + ->with($preprocessors[self::CONTENT_TYPE]) + ->willReturn($preprocessors[self::CONTENT_TYPE]); + + $chainMock = $this->getChainMock(self::CONTENT_TYPE); + + $this->objectManagerMock->expects(self::once()) + ->method('get') + ->with(self::PREPROCESSOR_CLASS) + ->willReturn($this->getPreprocessorMock($chainMock)); + + $pool->process($chainMock); } /** - * @param string $sourceContentType - * @param string $targetContentType - * @param array $expectedResult - * - * @dataProvider getPreProcessorsDataProvider + * Run test for process method (default preprocessor) */ - public function testProcess($sourceContentType, $targetContentType, array $expectedResult) + public function testProcessDefault() { + $preprocessors = [ + 'bad-type' => [], + ]; - $this->processorChain->expects($this->any()) - ->method('getOrigContentType') - ->willReturn($sourceContentType); - $this->processorChain->expects($this->any()) - ->method('getTargetContentType') - ->willReturn($targetContentType); - $processorMaps = []; - foreach ($expectedResult as $processor) { - $processorMock = $this->getMock($processor, ['process'], [], '', false); - $processorMock->expects($this->any()) - ->method('process') - ->with($this->processorChain); - $processorMaps[] = [$processor, $processorMock]; - } - $this->objectManager - ->expects(static::atLeastOnce()) + $pool = new Pool( + $this->objectManagerMock, + $this->sorterMock, + self::DEFAULT_PREPROCESSOR, + $preprocessors + ); + + $this->sorterMock->expects(self::never()) + ->method('sort'); + + $chainMock = $this->getChainMock(self::CONTENT_TYPE); + + $this->objectManagerMock->expects(self::once()) ->method('get') - ->willReturnMap($processorMaps); + ->with(self::DEFAULT_PREPROCESSOR) + ->willReturn($this->getPreprocessorMock($chainMock)); - $this->processorPool->process($this->processorChain); + $pool->process($chainMock); } - public function getPreProcessorsDataProvider() + /** + * Run test for process method (exception) + * + * @expectedException \UnexpectedValueException + * @expectedExceptionMessage "stdClass" has to implement the PreProcessorInterface. + */ + public function testProcessBadInterface() { - return [ - 'css => css' => [ - 'css', 'css', - [ - 'Magento\Framework\View\Asset\PreProcessor\VariableNotation', - 'Magento\Framework\View\Asset\PreProcessor\ModuleNotation', - ], - ], - //all undefined types will be processed by Passthrough preprocessor - 'css => less' => [ - 'css', 'less', - ['Magento\Framework\View\Asset\PreProcessor\Passthrough'], - ], - 'less => css' => [ - 'less', 'css', - [ - 'Magento\Framework\Css\PreProcessor\Less', - 'Magento\Framework\View\Asset\PreProcessor\VariableNotation', - 'Magento\Framework\View\Asset\PreProcessor\ModuleNotation', - ], - ], - 'less => less' => [ - 'less', 'less', - [ - 'Magento\Framework\Css\PreProcessor\Instruction\MagentoImport', - 'Magento\Framework\Css\PreProcessor\Instruction\Import', - ], - ], - //all undefined types will be processed by Passthrough preprocessor - 'txt => log (undefined)' => [ - 'txt', 'log', - ['Magento\Framework\View\Asset\PreProcessor\Passthrough'], - ], + $preprocessors = [ + self::CONTENT_TYPE => [ + 'test' => [ + Pool::PREPROCESSOR_CLASS => 'stdClass' + ] + ] ]; + + $pool = new Pool( + $this->objectManagerMock, + $this->sorterMock, + self::DEFAULT_PREPROCESSOR, + $preprocessors + ); + + $this->sorterMock->expects(self::once()) + ->method('sort') + ->with($preprocessors[self::CONTENT_TYPE]) + ->willReturn($preprocessors[self::CONTENT_TYPE]); + + $chainMock = $this->getChainMock(self::CONTENT_TYPE); + + $this->objectManagerMock->expects(self::once()) + ->method('get') + ->with('stdClass') + ->willReturn(new \stdClass()); + + $pool->process($chainMock); } }