Skip to content

Commit 3cc3279

Browse files
ENGCOM-6495: [GoogleAnalytics] covered Helper Data by Unit Test #26068
2 parents de3a2de + df22ab2 commit 3cc3279

File tree

1 file changed

+120
-0
lines changed
  • app/code/Magento/GoogleAnalytics/Test/Unit/Helper

1 file changed

+120
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Magento\GoogleAnalytics\Test\Unit\Helper;
11+
12+
use Magento\GoogleAnalytics\Helper\Data as HelperData;
13+
use Magento\Framework\App\Config\ScopeConfigInterface;
14+
use Magento\Store\Model\ScopeInterface;
15+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
16+
use PHPUnit\Framework\TestCase;
17+
use PHPUnit\Framework\MockObject\MockObject;
18+
19+
/**
20+
* Unit test for Magento\GoogleAnalytics\Helper\Data
21+
*/
22+
class DataTest extends TestCase
23+
{
24+
/**
25+
* @var HelperData
26+
*/
27+
private $helper;
28+
29+
/**
30+
* @var ScopeConfigInterface|MockObject
31+
*/
32+
private $scopeConfigMock;
33+
34+
/**
35+
* @inheritDoc
36+
*/
37+
protected function setUp(): void
38+
{
39+
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
40+
->setMethods(['getValue', 'isSetFlag'])
41+
->disableOriginalConstructor()
42+
->getMockForAbstractClass();
43+
44+
$objectManager = new ObjectManager($this);
45+
$this->helper = $objectManager->getObject(
46+
HelperData::class,
47+
[
48+
'scopeConfig' => $this->scopeConfigMock
49+
]
50+
);
51+
}
52+
53+
/**
54+
* Test for isGoogleAnalyticsAvailable()
55+
*
56+
* @param string $value
57+
* @param bool $flag
58+
* @param bool $result
59+
* @return void
60+
* @dataProvider gaDataProvider
61+
*/
62+
public function testIsGoogleAnalyticsAvailable($value, $flag, $result): void
63+
{
64+
$this->scopeConfigMock->expects($this->once())
65+
->method('getValue')
66+
->with(HelperData::XML_PATH_ACCOUNT, ScopeInterface::SCOPE_STORE)
67+
->willReturn($value);
68+
69+
$this->scopeConfigMock->expects($this->any())
70+
->method('isSetFlag')
71+
->with(HelperData::XML_PATH_ACTIVE, ScopeInterface::SCOPE_STORE)
72+
->willReturn($flag);
73+
74+
$this->assertEquals($result, $this->helper->isGoogleAnalyticsAvailable());
75+
}
76+
77+
/**
78+
* Data provider for isGoogleAnalyticsAvailable()
79+
*
80+
* @return array
81+
*/
82+
public function gaDataProvider(): array
83+
{
84+
return [
85+
['GA-XXXX', true, true],
86+
['GA-XXXX', false, false],
87+
['', true, false]
88+
];
89+
}
90+
91+
/**
92+
* Test for isAnonymizedIpActive()
93+
*
94+
* @param string $value
95+
* @param bool $result
96+
* @return void
97+
* @dataProvider yesNoDataProvider
98+
*/
99+
public function testIsAnonymizedIpActive($value, $result): void
100+
{
101+
$this->scopeConfigMock->expects($this->once())
102+
->method('getValue')
103+
->with(HelperData::XML_PATH_ANONYMIZE, ScopeInterface::SCOPE_STORE)
104+
->willReturn($value);
105+
$this->assertEquals($result, $this->helper->isAnonymizedIpActive());
106+
}
107+
108+
/**
109+
* Data provider for isAnonymizedIpActive()
110+
*
111+
* @return array
112+
*/
113+
public function yesNoDataProvider(): array
114+
{
115+
return [
116+
['Yes' => '1', 'result' => true],
117+
['No' => '0', 'result' => false]
118+
];
119+
}
120+
}

0 commit comments

Comments
 (0)