Skip to content

Commit 7391d9a

Browse files
committed
MAGE-1066 Add unit test
1 parent e581624 commit 7391d9a

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

Test/Unit/ConfigHelperTest.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Test\Unit;
4+
5+
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
6+
use Magento\Cookie\Helper\Cookie as CookieHelper;
7+
use Magento\Customer\Api\GroupExcludedWebsiteRepositoryInterface;
8+
use Magento\Customer\Model\ResourceModel\Group\Collection as GroupCollection;
9+
use Magento\Directory\Model\Currency as DirCurrency;
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\App\Config\Storage\WriterInterface;
12+
use Magento\Framework\App\Filesystem\DirectoryList;
13+
use Magento\Framework\App\ProductMetadataInterface;
14+
use Magento\Framework\Event\ManagerInterface;
15+
use Magento\Framework\Locale\Currency;
16+
use Magento\Framework\Module\ResourceInterface;
17+
use Magento\Framework\Serialize\SerializerInterface;
18+
use Magento\Store\Model\StoreManagerInterface;
19+
use PHPUnit\Framework\TestCase;
20+
21+
class ConfigHelperTest extends TestCase
22+
{
23+
protected ConfigHelper $configHelper;
24+
protected ScopeConfigInterface $configInterface;
25+
protected WriterInterface $configWriter;
26+
protected StoreManagerInterface $storeManager;
27+
protected Currency $currency;
28+
protected DirCurrency $dirCurrency;
29+
protected DirectoryList $directoryList;
30+
protected ResourceInterface $moduleResource;
31+
protected ProductMetadataInterface $productMetadata;
32+
protected ManagerInterface $eventManager;
33+
protected SerializerInterface $serializer;
34+
protected GroupCollection $groupCollection;
35+
protected GroupExcludedWebsiteRepositoryInterface $groupExcludedWebsiteRepository;
36+
protected CookieHelper $cookieHelper;
37+
38+
public function setUp(): void
39+
{
40+
$this->configInterface = $this->createMock(ScopeConfigInterface::class);
41+
$this->configWriter = $this->createMock(WriterInterface::class);
42+
$this->storeManager = $this->createMock(StoreManagerInterface::class);
43+
$this->currency = $this->createMock(Currency::class);
44+
$this->dirCurrency = $this->createMock(DirCurrency::class);
45+
$this->directoryList = $this->createMock(DirectoryList::class);
46+
$this->moduleResource = $this->createMock(ResourceInterface::class);
47+
$this->productMetadata = $this->createMock(ProductMetadataInterface::class);
48+
$this->eventManager = $this->createMock(ManagerInterface::class);
49+
$this->serializer = $this->createMock(SerializerInterface::class);
50+
$this->groupCollection = $this->createMock(GroupCollection::class);
51+
$this->groupExcludedWebsiteRepository = $this->createMock(GroupExcludedWebsiteRepositoryInterface::class);
52+
$this->cookieHelper = $this->createMock(CookieHelper::class);
53+
54+
$this->configHelper = new ConfigHelper(
55+
$this->configInterface,
56+
$this->configWriter,
57+
$this->storeManager,
58+
$this->currency,
59+
$this->dirCurrency,
60+
$this->directoryList,
61+
$this->moduleResource,
62+
$this->productMetadata,
63+
$this->eventManager,
64+
$this->serializer,
65+
$this->groupCollection,
66+
$this->groupExcludedWebsiteRepository,
67+
$this->cookieHelper
68+
);
69+
}
70+
71+
public function testGetIndexPrefix()
72+
{
73+
$testPrefix = 'foo_bar_';
74+
$this->configInterface->method('getValue')->willReturn($testPrefix);
75+
$this->assertEquals($testPrefix, $this->configHelper->getIndexPrefix());
76+
}
77+
78+
public function testGetIndexPrefixWhenNull() {
79+
$this->configInterface->method('getValue')->willReturn(null);
80+
$this->assertEquals('', $this->configHelper->getIndexPrefix());
81+
}
82+
}

0 commit comments

Comments
 (0)