9 use \Magento\Payment\Helper\Data;
13 class DataTest extends \PHPUnit\Framework\TestCase
22 private $initialConfig;
25 private $methodFactory;
35 private $appEmulation;
37 protected function setUp()
39 $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
40 $className = \Magento\Payment\Helper\Data::class;
44 $this->scopeConfig = $context->getScopeConfig();
45 $this->layoutMock = $this->createMock(\
Magento\Framework\View\LayoutInterface::class);
46 $layoutFactoryMock =
$arguments[
'layoutFactory'];
47 $layoutFactoryMock->expects($this->once())->method(
'create')->willReturn($this->layoutMock);
49 $this->methodFactory =
$arguments[
'paymentMethodFactory'];
50 $this->appEmulation =
$arguments[
'appEmulation'];
51 $this->initialConfig =
$arguments[
'initialConfig'];
58 list(
$code,
$class, $methodInstance) = [
'method_code',
'method_class',
'method_instance'];
60 $this->scopeConfig->expects(
69 $this->methodFactory->expects(
81 $this->assertEquals($methodInstance, $this->helper->getMethodInstance(
$code));
89 $this->scopeConfig->expects($this->once())
93 $this->helper->getMethodInstance(
'code');
104 $this->initialConfig->expects($this->once())
110 $methodA[
'code'] => $methodA[
'data'],
111 $methodB[
'code'] => $methodB[
'data'],
122 ->will($this->returnValue(\
Magento\Payment\Model\Method\AbstractMethod::class));
128 ->will($this->returnValue(\
Magento\Payment\Model\Method\AbstractMethod::class));
132 ->will($this->returnValue(
null));
134 $methodInstanceMockA = $this->getMockBuilder(\
Magento\Payment\Model\MethodInterface::class)
135 ->getMockForAbstractClass();
136 $methodInstanceMockA->expects($this->any())
137 ->method(
'isAvailable')
138 ->will($this->returnValue(
true));
139 $methodInstanceMockA->expects($this->any())
140 ->method(
'getConfigData')
141 ->with(
'sort_order',
null)
142 ->will($this->returnValue($methodA[
'data'][
'sort_order']));
144 $methodInstanceMockB = $this->getMockBuilder(\
Magento\Payment\Model\MethodInterface::class)
145 ->getMockForAbstractClass();
146 $methodInstanceMockB->expects($this->any())
147 ->method(
'isAvailable')
148 ->will($this->returnValue(
true));
149 $methodInstanceMockB->expects($this->any())
150 ->method(
'getConfigData')
151 ->with(
'sort_order',
null)
152 ->will($this->returnValue($methodB[
'data'][
'sort_order']));
154 $this->methodFactory->expects($this->at(0))
156 ->will($this->returnValue($methodInstanceMockA));
158 $this->methodFactory->expects($this->at(1))
160 ->will($this->returnValue($methodInstanceMockB));
162 $sortedMethods = $this->helper->getStoreMethods();
164 array_shift($sortedMethods)->getConfigData(
'sort_order')
165 < array_shift($sortedMethods)->getConfigData(
'sort_order')
171 list($blockType,
$methodCode) = [
'method_block_type',
'method_code'];
173 $methodMock = $this->getMockBuilder(\
Magento\Payment\Model\MethodInterface::class)
174 ->getMockForAbstractClass();
175 $layoutMock = $this->getMockBuilder(\
Magento\Framework\View\LayoutInterface::class)
176 ->disableOriginalConstructor()
179 $blockMock = $this->getMockBuilder(\
Magento\Framework\View\Element\BlockInterface::class)
180 ->disableOriginalConstructor()
181 ->setMethods([
'setMethod',
'toHtml'])
184 $methodMock->expects($this->once())->method(
'getFormBlockType')->willReturn($blockType);
185 $methodMock->expects($this->once())->method(
'getCode')->willReturn(
$methodCode);
186 $layoutMock->expects($this->once())->method(
'createBlock')
188 ->willReturn($blockMock);
189 $blockMock->expects($this->once())->method(
'setMethod')->with($methodMock);
191 $this->assertSame($blockMock, $this->helper->getMethodFormBlock($methodMock, $layoutMock));
196 $blockType =
'method_block_type';
198 $methodMock = $this->getMockBuilder(\
Magento\Payment\Model\MethodInterface::class)
199 ->getMockForAbstractClass();
200 $infoMock = $this->getMockBuilder(\
Magento\Payment\Model\Info::class)
201 ->disableOriginalConstructor()
204 $blockMock = $this->getMockBuilder(\
Magento\Framework\View\Element\BlockInterface::class)
205 ->disableOriginalConstructor()
206 ->setMethods([
'setInfo',
'toHtml'])
209 $infoMock->expects($this->once())->method(
'getMethodInstance')->willReturn($methodMock);
210 $methodMock->expects($this->once())->method(
'getInfoBlockType')->willReturn($blockType);
211 $this->layoutMock->expects($this->once())->method(
'createBlock')
213 ->willReturn($blockMock);
214 $blockMock->expects($this->once())->method(
'setInfo')->with($infoMock);
216 $this->assertSame($blockMock, $this->helper->getInfoBlock($infoMock));
221 list(
$storeId, $blockHtml, $secureMode, $blockType) = [1,
'HTML MARKUP',
true,
'method_block_type'];
223 $methodMock = $this->getMockBuilder(\
Magento\Payment\Model\MethodInterface::class)
224 ->getMockForAbstractClass();
225 $infoMock = $this->getMockBuilder(\
Magento\Payment\Model\Info::class)
226 ->disableOriginalConstructor()
229 $paymentBlockMock = $this->getMockBuilder(\
Magento\Framework\View\Element\BlockInterface::class)
230 ->disableOriginalConstructor()
231 ->setMethods([
'setArea',
'setIsSecureMode',
'getMethod',
'setStore',
'toHtml',
'setInfo'])
234 $this->appEmulation->expects($this->once())->method(
'startEnvironmentEmulation')->with(
$storeId);
235 $infoMock->expects($this->once())->method(
'getMethodInstance')->willReturn($methodMock);
236 $methodMock->expects($this->once())->method(
'getInfoBlockType')->willReturn($blockType);
237 $this->layoutMock->expects($this->once())->method(
'createBlock')
239 ->willReturn($paymentBlockMock);
240 $paymentBlockMock->expects($this->once())->method(
'setInfo')->with($infoMock);
241 $paymentBlockMock->expects($this->once())->method(
'setArea')
242 ->with(\
Magento\Framework\
App\Area::AREA_FRONTEND)
244 $paymentBlockMock->expects($this->once())->method(
'setIsSecureMode')
246 $paymentBlockMock->expects($this->once())->method(
'getMethod')
247 ->willReturn($methodMock);
248 $methodMock->expects($this->once())->method(
'setStore')->with(
$storeId);
249 $paymentBlockMock->expects($this->once())->method(
'toHtml')
250 ->willReturn($blockHtml);
251 $this->appEmulation->expects($this->once())->method(
'stopEnvironmentEmulation');
253 $this->assertEquals($blockHtml, $this->helper->getInfoBlockHtml($infoMock,
$storeId));
263 [
'code' =>
'methodA',
'data' => [
'sort_order' => 0]],
264 [
'code' =>
'methodB',
'data' => [
'sort_order' => 1]]
267 [
'code' =>
'methodA',
'data' => [
'sort_order' => 2]],
268 [
'code' =>
'methodB',
'data' => [
'sort_order' => 1]],
testSortMethods(array $methodA, array $methodB)
$_option $_optionId $class
const XML_PATH_PAYMENT_METHODS
testGetMethodInstanceWithException()
getSortMethodsDataProvider()