1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
namespace Dotdigitalgroup\Email\Helper;
use Magento\TestFramework\ObjectManager;
/**
* Class ApiEndpointTest
*
* @package Dotdigitalgroup\Email\Helper
* @magentoDBIsolation enabled
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ApiEndpointTest extends \PHPUnit\Framework\TestCase
{
/**
* @return void
*/
public function setup()
{
$this->removeData();
}
/**
* @return void
*/
public function tearDown()
{
$this->removeData();
}
/**
* @return void
*/
public function removeData()
{
/** @var ObjectManager $objectManager */
$objectManager = ObjectManager::getInstance();
/** @var \Magento\Config\Model\ResourceModel\Config $config */
$config = $objectManager->create(\Magento\Config\Model\ResourceModel\Config::class);
$data = $this->dataProvider();
foreach ($data as $item) {
$config->deleteConfig(Config::PATH_FOR_API_ENDPOINT, $item[2], $item[0]);
}
}
/**
* @param int $website
* @param string $endPoint
*
* @return null
*
* @dataProvider dataProvider
*/
public function testFetchingApiEndpointSuccessful($website, $endPoint)
{
/** @var ObjectManager $objectManager */
$objectManager = ObjectManager::getInstance();
$property = new \stdClass();
$property->name = 'ApiEndpoint';
$property->value = $endPoint;
$accountInfo = new \stdClass();
$accountInfo->properties = [$property];
$mockClient = $this->getMockBuilder(\Dotdigitalgroup\Email\Model\Apiconnector\Client::class)
->disableOriginalConstructor()
->getMock();
$mockClient->method('getAccountInfo')
->willReturn($accountInfo);
$mockClientFactory = $this->getMockBuilder(
\Dotdigitalgroup\Email\Model\Apiconnector\ClientFactory::class
)
->disableOriginalConstructor()
->getMock();
$mockClientFactory->method('create')
->willReturn($mockClient);
/** @var \Dotdigitalgroup\Email\Helper\Data $helper */
$helper = new \Dotdigitalgroup\Email\Helper\Data(
$objectManager->create(\Magento\Framework\App\ProductMetadata::class),
$objectManager->create(\Dotdigitalgroup\Email\Model\ContactFactory::class),
$objectManager->create(\Dotdigitalgroup\Email\Model\ResourceModel\Contact::class),
$objectManager->create(\Dotdigitalgroup\Email\Helper\File::class),
$objectManager->create(\Magento\Config\Model\ResourceModel\Config::class),
$objectManager->create(\Magento\Framework\App\ResourceConnection::class),
$objectManager->create(\Magento\Framework\App\Helper\Context::class),
$objectManager->create(\Magento\Store\Model\StoreManagerInterface::class),
$objectManager->create(\Magento\Customer\Model\CustomerFactory::class),
$objectManager->create(\Magento\Framework\Module\ModuleListInterface::class),
$objectManager->create(\Magento\Store\Model\Store::class),
$objectManager->create(\Magento\Framework\App\Config\Storage\Writer::class),
$mockClientFactory,
$objectManager->create(\Dotdigitalgroup\Email\Helper\ConfigFactory::class),
$objectManager->create(\Dotdigitalgroup\Email\Model\Config\Json::class),
$objectManager->create(\Magento\Framework\Stdlib\DateTime\DateTime::class),
$objectManager->create(\Magento\Quote\Model\ResourceModel\Quote::class),
$objectManager->create(\Magento\Quote\Model\QuoteFactory::class),
$objectManager->create(\Magento\User\Model\ResourceModel\User::class),
$objectManager->create(\Magento\Framework\Encryption\EncryptorInterface::class)
);
$apiEndpoint = $helper->getApiEndpoint($website, $mockClient);
$this->assertEquals(
$endPoint,
$apiEndpoint
);
}
/**
* @return array
*/
public function dataProvider()
{
return [
[
0,
'https://r1.dummy.com',
'default'
],
[
1,
'https://r1.dummy.com',
'website'
]
];
}
}