Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FieldPluginTest.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Paypal\Model\Config\Structure\Element\FieldPlugin as FieldConfigStructurePlugin;
11 use Magento\Config\Model\Config\Structure\Element\Field as FieldConfigStructureMock;
12 
13 class FieldPluginTest extends \PHPUnit\Framework\TestCase
14 {
18  private $plugin;
19 
23  private $objectManagerHelper;
24 
28  private $requestMock;
29 
33  private $subjectMock;
34 
35  protected function setUp()
36  {
37  $this->requestMock = $this->getMockBuilder(RequestInterface::class)
38  ->getMockForAbstractClass();
39  $this->subjectMock = $this->getMockBuilder(FieldConfigStructureMock::class)
40  ->disableOriginalConstructor()
41  ->getMock();
42 
43  $this->objectManagerHelper = new ObjectManagerHelper($this);
44  $this->plugin = $this->objectManagerHelper->getObject(
45  FieldConfigStructurePlugin::class,
46  ['request' => $this->requestMock]
47  );
48  }
49 
51  {
52  $someResult = 'some result';
53 
54  $this->assertEquals($someResult, $this->plugin->afterGetConfigPath($this->subjectMock, $someResult));
55  }
56 
58  {
59  $this->requestMock->expects(static::once())
60  ->method('getParam')
61  ->with('section')
62  ->willReturn('non-payment');
63 
64  $this->assertNull($this->plugin->afterGetConfigPath($this->subjectMock, null));
65  }
66 
73  public function testAroundGetConfigPath($subjectPath, $expectedConfigPath)
74  {
75  $this->requestMock->expects(static::once())
76  ->method('getParam')
77  ->with('section')
78  ->willReturn('payment');
79  $this->subjectMock->expects(static::once())
80  ->method('getPath')
81  ->willReturn($subjectPath);
82 
83  $this->assertEquals($expectedConfigPath, $this->plugin->afterGetConfigPath($this->subjectMock, null));
84  }
85 
90  {
91  return [
92  ['payment_us/group/field', 'payment/group/field'],
93  ['payment_other/group/field', 'payment/group/field'],
94  ['payment_us', 'payment_us'],
95  ['payment_wrong_country/group/field', 'payment_wrong_country/group/field']
96  ];
97  }
98 }