Skip to content

Commit 1f3daa6

Browse files
committed
[ADO-424] Add additional phpunit for Meta_BusinessExtension module
1 parent c6b2543 commit 1f3daa6

33 files changed

+4391
-102
lines changed

app/code/Meta/BusinessExtension/Test/Unit/Api/AdobeCloudConfigTest.php

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
namespace Meta\BusinessExtension\Test\Unit\Api;
66

77
use Meta\BusinessExtension\Model\Api\AdobeCloudConfig;
8+
use Meta\BusinessExtension\Api\AdobeCloudConfigInterface;
89
use PHPUnit\Framework\TestCase;
10+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
911

1012
class AdobeCloudConfigTest extends TestCase
1113
{
@@ -22,10 +24,11 @@ class AdobeCloudConfigTest extends TestCase
2224
protected function setUp(): void
2325
{
2426
parent::setUp();
25-
26-
$this->adobeCloudConfig = $this->getMockBuilder(AdobeCloudConfig::class)
27-
->disableOriginalConstructor()
28-
->getMock();
27+
$objectManager = new ObjectManager($this);
28+
29+
$this->adobeCloudConfig = $objectManager->getObject(
30+
AdobeCloudConfig::class
31+
);
2932
}
3033

3134
/**
@@ -37,8 +40,6 @@ public function testIsSellerOnAdobeCloudReturnsTrueWhenEnvVarIsSet(): void
3740
{
3841
/** check if the envinorment is non-premise */
3942
$_ENV['MAGENTO_CLOUD_ENVIRONMENT'] = 'MAGENTO_CLOUD_ENVIRONMENT';
40-
$this->adobeCloudConfig->method('isSellerOnAdobeCloud')
41-
->willReturn(true);
4243

4344
$this->assertTrue($this->adobeCloudConfig->isSellerOnAdobeCloud());
4445
unset($_ENV['MAGENTO_CLOUD_ENVIRONMENT']);
@@ -53,9 +54,33 @@ public function testIsSellerOnAdobeCloudReturnsFalseWhenEnvVarIsNotSet(): void
5354
{
5455
/** check if the envinorment is on-premise */
5556
unset($_ENV['MAGENTO_CLOUD_ENVIRONMENT']);
56-
$this->adobeCloudConfig->method('isSellerOnAdobeCloud')
57-
->willReturn(false);
5857

5958
$this->assertFalse($this->adobeCloudConfig->isSellerOnAdobeCloud());
6059
}
60+
61+
/**
62+
* Validate if seller is on-premise
63+
*
64+
* @return void
65+
*/
66+
public function testGetCommercePartnerSellerPlatformType(): void
67+
{
68+
/** check if the envinorment is on-premise */
69+
$_ENV['MAGENTO_CLOUD_ENVIRONMENT'] = 'MAGENTO_CLOUD_ENVIRONMENT';
70+
71+
$this->assertSame(AdobeCloudConfigInterface::ADOBE_COMMERCE_CLOUD, $this->adobeCloudConfig->getCommercePartnerSellerPlatformType());
72+
}
73+
74+
/**
75+
* Validate if seller is on-premise
76+
*
77+
* @return void
78+
*/
79+
public function testGetCommercePartnerSellerPlatformTypeIsNotOnCloud(): void
80+
{
81+
/** check if the envinorment is on-premise */
82+
unset($_ENV['MAGENTO_CLOUD_ENVIRONMENT']);
83+
84+
$this->assertSame(AdobeCloudConfigInterface::MAGENTO_OPEN_SOURCE, $this->adobeCloudConfig->getCommercePartnerSellerPlatformType());
85+
}
6186
}

app/code/Meta/BusinessExtension/Test/Unit/Api/CoreConfigTest.php

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PHPUnit\Framework\TestCase;
88
use Meta\BusinessExtension\Model\Api\CoreConfig;
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
910

