Skip to content

Commit bd7c119

Browse files
committed
[ADO-424] Adds phpunit for Meta_BusinessExtension module
1 parent a93ef9c commit bd7c119

23 files changed

+3984
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Meta\BusinessExtension\Test\Unit\Api;
6+
7+
use Meta\BusinessExtension\Model\Api\AdobeCloudConfig;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class AdobeCloudConfigTest extends TestCase
11+
{
12+
/**
13+
* @var AdobeCloudConfig
14+
*/
15+
private $adobeCloudConfig;
16+
17+
/**
18+
* Class setup function
19+
*
20+
* @return void
21+
*/
22+
protected function setUp(): void
23+
{
24+
parent::setUp();
25+
26+
$this->adobeCloudConfig = $this->getMockBuilder(AdobeCloudConfig::class)
27+
->disableOriginalConstructor()
28+
->getMock();
29+
}
30+
31+
/**
32+
* Validate if seller is on Cloud
33+
*
34+
* @return void
35+
*/
36+
public function testIsSellerOnAdobeCloudReturnsTrueWhenEnvVarIsSet(): void
37+
{
38+
/** check if the envinorment is non-premise */
39+
$_ENV['MAGENTO_CLOUD_ENVIRONMENT'] = 'MAGENTO_CLOUD_ENVIRONMENT';
40+
$this->adobeCloudConfig->method('isSellerOnAdobeCloud')
41+
->willReturn(true);
42+
43+
$this->assertTrue($this->adobeCloudConfig->isSellerOnAdobeCloud());
44+
unset($_ENV['MAGENTO_CLOUD_ENVIRONMENT']);
45+
}
46+
47+
/**
48+
* Validate if seller is on-premise
49+
*
50+
* @return void
51+
*/
52+
public function testIsSellerOnAdobeCloudReturnsFalseWhenEnvVarIsNotSet(): void
53+
{
54+
/** check if the envinorment is on-premise */
55+
unset($_ENV['MAGENTO_CLOUD_ENVIRONMENT']);
56+
$this->adobeCloudConfig->method('isSellerOnAdobeCloud')
57+
->willReturn(false);
58+
59+
$this->assertFalse($this->adobeCloudConfig->isSellerOnAdobeCloud());
60+
}
61+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Meta\BusinessExtension\Model\Api\CoreConfigFactory;
6+
use Meta\BusinessExtension\Model\Api\CoreConfig;
7+
use PHPUnit\Framework\TestCase;
8+
use Magento\Framework\ObjectManagerInterface;
9+
10+
class CoreConfigFactoryTest extends TestCase
11+
{
12+
/**
13+
* @var CoreConfigFactory
14+
*/
15+
private $metaCoreConfigFactoryObj;
16+
17+
/**
18+
* @var ObjectManagerInterface|\PHPUnit\Framework\MockObject\MockObject
19+
*/
20+
private $mockObjectManagerInterfaceDependency;
21+
22+
/**
23+
* Class setup function
24+
*
25+
* @return void
26+
*/
27+
protected function setUp(): void
28+
{
29+
parent::setUp();
30+
31+
$this->mockObjectManagerInterfaceDependency = $this->createMock(ObjectManagerInterface::class);
32+
$this->metaCoreConfigFactoryObj = new CoreConfigFactory($this->mockObjectManagerInterfaceDependency);
33+
}
34+
35+
/**
36+
* Test create method
37+
*
38+
* @return void
39+
*/
40+
public function testCreate(): void
41+
{
42+
$expectedCoreConfig = $this->createMock(CoreConfig::class);
43+
$data = $this->getData();
44+
45+
$this->mockObjectManagerInterfaceDependency->expects($this->once())
46+
->method('create')
47+
->with(CoreConfig::class, $data)
48+
->willReturn($expectedCoreConfig);
49+
50+
$actualCoreConfig = $this->metaCoreConfigFactoryObj->create($data);
51+
52+
$this->assertInstanceOf(CoreConfig::class, $actualCoreConfig);
53+
$this->assertSame($expectedCoreConfig, $actualCoreConfig);
54+
}
55+
56+
/**
57+
* Get data for testing
58+
*
59+
* @return array
60+
*/
61+
private function getData()
62+
{
63+
return [
64+
'externalBusinessId' => '1234567890',
65+
'isOrderSyncEnabled' => true,
66+
'isCatalogSyncEnabled' => true,
67+
'isPromotionsSyncEnabled' => true,
68+
'isActiveExtension' => true,
69+
'productIdentifierAttr' => 'sku',
70+
'outOfStockThreshold' => '10',
71+
'feedId' => 'meta_feed_id',
72+
'installedMetaExtensionVersion' => 'v1.0',
73+
'graphApiVersion' => 'v21.0',
74+
'magentoVersion' => 'v2.4.8',
75+
];
76+
}
77+
}
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Meta\BusinessExtension\Test\Unit\Api;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Meta\BusinessExtension\Model\Api\CoreConfig;
9+
10+
class CoreConfigTest extends TestCase
11+
{
12+
/**
13+
* @var CoreConfig
14+
*/
15+
private $metaCoreConfig;
16+
17+
/**
18+
* Class setup function
19+
*
20+
* @return void
21+
*/
22+
protected function setup(): void
23+
{
24+
parent::setup();
25+
26+
$this->metaCoreConfig = $this->getMockBuilder(CoreConfig::class)
27+
->disableOriginalConstructor()
28+
->getMock();
29+
}
30+
31+
/**
32+
* Validate if the external business ID is empty
33+
*
34+
* @return void
35+
*/
36+
public function testGetExternalBusinessId(): void
37+
{
38+
$this->metaCoreConfig->method('getExternalBusinessId')
39+
->willReturn('');
40+
41+
$this->assertEmpty($this->metaCoreConfig->getExternalBusinessId());
42+
}
43+
44+
/**
45+
* Validate if the external business ID is set
46+
*
47+
* @return void
48+
*/
49+
public function testSetExternalBusinessId(): void
50+
{
51+
$businessId = 'ZmJfaWRfMQ==';
52+
$this->metaCoreConfig->setExternalBusinessId($businessId);
53+
$this->metaCoreConfig->method('getExternalBusinessId')
54+
->willReturn($businessId);
55+
56+
$this->assertSame($businessId, $this->metaCoreConfig->getExternalBusinessId());
57+
}
58+
59+
/**
60+
* Validate if the order sync is enabled
61+
*
62+
* @return void
63+
*/
64+
public function testSetIsOrderSyncEnabled(): void
65+
{
66+
$isOrderSyncEnabled = true;
67+
$this->metaCoreConfig->setIsOrderSyncEnabled($isOrderSyncEnabled);
68+
69+
$this->metaCoreConfig->method('isOrderSyncEnabled')
70+
->willReturn($isOrderSyncEnabled);
71+
72+
$this->assertSame($isOrderSyncEnabled, $this->metaCoreConfig->isOrderSyncEnabled());
73+
}
74+
75+
/**
76+
* Validate if the catalog sync is enabled
77+
*
78+
* @return void
79+
*/
80+
public function testSetIsCatalogSyncEnabled(): void
81+
{
82+
$isCatalogSyncEnabled = true;
83+
$this->metaCoreConfig->setIsCatalogSyncEnabled($isCatalogSyncEnabled);
84+
85+
$this->metaCoreConfig->method('isCatalogSyncEnabled')
86+
->willReturn($isCatalogSyncEnabled);
87+
88+
$this->assertSame($isCatalogSyncEnabled, $this->metaCoreConfig->isCatalogSyncEnabled());
89+
}
90+
91+
/**
92+
* Validate if the Promotion sync is enabled
93+
*
94+
* @return void
95+
*/
96+
public function testSetIsPromotionsSyncEnabled(): void
97+
{
98+
$isPromotionsSyncEnabled = true;
99+
$this->metaCoreConfig->setIsPromotionsSyncEnabled($isPromotionsSyncEnabled);
100+
101+
$this->metaCoreConfig->method('isPromotionsSyncEnabled')
102+
->willReturn($isPromotionsSyncEnabled);
103+
104+
$this->assertSame($isPromotionsSyncEnabled, $this->metaCoreConfig->isPromotionsSyncEnabled());
105+
}
106+
107+
/**
108+
* Validate if the extension is active
109+
*
110+
* @return void
111+
*/
112+
public function testSetIsActiveExtension(): void
113+
{
114+
$isActiveExtension = true;
115+
$this->metaCoreConfig->setIsActiveExtension($isActiveExtension);
116+
117+
$this->metaCoreConfig->method('isActiveExtension')
118+
->willReturn($isActiveExtension);
119+
120+
$this->assertSame($isActiveExtension, $this->metaCoreConfig->isActiveExtension());
121+
}
122+
123+
/**
124+
* Validate if the product identifier attribute is set
125+
*
126+
* @return void
127+
*/
128+
public function testSetProductIdentifierAttr(): void
129+
{
130+
$productIdentifierAttr = 'sku';
131+
$this->metaCoreConfig->setProductIdentifierAttr($productIdentifierAttr);
132+
133+
$this->metaCoreConfig->method('getProductIdentifierAttr')
134+
->willReturn($productIdentifierAttr);
135+
136+
$this->assertSame($productIdentifierAttr, $this->metaCoreConfig->getProductIdentifierAttr());
137+
}
138+
139+
/**
140+
* Validate if the product stock threashold is set
141+
*
142+
* @return void
143+
*/
144+
public function testSetOutOfStockThreshold(): void
145+
{
146+
$outOfStockThreshold = '10';
147+
$this->metaCoreConfig->setOutOfStockThreshold($outOfStockThreshold);
148+
149+
$this->metaCoreConfig->method('getOutOfStockThreshold')
150+
->willReturn($outOfStockThreshold);
151+
152+
$this->assertSame($outOfStockThreshold, $this->metaCoreConfig->getOutOfStockThreshold());
153+
}
154+
155+
/**
156+
* Validate if the feed ID is set
157+
*
158+
* @return void
159+
*/
160+
public function testSetFeedId(): void
161+
{
162+
$feedId = 'feed-id';
163+
$this->metaCoreConfig->setFeedId($feedId);
164+
165+
$this->metaCoreConfig->method('getFeedId')
166+
->willReturn($feedId);
167+
168+
$this->assertSame($feedId, $this->metaCoreConfig->getFeedId());
169+
}
170+
171+
/**
172+
* Validate if the installed meta extension version is set
173+
*
174+
* @return void
175+
*/
176+
public function testSetInstalledMetaExtensionVersion(): void
177+
{
178+
$version = '1.0.0';
179+
$this->metaCoreConfig->setInstalledMetaExtensionVersion($version);
180+
181+
$this->metaCoreConfig->method('getInstalledMetaExtensionVersion')
182+
->willReturn($version);
183+
184+
$this->assertSame($version, $this->metaCoreConfig->getInstalledMetaExtensionVersion());
185+
}
186+
187+
/**
188+
* Validate if the Graph API version is set
189+
*
190+
* @return void
191+
*/
192+
public function testSetGraphApiVersion(): void
193+
{
194+
$graphApiVersion = 'v1.0';
195+
$this->metaCoreConfig->setGraphApiVersion($graphApiVersion);
196+
197+
$this->metaCoreConfig->method('getGraphApiVersion')
198+
->willReturn($graphApiVersion);
199+
200+
$this->assertSame($graphApiVersion, $this->metaCoreConfig->getGraphApiVersion());
201+
}
202+
203+
/**
204+
* Validate if the Graph API version is set
205+
*
206+
* @return void
207+
*/
208+
public function testSetMagentoVersion(): void
209+
{
210+
$magentoVersion = '2.4.5';
211+
$this->metaCoreConfig->setMagentoVersion($magentoVersion);
212+
213+
$this->metaCoreConfig->method('getMagentoVersion')
214+
->willReturn($magentoVersion);
215+
216+
$this->assertSame($magentoVersion, $this->metaCoreConfig->getMagentoVersion());
217+
}
218+
}

0 commit comments

Comments
 (0)