Skip to content

Commit 9bb6db3

Browse files
authored
Merge pull request #881 from sdinteractive/unit/testcase
ADO-424 : PHP Unit test case
2 parents 803dc56 + 647f863 commit 9bb6db3

File tree

95 files changed

+14615
-184
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+14615
-184
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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 Meta\BusinessExtension\Api\AdobeCloudConfigInterface;
9+
use PHPUnit\Framework\TestCase;
10+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
11+
12+
class AdobeCloudConfigTest extends TestCase
13+
{
14+
/**
15+
* @var AdobeCloudConfig
16+
*/
17+
private $adobeCloudConfig;
18+
19+
/**
20+
* Class setup function
21+
*
22+
* @return void
23+
*/
24+
protected function setUp(): void
25+
{
26+
parent::setUp();
27+
$objectManager = new ObjectManager($this);
28+
29+
$this->adobeCloudConfig = $objectManager->getObject(
30+
AdobeCloudConfig::class
31+
);
32+
}
33+
34+
/**
35+
* Validate if seller is on Cloud
36+
*
37+
* @return void
38+
*/
39+
public function testIsSellerOnAdobeCloudReturnsTrueWhenEnvVarIsSet(): void
40+
{
41+
/** check if the envinorment is non-premise */
42+
$_ENV['MAGENTO_CLOUD_ENVIRONMENT'] = 'MAGENTO_CLOUD_ENVIRONMENT';
43+
44+
$this->assertTrue($this->adobeCloudConfig->isSellerOnAdobeCloud());
45+
unset($_ENV['MAGENTO_CLOUD_ENVIRONMENT']);
46+
}
47+
48+
/**
49+
* Validate if seller is on-premise
50+
*
51+
* @return void
52+
*/
53+
public function testIsSellerOnAdobeCloudReturnsFalseWhenEnvVarIsNotSet(): void
54+
{
55+
/** check if the envinorment is on-premise */
56+
unset($_ENV['MAGENTO_CLOUD_ENVIRONMENT']);
57+
58+
$this->assertFalse($this->adobeCloudConfig->isSellerOnAdobeCloud());
59+
}
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+
}
86+
}
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: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
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+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
11+
class CoreConfigTest extends TestCase
12+
{
13+
/**
14+
* @var CoreConfig
15+
*/
16+
private $metaCoreConfig;
17+
18+
/**
19+
* Class setup function
20+
*
21+
* @return void
22+
*/
23+
protected function setup(): void
24+
{
25+
parent::setup();
26+
27+
$objectManager = new ObjectManager($this);
28+
$this->metaCoreConfig = $objectManager->getObject(
29+
CoreConfig::class,
30+
[
31+
'data' => []
32+
]
33+
);
34+
}
35+
36+
/**
37+
* Validate if the external business ID is empty
38+
*
39+
* @return void
40+
*/
41+
public function testGetExternalBusinessId(): void
42+
{
43+
$businessId = 'ZmJfaWRfMQ==';
44+
$this->metaCoreConfig->setExternalBusinessId($businessId);
45+
$this->assertEquals($businessId, $this->metaCoreConfig->getExternalBusinessId());
46+
}
47+
48+
/**
49+
* Validate if the order sync is enabled
50+
*
51+
* @return void
52+
*/
53+
public function testSetIsOrderSyncEnabled(): void
54+
{
55+
$isOrderSyncEnabled = true;
56+
$this->metaCoreConfig->setIsOrderSyncEnabled($isOrderSyncEnabled);
57+
58+
$this->assertSame($isOrderSyncEnabled, $this->metaCoreConfig->isOrderSyncEnabled());
59+
}
60+
61+
/**
62+
* Validate if the catalog sync is enabled
63+
*
64+
* @return void
65+
*/
66+
public function testSetIsCatalogSyncEnabled(): void
67+
{
68+
$isCatalogSyncEnabled = true;
69+
$this->metaCoreConfig->setIsCatalogSyncEnabled($isCatalogSyncEnabled);
70+
71+
$this->assertSame($isCatalogSyncEnabled, $this->metaCoreConfig->isCatalogSyncEnabled());
72+
}
73+
74+
/**
75+
* Validate if the Promotion sync is enabled
76+
*
77+
* @return void
78+
*/
79+
public function testSetIsPromotionsSyncEnabled(): void
80+
{
81+
$isPromotionsSyncEnabled = true;
82+
$this->metaCoreConfig->setIsPromotionsSyncEnabled($isPromotionsSyncEnabled);
83+
84+
$this->assertSame($isPromotionsSyncEnabled, $this->metaCoreConfig->isPromotionsSyncEnabled());
85+
}
86+
87+
/**
88+
* Validate if the extension is active
89+
*
90+
* @return void
91+
*/
92+
public function testSetIsActiveExtension(): void
93+
{
94+
$isActiveExtension = true;
95+
$this->metaCoreConfig->setIsActiveExtension($isActiveExtension);
96+
97+
$this->assertSame($isActiveExtension, $this->metaCoreConfig->isActiveExtension());
98+
}
99+
100+
/**
101+
* Validate if the product identifier attribute is set
102+
*
103+
* @return void
104+
*/
105+
public function testSetProductIdentifierAttr(): void
106+
{
107+
$productIdentifierAttr = 'sku';
108+
$this->metaCoreConfig->setProductIdentifierAttr($productIdentifierAttr);
109+
110+
$this->assertSame($productIdentifierAttr, $this->metaCoreConfig->getProductIdentifierAttr());
111+
}
112+
113+
/**
114+
* Validate if the product stock threashold is set
115+
*
116+
* @return void
117+
*/
118+
public function testSetOutOfStockThreshold(): void
119+
{
120+
$outOfStockThreshold = '10';
121+
$this->metaCoreConfig->setOutOfStockThreshold($outOfStockThreshold);
122+
123+
$this->assertSame($outOfStockThreshold, $this->metaCoreConfig->getOutOfStockThreshold());
124+
}
125+
126+
/**
127+
* Validate if the feed ID is set
128+
*
129+
* @return void
130+
*/
131+
public function testSetFeedId(): void
132+
{
133+
$feedId = 'feed-id';
134+
$this->metaCoreConfig->setFeedId($feedId);
135+
136+
$this->assertSame($feedId, $this->metaCoreConfig->getFeedId());
137+
}
138+
139+
/**
140+
* Validate if the installed meta extension version is set
141+
*
142+
* @return void
143+
*/
144+
public function testSetInstalledMetaExtensionVersion(): void
145+
{
146+
$version = '1.0.0';
147+
$this->metaCoreConfig->setInstalledMetaExtensionVersion($version);
148+
149+
$this->assertSame($version, $this->metaCoreConfig->getInstalledMetaExtensionVersion());
150+
}
151+
152+
/**
153+
* Validate if the Graph API version is set
154+
*
155+
* @return void
156+
*/
157+
public function testSetGraphApiVersion(): void
158+
{
159+
$graphApiVersion = 'v1.0';
160+
$this->metaCoreConfig->setGraphApiVersion($graphApiVersion);
161+
162+
$this->assertSame($graphApiVersion, $this->metaCoreConfig->getGraphApiVersion());
163+
}
164+
165+
/**
166+
* Validate if the Graph API version is set
167+
*
168+
* @return void
169+
*/
170+
public function testSetMagentoVersion(): void
171+
{
172+
$magentoVersion = '2.4.5';
173+
$this->metaCoreConfig->setMagentoVersion($magentoVersion);
174+
175+
$this->assertSame($magentoVersion, $this->metaCoreConfig->getMagentoVersion());
176+
}
177+
}

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)