Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfigTest.php
Go to the documentation of this file.
1 <?php
7 
10 
11 class ConfigTest extends \PHPUnit\Framework\TestCase
12 {
16  private $model;
17 
21  private $scopeConfig;
22 
26  private $directoryHelper;
27 
31  private $storeManager;
32 
36  private $ccTypeFactory;
37 
41  private $certFactory;
42 
43  protected function setUp()
44  {
45  $this->scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
46 
47  $this->directoryHelper = $this->getMockBuilder(\Magento\Directory\Helper\Data::class)
48  ->disableOriginalConstructor()
49  ->getMock();
50 
51  $this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
52 
53  $this->ccTypeFactory = $this->getMockBuilder(\Magento\Payment\Model\Source\CctypeFactory::class)
54  ->disableOriginalConstructor()
55  ->getMock();
56 
57  $this->certFactory = $this->getMockBuilder(\Magento\Paypal\Model\CertFactory::class)
58  ->disableOriginalConstructor()
59  ->getMock();
60 
61  $this->model = new Config(
62  $this->scopeConfig,
63  $this->directoryHelper,
64  $this->storeManager,
65  $this->ccTypeFactory,
66  $this->certFactory
67  );
68  }
69 
70  public function testGetCountryMethods()
71  {
72  $this->assertNotContains('payflow_direct', $this->model->getCountryMethods('GB'));
73  $this->assertContains(Config::METHOD_WPP_PE_EXPRESS, $this->model->getCountryMethods('CA'));
74  $this->assertNotContains(Config::METHOD_WPP_PE_EXPRESS, $this->model->getCountryMethods('GB'));
75  $this->assertContains(Config::METHOD_WPP_PE_EXPRESS, $this->model->getCountryMethods('CA'));
76  $this->assertContains(Config::METHOD_WPP_EXPRESS, $this->model->getCountryMethods('DE'));
77  $this->assertContains(Config::METHOD_BILLING_AGREEMENT, $this->model->getCountryMethods('DE'));
78  $this->assertNotContains(Config::METHOD_WPP_PE_BML, $this->model->getCountryMethods('other'));
79  $this->assertNotContains(Config::METHOD_WPP_BML, $this->model->getCountryMethods('other'));
80  $this->assertNotContains(Config::METHOD_WPP_PE_BML, $this->model->getCountryMethods('CA'));
81  $this->assertNotContains(Config::METHOD_WPP_BML, $this->model->getCountryMethods('CA'));
82  $this->assertNotContains(Config::METHOD_WPP_PE_BML, $this->model->getCountryMethods('GB'));
83  $this->assertNotContains(Config::METHOD_WPP_BML, $this->model->getCountryMethods('GB'));
84  $this->assertNotContains(Config::METHOD_WPP_PE_BML, $this->model->getCountryMethods('AU'));
85  $this->assertNotContains(Config::METHOD_WPP_BML, $this->model->getCountryMethods('AU'));
86  $this->assertNotContains(Config::METHOD_WPP_PE_BML, $this->model->getCountryMethods('NZ'));
87  $this->assertNotContains(Config::METHOD_WPP_BML, $this->model->getCountryMethods('NZ'));
88  $this->assertNotContains(Config::METHOD_WPP_PE_BML, $this->model->getCountryMethods('JP'));
89  $this->assertNotContains(Config::METHOD_WPP_BML, $this->model->getCountryMethods('JP'));
90  $this->assertNotContains(Config::METHOD_WPP_PE_BML, $this->model->getCountryMethods('FR'));
91  $this->assertNotContains(Config::METHOD_WPP_BML, $this->model->getCountryMethods('FR'));
92  $this->assertNotContains(Config::METHOD_WPP_PE_BML, $this->model->getCountryMethods('IT'));
93  $this->assertNotContains(Config::METHOD_WPP_BML, $this->model->getCountryMethods('IT'));
94  $this->assertNotContains(Config::METHOD_WPP_PE_BML, $this->model->getCountryMethods('ES'));
95  $this->assertNotContains(Config::METHOD_WPP_BML, $this->model->getCountryMethods('ES'));
96  $this->assertNotContains(Config::METHOD_WPP_PE_BML, $this->model->getCountryMethods('HK'));
97  $this->assertNotContains(Config::METHOD_WPP_BML, $this->model->getCountryMethods('HK'));
98  $this->assertNotContains(Config::METHOD_WPP_PE_BML, $this->model->getCountryMethods('DE'));
99  $this->assertNotContains(Config::METHOD_WPP_BML, $this->model->getCountryMethods('DE'));
100  }
101 
102  public function testIsMethodActive()
103  {
104  $this->assertFalse($this->model->isMethodActive('payflow_direct'));
105  }
106 
110  public function testIsMethodAvailableWPPPE()
111  {
112  $this->assertFalse($this->model->isMethodAvailable('payflow_direct'));
113  }
114 
118  public function testIsMethodAvailableForIsMethodActive($methodName, $expected)
119  {
120  $this->scopeConfig->expects($this->any())
121  ->method('getValue')
122  ->with('paypal/general/merchant_country')
123  ->will($this->returnValue('US'));
124  $this->scopeConfig->expects($this->exactly(2))
125  ->method('isSetFlag')
126  ->withAnyParameters()
127  ->will($this->returnValue(true));
128 
129  $this->model->setMethod($methodName);
130  $this->assertEquals($expected, $this->model->isMethodAvailable($methodName));
131  }
132 
134  {
135  $this->scopeConfig->expects(static::once())
136  ->method('getValue')
137  ->with(
138  'paypal/general/merchant_country',
140  null
141  )->willReturn('US');
142 
143  $this->directoryHelper->expects(static::never())
144  ->method('getDefaultCountry');
145 
146  static::assertEquals('US', $this->model->getMerchantCountry());
147  }
148 
150  {
151  $this->scopeConfig->expects(static::once())
152  ->method('getValue')
153  ->with(
154  'paypal/general/merchant_country',
156  null
157  )->willReturn(null);
158 
159  $this->directoryHelper->expects(static::once())
160  ->method('getDefaultCountry')
161  ->with(null)
162  ->willReturn('US');
163 
164  static::assertEquals('US', $this->model->getMerchantCountry());
165  }
166 
171  {
172  return [
174  [Config::METHOD_WPP_BML, true],
177  ];
178  }
179 
180  public function testIsCreditCardMethod()
181  {
182  $this->assertFalse($this->model->getIsCreditCardMethod('payflow_direct'));
183  }
184 
185  public function testGetSpecificConfigPath()
186  {
187  $this->model->setMethod('payflow_direct');
188  $this->assertNull($this->model->getValue('useccv'));
189  $this->assertNull($this->model->getValue('vendor'));
190 
191  // _mapBmlFieldset
192  $this->model->setMethod(Config::METHOD_WPP_BML);
193  $this->scopeConfig->expects($this->once())
194  ->method('getValue')
195  ->with('payment/' . Config::METHOD_WPP_EXPRESS . '/allow_ba_signup')
196  ->will($this->returnValue(1));
197  $this->assertEquals(1, $this->model->getValue('allow_ba_signup'));
198  }
199 
201  {
202  // _mapBmlPayflowFieldset
203  $this->model->setMethod(Config::METHOD_WPP_PE_BML);
204  $this->scopeConfig->expects($this->once())
205  ->method('getValue')
206  ->with('payment/' . Config::METHOD_WPP_PE_EXPRESS . '/allow_ba_signup')
207  ->will($this->returnValue(1));
208  $this->assertEquals(1, $this->model->getValue('allow_ba_signup'));
209  }
210 
212  {
213  // _mapWpukFieldset
214  $this->model->setMethod(Config::METHOD_PAYFLOWADVANCED);
215  $this->scopeConfig->expects($this->once())
216  ->method('getValue')
217  ->with('payment/' . Config::METHOD_PAYFLOWADVANCED . '/payment_action')
218  ->willReturn('Authorization');
219  $this->assertEquals('Authorization', $this->model->getValue('payment_action'));
220  }
221 
226  {
227  $this->scopeConfig->expects($this->once())
228  ->method('getValue')
229  ->with('payment/paypal_express/skip_order_review_step')
230  ->will($this->returnValue($value));
231  $this->assertEquals($url, $this->model->getPayPalBasicStartUrl('token'));
232  }
233 
238  {
239  return [
240  [true, 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=token&useraction=commit'],
241  [false, 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=token']
242  ];
243  }
244 
246  {
247  $url = 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&order_id=orderId';
248  $this->assertEquals($url, $this->model->getExpressCheckoutOrderUrl('orderId'));
249  }
250 
251  public function testGetBmlPublisherId()
252  {
253  $this->scopeConfig->expects($this->once())
254  ->method('getValue')
255  ->with('payment/' . Config::METHOD_WPP_BML . '/publisher_id')
256  ->will($this->returnValue('12345'));
257  $this->assertEquals('12345', $this->model->getBmlPublisherId());
258  }
259 
263  public function testGetBmlPosition($section, $expected)
264  {
265  $this->scopeConfig->expects($this->once())
266  ->method('getValue')
267  ->with('payment/' . Config::METHOD_WPP_BML . '/' . $section . '_position')
268  ->will($this->returnValue($expected));
269  $this->assertEquals($expected, $this->model->getBmlPosition($section));
270  }
271 
275  public function getBmlPositionDataProvider()
276  {
277  return [
278  ['head', 'left'],
279  ['checkout', 'top']
280  ];
281  }
282 
286  public function testGetBmlSize($section, $expected)
287  {
288  $this->scopeConfig->expects($this->once())
289  ->method('getValue')
290  ->with('payment/' . Config::METHOD_WPP_BML . '/' . $section . '_size')
291  ->will($this->returnValue($expected));
292  $this->assertEquals($expected, $this->model->getBmlSize($section));
293  }
294 
298  public function getBmlSizeDataProvider()
299  {
300  return [
301  ['head', '125x75'],
302  ['checkout', ['50x50']]
303  ];
304  }
305 
309  public function testGetBmlDisplay($section, $expectedValue, $expectedFlag, $expected)
310  {
311  $this->model->setStoreId(1);
312  $this->directoryHelper->expects($this->any())
313  ->method('getDefaultCountry')
314  ->with(1)
315  ->will($this->returnValue('US'));
316  $this->scopeConfig->expects($this->any())
317  ->method('isSetFlag')
318  ->will($this->returnValue($expectedFlag));
319  $this->scopeConfig->expects($this->any())
320  ->method('getValue')
321  ->will($this->returnValueMap([
322  ['payment/' . Config::METHOD_WPP_BML . '/' . $section . '_display', 'store', 1, $expectedValue],
323  ['payment/' . Config::METHOD_WPP_BML . '/active', 'store', 1, $expectedValue],
324  ['payment/' . Config::METHOD_WPP_PE_BML . '/active', 'store', 1, $expectedValue],
325  ]));
326  $this->assertEquals($expected, $this->model->getBmlDisplay($section));
327  }
328 
332  public function dataProviderGetBmlDisplay()
333  {
334  return [
335  ['head', true, true, true],
336  ['head', true, false, false],
337  ['head', false, true, false],
338  ['head', false, false, false],
339  ];
340  }
341 
353  $localeCode,
354  $orderTotal,
355  $pal,
356  $areButtonDynamic,
357  $sandboxFlag,
358  $buttonType,
359  $result
360  ) {
361  $this->model->setMethod(Config::METHOD_WPP_EXPRESS);
362  $this->model->setStoreId(123);
363 
364  $this->scopeConfig->expects($this->any())
365  ->method('getValue')
366  ->willReturnMap([
367  ['paypal/wpp/button_flavor', ScopeInterface::SCOPE_STORE, 123, $areButtonDynamic],
368  ['paypal/wpp/sandbox_flag', ScopeInterface::SCOPE_STORE, 123, $sandboxFlag],
369  ['paypal/wpp/button_type', ScopeInterface::SCOPE_STORE, 123, $buttonType],
370  ]);
371 
372  $this->assertEquals(
373  $result,
374  $this->model->getExpressCheckoutShortcutImageUrl($localeCode, $orderTotal, $pal)
375  );
376  }
377 
382  {
383  return [
384  [
386  'https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-medium.png'
387  ],
388  [
390  'https://fpdbs.sandbox.paypal.com/dynamicimageweb?cmd=_dynamic-image&buttontype=ecshortcut&locale=en_GB'
391  ],
392  [
393  'en_GB', null, null, Config::EC_FLAVOR_DYNAMIC, false, Config::EC_BUTTON_TYPE_SHORTCUT,
394  'https://fpdbs.paypal.com/dynamicimageweb?cmd=_dynamic-image&buttontype=ecshortcut&locale=en_GB'
395  ],
396  [
397  'en_US', null, null, Config::EC_FLAVOR_STATIC, false, Config::EC_BUTTON_TYPE_MARK,
398  'https://www.paypalobjects.com/webstatic/en_US/i/buttons/pp-acceptance-medium.png'
399  ],
400  [
401  'en_US', null, null, Config::EC_FLAVOR_STATIC, true, Config::EC_BUTTON_TYPE_SHORTCUT,
402  'https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-medium.png'],
403  [
404  'en_GB', null, null, Config::EC_FLAVOR_STATIC, true, Config::EC_BUTTON_TYPE_SHORTCUT,
405  'https://www.paypal.com/en_GB/i/btn/btn_xpressCheckout.gif'
406  ],
407  ];
408  }
409 
420  public function testGetPaymentMarkImageUrl(
421  $localeCode,
422  $orderTotal,
423  $pal,
424  $staticSize,
425  $areButtonDynamic,
426  $sandboxFlag,
427  $result
428  ) {
429  $this->model->setMethod(Config::METHOD_WPP_EXPRESS);
430  $this->model->setStoreId(123);
431 
432  $this->scopeConfig->expects($this->any())
433  ->method('getValue')
434  ->willReturnMap([
435  ['paypal/wpp/button_flavor', ScopeInterface::SCOPE_STORE, 123, $areButtonDynamic],
436  ['paypal/wpp/sandbox_flag', ScopeInterface::SCOPE_STORE, 123, $sandboxFlag],
437  ]);
438 
439  $this->assertEquals(
440  $result,
441  $this->model->getPaymentMarkImageUrl($localeCode, $orderTotal, $pal, $staticSize)
442  );
443  }
444 
449  {
450  return [
451  [
452  'en_US', null, null, 'small', Config::EC_FLAVOR_DYNAMIC, true,
453  'https://www.paypalobjects.com/webstatic/en_US/i/buttons/ppcredit-logo-medium.png'
454  ],
455  [
456  'en_GB', null, null, 'small', Config::EC_FLAVOR_DYNAMIC, true,
457  'https://fpdbs.sandbox.paypal.com/dynamicimageweb?cmd=_dynamic-image&buttontype=ecmark&locale=en_GB'
458  ],
459  [
460  'en_GB', null, null, 'small', Config::EC_FLAVOR_DYNAMIC, false,
461  'https://fpdbs.paypal.com/dynamicimageweb?cmd=_dynamic-image&buttontype=ecmark&locale=en_GB'
462  ],
463  [
464  'en_US', null, null, 'medium', Config::EC_FLAVOR_STATIC, true,
465  'https://www.paypalobjects.com/webstatic/en_US/i/buttons/pp-acceptance-medium.png'
466  ],
467  [
468  'en_US', null, null, 'medium', Config::EC_FLAVOR_STATIC, true,
469  'https://www.paypalobjects.com/webstatic/en_US/i/buttons/pp-acceptance-medium.png'
470  ],
471  [
472  'en_US', null, null, 'large', Config::EC_FLAVOR_STATIC, true,
473  'https://www.paypalobjects.com/webstatic/en_US/i/buttons/pp-acceptance-large.png'
474  ],
475  [
476  'en_GB', null, null, 'affected', Config::EC_FLAVOR_STATIC, true,
477  'https://www.paypalobjects.com/webstatic/en_US/i/buttons/pp-acceptance-medium.png'
478  ],
479  ];
480  }
481 }
testGetBmlDisplay($section, $expectedValue, $expectedFlag, $expected)
Definition: ConfigTest.php:309
testGetPaymentMarkImageUrl( $localeCode, $orderTotal, $pal, $staticSize, $areButtonDynamic, $sandboxFlag, $result)
Definition: ConfigTest.php:420
$value
Definition: gender.phtml:16
testIsMethodAvailableForIsMethodActive($methodName, $expected)
Definition: ConfigTest.php:118
testGetExpressCheckoutShortcutImageUrl( $localeCode, $orderTotal, $pal, $areButtonDynamic, $sandboxFlag, $buttonType, $result)
Definition: ConfigTest.php:352