1011
class CoreConfigTest extends TestCase
1112
{
@@ -23,9 +24,13 @@ protected function setup(): void
2324
{
2425
parent::setup();
2526

26-
$this->metaCoreConfig = $this->getMockBuilder(CoreConfig::class)
27-
->disableOriginalConstructor()
28-
->getMock();
27+
$objectManager = new ObjectManager($this);
28+
$this->metaCoreConfig = $objectManager->getObject(
29+
CoreConfig::class,
30+
[
31+
'data' => []
32+
]
33+
);
2934
}
3035

3136
/**
@@ -34,26 +39,10 @@ protected function setup(): void
3439
* @return void
3540
*/
3641
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-
{
42+
{
5143
$businessId = 'ZmJfaWRfMQ==';
5244
$this->metaCoreConfig->setExternalBusinessId($businessId);
53-
$this->metaCoreConfig->method('getExternalBusinessId')
54-
->willReturn($businessId);
55-
56-
$this->assertSame($businessId, $this->metaCoreConfig->getExternalBusinessId());
45+
$this->assertEquals($businessId, $this->metaCoreConfig->getExternalBusinessId());
5746
}
5847

5948
/**
@@ -65,9 +54,6 @@ public function testSetIsOrderSyncEnabled(): void
6554
{
6655
$isOrderSyncEnabled = true;
6756
$this->metaCoreConfig->setIsOrderSyncEnabled($isOrderSyncEnabled);
68-
69-
$this->metaCoreConfig->method('isOrderSyncEnabled')
70-
->willReturn($isOrderSyncEnabled);
7157

7258
$this->assertSame($isOrderSyncEnabled, $this->metaCoreConfig->isOrderSyncEnabled());
7359
}
@@ -81,9 +67,6 @@ public function testSetIsCatalogSyncEnabled(): void
8167
{
8268
$isCatalogSyncEnabled = true;
8369
$this->metaCoreConfig->setIsCatalogSyncEnabled($isCatalogSyncEnabled);
84-
85-
$this->metaCoreConfig->method('isCatalogSyncEnabled')
86-
->willReturn($isCatalogSyncEnabled);
8770

8871
$this->assertSame($isCatalogSyncEnabled, $this->metaCoreConfig->isCatalogSyncEnabled());
8972
}
@@ -97,9 +80,6 @@ public function testSetIsPromotionsSyncEnabled(): void
9780
{
9881
$isPromotionsSyncEnabled = true;
9982
$this->metaCoreConfig->setIsPromotionsSyncEnabled($isPromotionsSyncEnabled);
100-
101-
$this->metaCoreConfig->method('isPromotionsSyncEnabled')
102-
->willReturn($isPromotionsSyncEnabled);
10383

10484
$this->assertSame($isPromotionsSyncEnabled, $this->metaCoreConfig->isPromotionsSyncEnabled());
10585
}
@@ -113,9 +93,6 @@ public function testSetIsActiveExtension(): void
11393
{
11494
$isActiveExtension = true;
11595
$this->metaCoreConfig->setIsActiveExtension($isActiveExtension);
116-
117-
$this->metaCoreConfig->method('isActiveExtension')
118-
->willReturn($isActiveExtension);
11996

12097
$this->assertSame($isActiveExtension, $this->metaCoreConfig->isActiveExtension());
12198
}
@@ -129,9 +106,6 @@ public function testSetProductIdentifierAttr(): void
129106
{
130107
$productIdentifierAttr = 'sku';
131108
$this->metaCoreConfig->setProductIdentifierAttr($productIdentifierAttr);
132-
133-
$this->metaCoreConfig->method('getProductIdentifierAttr')
134-
->willReturn($productIdentifierAttr);
135109

136110
$this->assertSame($productIdentifierAttr, $this->metaCoreConfig->getProductIdentifierAttr());
137111
}
@@ -145,9 +119,6 @@ public function testSetOutOfStockThreshold(): void
145119
{
146120
$outOfStockThreshold = '10';
147121
$this->metaCoreConfig->setOutOfStockThreshold($outOfStockThreshold);
148-
149-
$this->metaCoreConfig->method('getOutOfStockThreshold')
150-
->willReturn($outOfStockThreshold);
151122

152123
$this->assertSame($outOfStockThreshold, $this->metaCoreConfig->getOutOfStockThreshold());
153124
}
@@ -161,9 +132,6 @@ public function testSetFeedId(): void
161132
{
162133
$feedId = 'feed-id';
163134
$this->metaCoreConfig->setFeedId($feedId);
164-
165-
$this->metaCoreConfig->method('getFeedId')
166-
->willReturn($feedId);
167135

168136
$this->assertSame($feedId, $this->metaCoreConfig->getFeedId());
169137
}
@@ -177,9 +145,6 @@ public function testSetInstalledMetaExtensionVersion(): void
177145
{
178146
$version = '1.0.0';
179147
$this->metaCoreConfig->setInstalledMetaExtensionVersion($version);
180-
181-
$this->metaCoreConfig->method('getInstalledMetaExtensionVersion')
182-
->willReturn($version);
183148

184149
$this->assertSame($version, $this->metaCoreConfig->getInstalledMetaExtensionVersion());
185150
}
@@ -193,9 +158,6 @@ public function testSetGraphApiVersion(): void
193158
{
194159
$graphApiVersion = 'v1.0';
195160
$this->metaCoreConfig->setGraphApiVersion($graphApiVersion);
196-
197-
$this->metaCoreConfig->method('getGraphApiVersion')
198-
->willReturn($graphApiVersion);
199161

200162
$this->assertSame($graphApiVersion, $this->metaCoreConfig->getGraphApiVersion());
201163
}
@@ -209,9 +171,6 @@ public function testSetMagentoVersion(): void
209171
{
210172
$magentoVersion = '2.4.5';
211173
$this->metaCoreConfig->setMagentoVersion($magentoVersion);
212-
213-
$this->metaCoreConfig->method('getMagentoVersion')
214-
->willReturn($magentoVersion);
215174

216175
$this->assertSame($magentoVersion, $this->metaCoreConfig->getMagentoVersion());
217176
}

app/code/Meta/BusinessExtension/Test/Unit/Api/CustomApiKey/APIKeyServiceTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,27 @@ public function testUpsertApiKey()
6666
$this->assertEquals($apiKey, $result);
6767
}
6868

69+
public function testGetCustomApiKeyWithNull()
70+
{
71+
$this->scopeConfig->method('getValue')
72+
->with('meta_extension/general/api_key')
73+
->willReturn(null);
74+
$apiKeyService = new ApiKeyService(
75+
$this->apiKeyGenerator,
76+
$this->configWriter,
77+
$this->scopeConfig,
78+
$this->logger
79+
);
80+
$this->logger->expects($this->exactly(2))
81+
->method('info')
82+
->withConsecutive(['API key does not exist. Generating a new key.'],['API key has been generated and saved.'])
83+
->willReturnSelf();
84+
$this->configWriter->expects($this->once())->method('save');
85+
$result = $apiKeyService->getCustomApiKey();
86+
87+
$this->assertIsString($result);
88+
}
89+
6990
public function testCustomApiKey()
7091
{
7192
$apiKey = 'generated-api-key';

0 commit comments

Comments
 (0)