ReaderTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Test\Unit\Model\Config\Rules;
  7. use Magento\Framework\Config\FileResolverInterface;
  8. use Magento\Framework\Config\SchemaLocatorInterface;
  9. use Magento\Framework\Config\ValidationStateInterface;
  10. use Magento\Paypal\Helper\Backend;
  11. use Magento\Paypal\Model\Config\Rules\Converter;
  12. use Magento\Paypal\Model\Config\Rules\Reader;
  13. class ReaderTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /** @var Reader */
  16. protected $reader;
  17. /** @var FileResolverInterface|\PHPUnit_Framework_MockObject_MockObject */
  18. protected $fileResolver;
  19. /** @var Converter|\PHPUnit_Framework_MockObject_MockObject */
  20. protected $converter;
  21. /** @var SchemaLocatorInterface|\PHPUnit_Framework_MockObject_MockObject */
  22. protected $schemaLocator;
  23. /** @var ValidationStateInterface|\PHPUnit_Framework_MockObject_MockObject */
  24. protected $validationState;
  25. /** @var Backend|\PHPUnit_Framework_MockObject_MockObject */
  26. protected $helper;
  27. /**
  28. * Set up
  29. *
  30. * @return void
  31. */
  32. protected function setUp()
  33. {
  34. $this->fileResolver = $this->getMockForAbstractClass(
  35. \Magento\Framework\Config\FileResolverInterface::class
  36. );
  37. $this->converter = $this->createMock(\Magento\Paypal\Model\Config\Rules\Converter::class);
  38. $this->schemaLocator = $this->getMockForAbstractClass(
  39. \Magento\Framework\Config\SchemaLocatorInterface::class
  40. );
  41. $this->validationState = $this->getMockForAbstractClass(
  42. \Magento\Framework\Config\ValidationStateInterface::class
  43. );
  44. $this->helper = $this->createMock(\Magento\Paypal\Helper\Backend::class);
  45. }
  46. /**
  47. * @param string $countryCode
  48. * @param string $xml
  49. * @param string $expected
  50. * @dataProvider dataProviderReadExistingCountryConfig
  51. */
  52. public function testReadExistingCountryConfig($countryCode, $xml, $expected)
  53. {
  54. $this->helper->expects($this->once())
  55. ->method('getConfigurationCountryCode')
  56. ->willReturn($countryCode);
  57. $this->fileResolver->expects($this->once())
  58. ->method('get')
  59. ->with($this->equalTo($expected))
  60. ->willReturn($xml);
  61. $this->reader = new \Magento\Paypal\Model\Config\Rules\Reader(
  62. $this->fileResolver,
  63. $this->converter,
  64. $this->schemaLocator,
  65. $this->validationState,
  66. $this->helper
  67. );
  68. $this->reader->read();
  69. }
  70. /**
  71. * @param string $countryCode
  72. * @param string $xml
  73. * @param string $expected
  74. * @dataProvider dataProviderReadOtherCountryConfig
  75. */
  76. public function testReadOtherCountryConfig($countryCode, $xml, $expected)
  77. {
  78. $this->helper->expects($this->once())
  79. ->method('getConfigurationCountryCode')
  80. ->willReturn($countryCode);
  81. $this->fileResolver->expects($this->at(0))
  82. ->method('get')
  83. ->willReturn([]);
  84. $this->fileResolver->expects($this->at(1))
  85. ->method('get')
  86. ->with($this->equalTo($expected))
  87. ->willReturn($xml);
  88. $this->reader = new Reader(
  89. $this->fileResolver,
  90. $this->converter,
  91. $this->schemaLocator,
  92. $this->validationState,
  93. $this->helper
  94. );
  95. $this->reader->read();
  96. }
  97. /**
  98. * @return array
  99. */
  100. public function dataProviderReadExistingCountryConfig()
  101. {
  102. return [
  103. ['us', ['<payment/>'], 'adminhtml/rules/payment_us.xml'],
  104. ['ca', ['<payment/>'], 'adminhtml/rules/payment_ca.xml'],
  105. ['au', ['<payment/>'], 'adminhtml/rules/payment_au.xml'],
  106. ['gb', ['<payment/>'], 'adminhtml/rules/payment_gb.xml'],
  107. ['jp', ['<payment/>'], 'adminhtml/rules/payment_jp.xml'],
  108. ['fr', ['<payment/>'], 'adminhtml/rules/payment_fr.xml'],
  109. ['it', ['<payment/>'], 'adminhtml/rules/payment_it.xml'],
  110. ['es', ['<payment/>'], 'adminhtml/rules/payment_es.xml'],
  111. ['hk', ['<payment/>'], 'adminhtml/rules/payment_hk.xml'],
  112. ['nz', ['<payment/>'], 'adminhtml/rules/payment_nz.xml'],
  113. ['de', ['<payment/>'], 'adminhtml/rules/payment_de.xml'],
  114. ];
  115. }
  116. /**
  117. * @return array
  118. */
  119. public function dataProviderReadOtherCountryConfig()
  120. {
  121. return [
  122. ['no', ['<payment/>'], 'adminhtml/rules/payment_other.xml'],
  123. ];
  124. }
  125. }