Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StructurePluginTest.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Paypal\Model\Config\StructurePlugin as ConfigStructurePlugin;
10 use Magento\Config\Model\Config\ScopeDefiner as ConfigScopeDefiner;
11 use Magento\Paypal\Helper\Backend as BackendHelper;
13 use Magento\Config\Model\Config\Structure\ElementInterface as ElementConfigStructure;
14 
15 class StructurePluginTest extends \PHPUnit\Framework\TestCase
16 {
20  private $plugin;
21 
25  private $objectManagerHelper;
26 
30  private $configScopeDefinerMock;
31 
35  private $backendHelperMock;
36 
40  private $configStructureMock;
41 
45  private $elementConfigStructureMock;
46 
47  protected function setUp()
48  {
49  $this->configScopeDefinerMock = $this->getMockBuilder(ConfigScopeDefiner::class)
50  ->disableOriginalConstructor()
51  ->getMock();
52  $this->backendHelperMock = $this->getMockBuilder(BackendHelper::class)
53  ->disableOriginalConstructor()
54  ->getMock();
55  $this->configStructureMock = $this->getMockBuilder(ConfigStructure::class)
56  ->disableOriginalConstructor()
57  ->getMock();
58  $this->elementConfigStructureMock = $this->getMockBuilder(ElementConfigStructure::class)
59  ->getMockForAbstractClass();
60 
61  $this->objectManagerHelper = new ObjectManagerHelper($this);
62  $this->plugin = $this->objectManagerHelper->getObject(
63  ConfigStructurePlugin::class,
64  [
65  'scopeDefiner' => $this->configScopeDefinerMock,
66  'backendHelper' => $this->backendHelperMock
67  ]
68  );
69  }
70 
72  {
73  $countries = ConfigStructurePlugin::getPaypalConfigCountries(true);
74 
75  $this->assertContains('payment_us', $countries);
76  $this->assertContains('payment_other', $countries);
77  }
78 
79  public function testGetPaypalConfigCountries()
80  {
81  $countries = ConfigStructurePlugin::getPaypalConfigCountries(false);
82 
83  $this->assertContains('payment_us', $countries);
84  $this->assertNotContains('payment_other', $countries);
85  }
86 
93  public function testAroundGetElementByPathPartsNonPayment($pathParts, $returnResult)
94  {
95  $result = $returnResult ? $this->elementConfigStructureMock : null;
96  $proceed = function () use ($result) {
97  return $result;
98  };
99 
100  $this->assertSame(
101  $result,
102  $this->plugin->aroundGetElementByPathParts($this->configStructureMock, $proceed, $pathParts)
103  );
104  }
105 
110  {
111  return [
112  [['non-payment', 'group1', 'group2', 'field'], true],
113  [['non-payment'], true],
114  [['non-payment', 'group1', 'group2', 'field'], false],
115  [['non-payment'], false],
116  ];
117  }
118 
125  public function testAroundGetElementByPathPartsNoResult($pathParts, $countryCode)
126  {
127  $proceed = function () {
128  return null;
129  };
130 
131  $this->backendHelperMock->expects(static::once())
132  ->method('getConfigurationCountryCode')
133  ->willReturn($countryCode);
134 
135  $this->assertEquals(
136  null,
137  $this->plugin->aroundGetElementByPathParts($this->configStructureMock, $proceed, $pathParts)
138  );
139  }
140 
147  public function testAroundGetElementByPathParts($pathParts, $countryCode)
148  {
149  $result = $this->elementConfigStructureMock;
150  $proceed = function () use ($result) {
151  return $result;
152  };
153 
154  $this->backendHelperMock->expects(static::once())
155  ->method('getConfigurationCountryCode')
156  ->willReturn($countryCode);
157 
158  $this->assertSame(
159  $this->elementConfigStructureMock,
160  $this->plugin->aroundGetElementByPathParts($this->configStructureMock, $proceed, $pathParts)
161  );
162  }
163 
168  {
169  return [
170  [
171  ['payment', 'group1', 'group2', 'field'],
172  'any',
173  ],
174  [
175  ['payment', 'group1', 'group2', 'field'],
176  'DE',
177  ]
178  ];
179  }
180 }