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
8 
13 class DataTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $_scopeConfigMock;
19 
24 
28  protected $_helper;
29 
30  protected function setUp()
31  {
32  $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
33  $className = \Magento\GoogleOptimizer\Helper\Data::class;
34  $arguments = $objectManagerHelper->getConstructArguments($className);
36  $context = $arguments['context'];
37  $this->_scopeConfigMock = $context->getScopeConfig();
38  $this->_googleAnalyticsHelperMock = $arguments['analyticsHelper'];
39  $this->_helper = $objectManagerHelper->getObject($className, $arguments);
40  }
41 
46  public function testGoogleExperimentIsEnabled($isExperimentsEnabled)
47  {
48  $store = 1;
49  $this->_scopeConfigMock->expects(
50  $this->once()
51  )->method(
52  'isSetFlag'
53  )->with(
54  \Magento\GoogleOptimizer\Helper\Data::XML_PATH_ENABLED,
55  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
56  $store
57  )->will(
58  $this->returnValue($isExperimentsEnabled)
59  );
60 
61  $this->assertEquals($isExperimentsEnabled, $this->_helper->isGoogleExperimentEnabled($store));
62  }
63 
67  public function dataProviderBoolValues()
68  {
69  return [[true], [false]];
70  }
71 
78  public function testGoogleExperimentIsActive($isExperimentsEnabled, $isAnalyticsAvailable, $result)
79  {
80  $store = 1;
81  $this->_scopeConfigMock->expects(
82  $this->once()
83  )->method(
84  'isSetFlag'
85  )->with(
86  \Magento\GoogleOptimizer\Helper\Data::XML_PATH_ENABLED,
87  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
88  $store
89  )->will(
90  $this->returnValue($isExperimentsEnabled)
91  );
92 
93  $this->_googleAnalyticsHelperMock->expects(
94  $this->any()
95  )->method(
96  'isGoogleAnalyticsAvailable'
97  )->with(
98  $store
99  )->will(
100  $this->returnValue($isAnalyticsAvailable)
101  );
102 
103  $this->assertEquals($result, $this->_helper->isGoogleExperimentActive($store));
104  }
105 
110  {
111  return [
112  [true, true, true],
113  [false, true, false],
114  [false, false, false],
115  [true, false, false]
116  ];
117  }
118 }
testGoogleExperimentIsEnabled($isExperimentsEnabled)
Definition: DataTest.php:46
testGoogleExperimentIsActive($isExperimentsEnabled, $isAnalyticsAvailable, $result)
Definition: DataTest.php:78
$arguments
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31