Skip to content

Commit be81804

Browse files
committed
[GoogleAnalytics] covered Helper Data by Unit Test
1 parent c7a2450 commit be81804

File tree

1 file changed

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

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
* @return void
57+
* @dataProvider gaDataProvider
58+
*/
59+
public function testIsGoogleAnalyticsAvailable($value, $flag): void
60+
{
61+
$this->scopeConfigMock->expects($this->once())
62+
->method('getValue')
63+
->with(HelperData::XML_PATH_ACCOUNT, ScopeInterface::SCOPE_STORE)
64+
->willReturn($value);
65+
66+
$this->scopeConfigMock->expects($this->any())
67+
->method('isSetFlag')
68+
->with(HelperData::XML_PATH_ACTIVE, ScopeInterface::SCOPE_STORE)
69+
->willReturn($flag);
70+
71+
$this->assertEquals(($value && $flag), $this->helper->isGoogleAnalyticsAvailable());
72+
}
73+
74+
/**
75+
* Data provider for isGoogleAnalyticsAvailable()
76+
*
77+
* @return array
78+
*/
79+
public function gaDataProvider(): array
80+
{
81+
return [
82+
['GA-XXXX', true],
83+
['GA-XXXX', false],
84+
['', true]
85+
];
86+
}
87+
88+
/**
89+
* Test for isAnonymizedIpActive()
90+
*
91+
* @return void
92+
* @dataProvider yesNoDataProvider
93+
*/
94+
public function testIsAnonymizedIpActive($value): void
95+
{
96+
$this->scopeConfigMock->expects($this->once())
97+
->method('getValue')
98+
->with(HelperData::XML_PATH_ANONYMIZE, ScopeInterface::SCOPE_STORE)
99+
->willReturn($value);
100+
$this->assertEquals((bool) $value, $this->helper->isAnonymizedIpActive());
101+
}
102+
103+
/**
104+
* Data provider for isAnonymizedIpActive()
105+
*
106+
* @return array
107+
*/
108+
public function yesNoDataProvider(): array
109+
{
110+
return [
111+
['Yes' => '1'],
112+
['No' => '0']
113+
];
114+
}
115+
}

0 commit comments

Comments
 (0)