-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1189 from magento-mpi/MPI-PR206
MPI-PR206-2
- Loading branch information
Showing
16 changed files
with
505 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Braintree\Model; | ||
|
||
use Magento\Framework\Locale\ResolverInterface; | ||
use Magento\Braintree\Gateway\Config\PayPal\Config; | ||
|
||
class LocaleResolver implements ResolverInterface | ||
{ | ||
/** | ||
* @var ResolverInterface | ||
*/ | ||
private $resolver; | ||
|
||
/** | ||
* @var Config | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* @param ResolverInterface $resolver | ||
* @param Config $config | ||
*/ | ||
public function __construct(ResolverInterface $resolver, Config $config) | ||
{ | ||
$this->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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
dev/tests/js/jasmine/tests/app/code/Magento/Braintree/frontend/js/paypal/button.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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('<button id="' + btnId + '"></button>')[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); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.