Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataTest.php
Go to the documentation of this file.
1 <?php
7 
8 class DataTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $helper;
14 
18  protected $scopeConfigMock;
19 
23  protected $remoteAddressMock;
24 
28  protected $httpHeaderMock;
29 
30  protected function setUp()
31  {
32  $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
33  $className = \Magento\Developer\Helper\Data::class;
34  $arguments = $objectManagerHelper->getConstructArguments($className);
36  $context = $arguments['context'];
37  $this->scopeConfigMock = $context->getScopeConfig();
38  $this->remoteAddressMock = $context->getRemoteAddress();
39  $this->httpHeaderMock = $context->getHttpHeader();
40  $this->helper = $objectManagerHelper->getObject($className, $arguments);
41  }
42 
48  public function testIsDevAllowed($allowedIps, $expected, $callNum = 1)
49  {
50  $storeId = 'storeId';
51 
52  $this->scopeConfigMock->expects($this->once())
53  ->method('getValue')
54  ->with(
55  \Magento\Developer\Helper\Data::XML_PATH_DEV_ALLOW_IPS,
56  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
57  $storeId
58  )->will($this->returnValue($allowedIps));
59 
60  $this->remoteAddressMock->expects($this->once())
61  ->method('getRemoteAddress')
62  ->will($this->returnValue('remoteAddress'));
63 
64  $this->httpHeaderMock->expects($this->exactly($callNum))
65  ->method('getHttpHost')
66  ->will($this->returnValue('httpHost'));
67 
68  $this->assertEquals($expected, $this->helper->isDevAllowed($storeId));
69  }
70 
74  public function isDevAllowedDataProvider()
75  {
76  return [
77  'allow_nothing' => [
78  '',
79  true,
80  0,
81  ],
82  'allow_remote_address' => [
83  'ip1, ip2, remoteAddress',
84  true,
85  0,
86  ],
87  'allow_http_host' => [
88  'ip1, ip2, httpHost',
89  true,
90  ],
91  'allow_neither' => [
92  'ip1, ip2, ip3',
93  false,
94  ],
95  ];
96  }
97 }
$arguments
testIsDevAllowed($allowedIps, $expected, $callNum=1)
Definition: DataTest.php:48
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31