diff --git a/app/code/Magento/Braintree/Block/Paypal/Button.php b/app/code/Magento/Braintree/Block/Paypal/Button.php index 8a90fc23ad123..efd9e473699c3 100644 --- a/app/code/Magento/Braintree/Block/Paypal/Button.php +++ b/app/code/Magento/Braintree/Block/Paypal/Button.php @@ -5,13 +5,13 @@ */ namespace Magento\Braintree\Block\Paypal; -use Magento\Checkout\Model\Session; +use Magento\Braintree\Gateway\Config\PayPal\Config; +use Magento\Braintree\Model\Ui\ConfigProvider; use Magento\Catalog\Block\ShortcutInterface; -use Magento\Framework\View\Element\Template; +use Magento\Checkout\Model\Session; use Magento\Framework\Locale\ResolverInterface; -use Magento\Braintree\Model\Ui\ConfigProvider; +use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; -use Magento\Braintree\Gateway\Config\PayPal\Config; use Magento\Payment\Model\MethodInterface; /** @@ -110,7 +110,7 @@ public function getContainerId() */ public function getLocale() { - return strtolower($this->localeResolver->getLocale()); + return $this->localeResolver->getLocale(); } /** diff --git a/app/code/Magento/Braintree/Model/LocaleResolver.php b/app/code/Magento/Braintree/Model/LocaleResolver.php new file mode 100644 index 0000000000000..cebd90dffc70e --- /dev/null +++ b/app/code/Magento/Braintree/Model/LocaleResolver.php @@ -0,0 +1,93 @@ +resolver = $resolver; + $this->config = $config; + } + + /** + * @inheritdoc + */ + public function getDefaultLocalePath() + { + return $this->resolver->getDefaultLocalePath(); + } + + /** + * @inheritdoc + */ + public function setDefaultLocale($locale) + { + return $this->resolver->setDefaultLocale($locale); + } + + /** + * @inheritdoc + */ + public function getDefaultLocale() + { + return $this->resolver->getDefaultLocale(); + } + + /** + * @inheritdoc + */ + public function setLocale($locale = null) + { + return $this->resolver->setLocale($locale); + } + + /** + * Gets store's locale or the `en_US` locale if store's locale does not supported by PayPal. + * + * @return string + */ + public function getLocale() + { + $locale = $this->resolver->getLocale(); + $allowedLocales = $this->config->getValue('supported_locales'); + + return strpos($allowedLocales, $locale) !== false ? $locale : 'en_US'; + } + + /** + * @inheritdoc + */ + public function emulate($scopeId) + { + return $this->resolver->emulate($scopeId); + } + + /** + * @inheritdoc + */ + public function revert() + { + return $this->resolver->revert(); + } +} diff --git a/app/code/Magento/Braintree/Model/Ui/PayPal/ConfigProvider.php b/app/code/Magento/Braintree/Model/Ui/PayPal/ConfigProvider.php index fc400cb375ea7..e06b913db8ef4 100644 --- a/app/code/Magento/Braintree/Model/Ui/PayPal/ConfigProvider.php +++ b/app/code/Magento/Braintree/Model/Ui/PayPal/ConfigProvider.php @@ -54,7 +54,7 @@ public function getConfig() 'title' => $this->config->getTitle(), 'isAllowShippingAddressOverride' => $this->config->isAllowToEditShippingAddress(), 'merchantName' => $this->config->getMerchantName(), - 'locale' => strtolower($this->resolver->getLocale()), + 'locale' => $this->resolver->getLocale(), 'paymentAcceptanceMarkSrc' => 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/pp-acceptance-medium.png', 'vaultCode' => self::PAYPAL_VAULT_CODE, diff --git a/app/code/Magento/Braintree/Test/Unit/Model/Ui/PayPal/ConfigProviderTest.php b/app/code/Magento/Braintree/Test/Unit/Model/Ui/PayPal/ConfigProviderTest.php index 92d5f0a41716b..ea46d8ee77a8a 100644 --- a/app/code/Magento/Braintree/Test/Unit/Model/Ui/PayPal/ConfigProviderTest.php +++ b/app/code/Magento/Braintree/Test/Unit/Model/Ui/PayPal/ConfigProviderTest.php @@ -49,42 +49,35 @@ protected function setUp() /** * Run test getConfig method * - * @param array $config + * @param array $expected * @dataProvider getConfigDataProvider */ public function testGetConfig($expected) { - $this->config->expects(static::once()) - ->method('isActive') + $this->config->method('isActive') ->willReturn(true); - $this->config->expects(static::once()) - ->method('isAllowToEditShippingAddress') + $this->config->method('isAllowToEditShippingAddress') ->willReturn(true); - $this->config->expects(static::once()) - ->method('getMerchantName') + $this->config->method('getMerchantName') ->willReturn('Test'); - $this->config->expects(static::once()) - ->method('getTitle') + $this->config->method('getTitle') ->willReturn('Payment Title'); - $this->localeResolver->expects(static::once()) - ->method('getLocale') + $this->localeResolver->method('getLocale') ->willReturn('en_US'); - $this->config->expects(static::once()) - ->method('isSkipOrderReview') + $this->config->method('isSkipOrderReview') ->willReturn(false); - $this->config->expects(static::once()) - ->method('getPayPalIcon') + $this->config->method('getPayPalIcon') ->willReturn([ 'width' => 30, 'height' => 26, 'url' => 'https://icon.test.url' ]); - static::assertEquals($expected, $this->configProvider->getConfig()); + self::assertEquals($expected, $this->configProvider->getConfig()); } /** @@ -101,7 +94,7 @@ public function getConfigDataProvider() 'title' => 'Payment Title', 'isAllowShippingAddressOverride' => true, 'merchantName' => 'Test', - 'locale' => 'en_us', + 'locale' => 'en_US', 'paymentAcceptanceMarkSrc' => 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/pp-acceptance-medium.png', 'vaultCode' => ConfigProvider::PAYPAL_VAULT_CODE, diff --git a/app/code/Magento/Braintree/etc/config.xml b/app/code/Magento/Braintree/etc/config.xml index f1bbdf79b7d7e..e91f59fb0740e 100644 --- a/app/code/Magento/Braintree/etc/config.xml +++ b/app/code/Magento/Braintree/etc/config.xml @@ -34,7 +34,7 @@ processing sandbox 0 - + cvv,number @@ -66,6 +66,7 @@ 1 processorResponseCode,processorResponseText,paymentId processorResponseCode,processorResponseText,paymentId,payerEmail + en_US,en_GB,en_AU,da_DK,fr_FR,fr_CA,de_DE,zh_HK,it_IT,nl_NL,no_NO,pl_PL,es_ES,sv_SE,tr_TR,pt_BR,ja_JP,id_ID,ko_KR,pt_PT,ru_RU,th_TH,zh_CN,zh_TW BraintreeCreditCardVaultFacade diff --git a/app/code/Magento/Braintree/etc/frontend/di.xml b/app/code/Magento/Braintree/etc/frontend/di.xml index 1983bb1f20e62..ea417c407dffd 100644 --- a/app/code/Magento/Braintree/etc/frontend/di.xml +++ b/app/code/Magento/Braintree/etc/frontend/di.xml @@ -46,6 +46,7 @@ + Magento\Braintree\Model\LocaleResolver Magento_Braintree::paypal/button.phtml braintree.paypal.mini-cart @@ -54,4 +55,10 @@ BraintreePayPalFacade + + + + Magento\Braintree\Model\LocaleResolver + + diff --git a/app/code/Magento/Braintree/view/frontend/requirejs-config.js b/app/code/Magento/Braintree/view/frontend/requirejs-config.js index 8b347d799007a..9fc38064677ef 100644 --- a/app/code/Magento/Braintree/view/frontend/requirejs-config.js +++ b/app/code/Magento/Braintree/view/frontend/requirejs-config.js @@ -6,7 +6,7 @@ var config = { map: { '*': { - braintree: 'https://js.braintreegateway.com/js/braintree-2.25.0.min.js' + braintree: 'https://js.braintreegateway.com/js/braintree-2.32.0.min.js' } } }; diff --git a/app/code/Magento/Braintree/view/frontend/web/js/paypal/button.js b/app/code/Magento/Braintree/view/frontend/web/js/paypal/button.js index eaac1cd116082..3ac50fbcb47cc 100644 --- a/app/code/Magento/Braintree/view/frontend/web/js/paypal/button.js +++ b/app/code/Magento/Braintree/view/frontend/web/js/paypal/button.js @@ -105,7 +105,11 @@ define( event.preventDefault(); registry.get(self.integrationName, function (integration) { - integration.paypal.initAuthFlow(); + try { + integration.paypal.initAuthFlow(); + } catch (e) { + $this.attr('disabled', 'disabled'); + } }); }); }.bind(this); diff --git a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js index 182ec5e7168e8..9804ee8489625 100644 --- a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js +++ b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js @@ -13,7 +13,8 @@ define([ 'Magento_Checkout/js/model/full-screen-loader', 'Magento_Checkout/js/model/payment/additional-validators', 'Magento_Vault/js/view/payment/vault-enabler', - 'Magento_Checkout/js/action/create-billing-address' + 'Magento_Checkout/js/action/create-billing-address', + 'mage/translate' ], function ( $, _, @@ -23,7 +24,8 @@ define([ fullScreenLoader, additionalValidators, VaultEnabler, - createBillingAddress + createBillingAddress, + $t ) { 'use strict'; @@ -403,7 +405,13 @@ define([ */ payWithPayPal: function () { if (additionalValidators.validate()) { - Braintree.checkout.paypal.initAuthFlow(); + try { + Braintree.checkout.paypal.initAuthFlow(); + } catch (e) { + this.messageContainer.addErrorMessage({ + message: $t('Payment ' + this.getTitle() + ' can\'t be initialized.') + }); + } } }, diff --git a/composer.json b/composer.json index 79b44a9ae2e38..08b921abcd650 100644 --- a/composer.json +++ b/composer.json @@ -68,6 +68,7 @@ "ext-openssl": "*", "ext-zip": "*", "ext-pdo_mysql": "*", + "ext-soap": "*", "sjparkinson/static-review": "~4.1", "ramsey/uuid": "3.6.1" }, diff --git a/composer.lock b/composer.lock index 8b56f72d8d650..845d2bbf5576d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "f6383328a3387e72091eddc2ed464cd1", - "content-hash": "466e4d122888ecfdcc9705c880a4dd69", + "hash": "943975c96428352b445c2636c6c53e9b", + "content-hash": "c7ae72ad7777ba197d1ba038a50df230", "packages": [ { "name": "braintree/braintree_php", @@ -5449,7 +5449,8 @@ "ext-mbstring": "*", "ext-openssl": "*", "ext-zip": "*", - "ext-pdo_mysql": "*" + "ext-pdo_mysql": "*", + "ext-soap": "*" }, "platform-dev": [] } diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/paypal/button.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/paypal/button.test.js new file mode 100644 index 0000000000000..a4767fb551ee3 --- /dev/null +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/paypal/button.test.js @@ -0,0 +1,85 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +/* eslint-disable max-nested-callbacks */ +define([ + 'squire', + 'jquery' +], function (Squire) { + 'use strict'; + + describe('Magento_Braintree/js/paypal/button', function () { + var injector, + mocks, + braintree, + component, + registry, + btnId = 'braintree_paypal_btn', + tplElement = jQuery('')[0]; + + require.config({ + map: { + '*': { + 'braintree': 'braintree' + } + } + }); + + injector = new Squire(); + mocks = { + 'braintree': { + paypal: { + /** Stub */ + initAuthFlow: function () {} + }, + + /** Stub */ + setup: function () {} + } + }; + + beforeEach(function (done) { + injector.mock(mocks); + + injector.require([ + 'braintree', + 'uiRegistry', + 'Magento_Braintree/js/paypal/button' + ], function (adapter, reg, Constr) { + braintree = adapter; + registry = reg; + jQuery(document.body).append(tplElement); + + spyOn(braintree, 'setup').and.callFake(function () { + registry.set('braintreePaypal.currentIntegration', braintree); + jQuery('#' + btnId).removeAttr('disabled'); + }); + + component = new Constr({ + id: btnId + }); + done(); + }); + }); + + afterAll(function (done) { + tplElement.remove(); + registry.remove(component.integrationName); + done(); + }); + + it('The PayPal::initAuthFlow throws an exception.', function () { + var $selector = jQuery('#' + component.id); + + spyOn(braintree.paypal, 'initAuthFlow').and.callFake(function () { + throw new TypeError('Cannot read property of undefined'); + }); + + $selector.trigger('click'); + + expect($selector.prop('disabled')).toEqual(true); + }); + }); +}); diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/paypal.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/paypal.test.js new file mode 100644 index 0000000000000..a9987f5e01ba8 --- /dev/null +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/view/payment/method-renderer/paypal.test.js @@ -0,0 +1,79 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +/* eslint-disable max-nested-callbacks */ +define([ + 'squire', + 'ko' +], function (Squire, ko) { + 'use strict'; + + describe('Magento_Braintree/js/view/payment/method-renderer/paypal', function () { + + var injector = new Squire(), + mocks = { + 'Magento_Checkout/js/model/quote': { + billingAddress: ko.observable(), + shippingAddress: ko.observable({ + postcode: '', + street: [], + canUseForBilling: ko.observable() + }), + paymentMethod: ko.observable(), + totals: ko.observable({ + 'base_grand_total': 0 + }) + }, + 'Magento_Braintree/js/view/payment/adapter': { + checkout: { + paypal: { + /** Stub */ + initAuthFlow: function () {} + } + } + } + }, + braintreeAdapter, + component, + additionalValidator; + + beforeEach(function (done) { + window.checkoutConfig = { + quoteData: {}, + payment: { + 'braintree_paypal': { + title: 'Braintree PayPal' + } + }, + vault: {} + }; + + injector.mock(mocks); + + injector.require([ + 'Magento_Braintree/js/view/payment/adapter', + 'Magento_Checkout/js/model/payment/additional-validators', + 'Magento_Braintree/js/view/payment/method-renderer/paypal' + ], function (adapter, validator, Constr) { + braintreeAdapter = adapter; + additionalValidator = validator; + component = new Constr(); + done(); + }); + }); + + it('The PayPal::initAuthFlow throws an exception.', function () { + + spyOn(additionalValidator, 'validate').and.returnValue(true); + spyOn(braintreeAdapter.checkout.paypal, 'initAuthFlow').and.callFake(function () { + throw new TypeError('Cannot read property of undefined'); + }); + spyOn(component.messageContainer, 'addErrorMessage'); + + component.payWithPayPal(); + expect(component.messageContainer.addErrorMessage).toHaveBeenCalled(); + }); + }); +}); diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/ComposerLockTest.php b/dev/tests/static/testsuite/Magento/Test/Integrity/ComposerLockTest.php index 001d7b1327dcc..c856296102095 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/ComposerLockTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/ComposerLockTest.php @@ -10,15 +10,121 @@ */ class ComposerLockTest extends \PHPUnit_Framework_TestCase { - public function testUpToDate() + /** + * @return string + */ + public function testLockFileExists() { - $hash = hash_file('md5', BP . '/composer.json'); $lockFilePath = BP . '/composer.lock'; - if (!file_exists($lockFilePath)) { - $this->markTestSkipped('composer.lock file doesn\'t exist'); + $this->assertLockFileExists($lockFilePath); + return $lockFilePath; + } + + /** + * @depends testLockFileExists + * @param string $lockFilePath + * @return string + */ + public function testLockFileReadable($lockFilePath) + { + $this->assertLockFileReadable($lockFilePath); + return $lockFilePath; + } + + /** + * @depends testLockFileReadable + * @param string $lockFilePath + * @return string + */ + public function testLockFileContainsJson($lockFilePath) + { + $lockFileContent = file_get_contents($lockFilePath); + $this->assertLockFileContainsValidJson($lockFileContent); + return $lockFileContent; + } + + /** + * @depends testLockFileContainsJson + * @param string $lockFileContent + */ + public function testUpToDate($lockFileContent) + { + $lockData = json_decode($lockFileContent, true); + $composerFilePath = BP . '/composer.json'; + $this->assertLockDataRelevantToComposerFile($lockData, $composerFilePath); + } + + /** + * @param string $lockFilePath + */ + private function assertLockFileExists($lockFilePath) + { + $this->assertFileExists($lockFilePath, 'composer.lock file does not exist'); + } + + /** + * @param string $lockFilePath + */ + private function assertLockFileReadable($lockFilePath) + { + if (!is_readable($lockFilePath)) { + $this->fail('composer.lock file is not readable'); } - $jsonData = file_get_contents($lockFilePath); - $json = json_decode($jsonData); - $this->assertSame($hash, $json->hash, 'composer.lock file is not up to date'); + } + + /** + * @param string $lockFileContent + */ + private function assertLockFileContainsValidJson($lockFileContent) + { + $this->assertJson($lockFileContent, 'composer.lock file does not contains valid json'); + } + + /** + * @param array $lockData + * @param string $composerFilePath + */ + private function assertLockDataRelevantToComposerFile(array $lockData, $composerFilePath) + { + if (isset($lockData['content-hash'])) { + $this->assertLockDataRelevantToMeaningfulComposerConfig($lockData, $composerFilePath); + } else if (isset($lockData['hash'])) { + $this->assertLockDataRelevantToFullComposerConfig($lockData, $composerFilePath); + } else { + $this->fail('composer.lock does not linked to composer.json data'); + } + } + + /** + * @param array $lockData + * @param string $composerFilePath + */ + private function assertLockDataRelevantToMeaningfulComposerConfig(array $lockData, $composerFilePath) + { + $contentHashCalculator = 'Composer\Package\Locker::getContentHash'; + if (!is_callable($contentHashCalculator)) { + $this->markTestSkipped('Unable to check composer.lock file by content hash'); + } + + $composerContentHash = call_user_func($contentHashCalculator, file_get_contents($composerFilePath)); + $this->assertSame( + $composerContentHash, + $lockData['content-hash'], + 'composer.lock file is not up to date (composer.json file was modified)' + ); + } + + /** + * @param array $lockData + * @param string $composerFilePath + */ + private function assertLockDataRelevantToFullComposerConfig(array $lockData, $composerFilePath) + { + $composerFileHash = hash_file('md5', $composerFilePath); + $this->assertSame( + $composerFileHash, + $lockData['hash'], + 'composer.lock file is not up to date (composer.json file was modified)' + ); } } diff --git a/lib/internal/Magento/Framework/View/Element/Html/Calendar.php b/lib/internal/Magento/Framework/View/Element/Html/Calendar.php index 8bfa611466ac4..0c8187569cf28 100644 --- a/lib/internal/Magento/Framework/View/Element/Html/Calendar.php +++ b/lib/internal/Magento/Framework/View/Element/Html/Calendar.php @@ -78,14 +78,31 @@ protected function _toHtml() ] ); - // get months names + /** + * Month names in abbreviated format values was added to ICU Data tables + * starting ICU library version 52.1. For some OS, like CentOS, default + * installation version of ICU library is 50.1.2, which not contain + * 'abbreviated' key, and that may cause a PHP fatal error when passing + * as an argument of function 'iterator_to_array'. This issue affects + * locales like ja_JP, ko_KR etc. + * + * @see http://source.icu-project.org/repos/icu/tags/release-50-1-2/icu4c/source/data/locales/ja.txt + * @see http://source.icu-project.org/repos/icu/tags/release-52-1/icu4c/source/data/locales/ja.txt + * @var \ResourceBundle $monthsData + */ $monthsData = $localeData['calendar']['gregorian']['monthNames']; $this->assign( 'months', [ 'wide' => $this->encoder->encode(array_values(iterator_to_array($monthsData['format']['wide']))), 'abbreviated' => $this->encoder->encode( - array_values(iterator_to_array($monthsData['format']['abbreviated'])) + array_values( + iterator_to_array( + null !== $monthsData->get('format')->get('abbreviated') + ? $monthsData['format']['abbreviated'] + : $monthsData['format']['wide'] + ) + ) ), ] ); diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/CalendarTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/CalendarTest.php index d5a9adb80a84a..36e16499ca763 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/CalendarTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/CalendarTest.php @@ -5,49 +5,92 @@ */ namespace Magento\Framework\View\Test\Unit\Element\Html; +use Magento\Framework\Locale\ResolverInterface; +use Magento\Framework\Stdlib\DateTime\TimezoneInterface; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Framework\View\Element\Html\Calendar; +use Magento\Framework\View\Element\Template\Context; +use PHPUnit_Framework_MockObject_MockObject as MockObject; + +/** + * @see Calendar + */ class CalendarTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager + * @see MAGETWO-60828 + * @see Calendar::_toHtml + * + * @param string $locale + * @dataProvider localesDataProvider */ - protected $objectManagerHelper; - - /** @var \Magento\Framework\View\Element\Html\Calendar */ - protected $block; - - /** @var \Magento\Framework\View\Element\Template\Context */ - protected $context; + public function testToHtmlWithDifferentLocales($locale) + { + $calendarBlock = (new ObjectManager($this))->getObject( + Calendar::class, + [ + 'localeResolver' => $this->getLocalResolver($locale) + ] + ); - /** @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $localeDate; + $calendarBlock->toHtml(); + } - protected function setUp() + /** + * @return array + */ + public function localesDataProvider() { - $this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->localeDate = $this->getMockBuilder(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class) - ->getMock(); + return [ + ['en_US'], + ['ja_JP'], + ['ko_KR'], + ]; + } - /** @var \Magento\Framework\View\Element\Template\Context $context */ - $this->context = $this->objectManagerHelper->getObject( - \Magento\Framework\View\Element\Template\Context::class, + /** + * @see Calendar::getYearRange + */ + public function testGetYearRange() + { + $calendarBlock = (new ObjectManager($this))->getObject( + Calendar::class, [ - 'localeDate' => $this->localeDate, + 'context' => $this->getContext() ] ); - /** @var \Magento\Framework\View\Element\Html\Links $block */ - $this->block = $this->objectManagerHelper->getObject( - \Magento\Framework\View\Element\Html\Calendar::class, - ['context' => $this->context] + $testCurrentYear = (new \DateTime())->format('Y'); + $this->assertEquals( + (int) $testCurrentYear - 100 . ':' . ($testCurrentYear + 100), + $calendarBlock->getYearRange() ); } /** - * @test + * @param string $locale + * @return ResolverInterface|MockObject */ - public function testGetYearRange() + private function getLocalResolver($locale) { - $testCurrentYear = (new \DateTime())->format('Y'); - $this->assertEquals((int)$testCurrentYear - 100 . ':' . ($testCurrentYear + 100), $this->block->getYearRange()); + $localResolver = $this->getMockBuilder(ResolverInterface::class) + ->getMockForAbstractClass(); + $localResolver->method('getLocale')->willReturn($locale); + + return $localResolver; + } + + /** + * @return Context|Object + */ + private function getContext() + { + $localeDate = $this->getMockBuilder(TimezoneInterface::class) + ->getMockForAbstractClass(); + + return (new ObjectManager($this))->getObject( + Context::class, + ['localeDate' => $localeDate] + ); } }