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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?php
/**
* Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
*/
namespace Temando\Shipping\Model\Config;
use Magento\TestFramework\ObjectManager;
use Magento\TestFramework\Helper\Bootstrap;
/**
* Temando Config Model Test
*
* @package Temando\Shipping\Test\Integration
* @author Sebastian Ertner <sebastian.ertner@netresearch.de>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link http://www.temando.com/
*/
class ModuleConfigTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ObjectManager
*/
private $objectManager;
/**
* @var ModuleConfig
*/
private $config;
/**
* @var \Magento\Framework\App\Config\Storage\Writer | \PHPUnit_Framework_MockObject_MockObject
*/
private $configWriterMock;
/**
* Init object manager
*/
protected function setUp()
{
parent::setUp();
$this->objectManager = Bootstrap::getObjectManager();
$this->configWriterMock = $this->getMockBuilder(\Magento\Framework\App\Config\Storage\Writer::class)
->setMethods(['save', 'delete'])
->disableOriginalConstructor()
->getMock();
$configAccessor = Bootstrap::getObjectManager()->create(ConfigAccessor::class, [
'configWriter' => $this->configWriterMock,
]);
$this->config = $this->objectManager->create(ModuleConfig::class, [
'configAccessor' => $configAccessor,
]);
}
/**
* @test
* @magentoConfigFixture default/carriers/temando/logging_enabled 1
*/
public function logIsEnabled()
{
$this->assertTrue($this->config->isLoggingEnabled());
}
/**
* @test
* @magentoConfigFixture default/carriers/temando/logging_enabled 0
*/
public function logIsDisabled()
{
$this->assertFalse($this->config->isLoggingEnabled());
}
/**
* @test
* @magentoConfigFixture default/general/store_information/name Info Name
* @magentoConfigFixture default/general/store_information/phone Info Phone
* @magentoConfigFixture default/general/store_information/country_id Info Contry
* @magentoConfigFixture default/general/store_information/postcode Info Postcode
* @magentoConfigFixture default/general/store_information/city Info City
* @magentoConfigFixture default/general/store_information/street_line1 Info Street
*/
public function getStoreInformation()
{
$info = $this->config->getStoreInformation();
$this->assertInstanceOf(\Magento\Framework\DataObject::class, $info);
$this->assertEquals('Info Name', $info->getData('name'));
$this->assertEquals('Info Phone', $info->getData('phone'));
$this->assertEquals('Info Contry', $info->getData('country_id'));
$this->assertEquals('Info Postcode', $info->getData('postcode'));
$this->assertEquals('Info City', $info->getData('city'));
$this->assertEquals('Info Street', $info->getData('street_line1'));
}
/**
* @test
* @magentoConfigFixture default/shipping/origin/postcode Origin Postcode
* @magentoConfigFixture default/shipping/origin/city Origin City
* @magentoConfigFixture default/shipping/origin/street_line1 Origin Street
*/
public function getShippingOrigin()
{
$origin = $this->config->getShippingOrigin();
$this->assertInstanceOf(\Magento\Framework\DataObject::class, $origin);
$this->assertEquals('Origin Postcode', $origin->getData('postcode'));
$this->assertEquals('Origin City', $origin->getData('city'));
$this->assertEquals('Origin Street', $origin->getData('street_line1'));
}
/**
* @test
* @magentoConfigFixture default/general/locale/weight_unit Foo Unit
*/
public function getWeightUnit()
{
$this->assertEquals('Foo Unit', $this->config->getWeightUnit());
}
/**
* @test
* @magentoConfigFixture default/carriers/temando/sovereign_endpoint endpoint.com
*/
public function getApiEndpoint()
{
$this->assertEquals('endpoint.com', $this->config->getApiEndpoint());
}
/**
* @test
* @magentoConfigFixture default/carriers/temando/account_id 23
*/
public function getAccountId()
{
$this->assertEquals('23', $this->config->getAccountId());
}
/**
* @test
*/
public function saveAccountId()
{
$this->configWriterMock
->expects($this->once())
->method('save')
->with(ModuleConfig::CONFIG_XML_PATH_ACCOUNT_ID, '12');
$this->config->saveAccountId('12');
}
/**
* @test
* @magentoConfigFixture default/carriers/temando/bearer_token 808
*/
public function getBearerToken()
{
$this->assertEquals('808', $this->config->getBearerToken());
}
/**
* @test
*/
public function saveBearerToken()
{
$this->configWriterMock
->expects($this->once())
->method('save')
->with(ModuleConfig::CONFIG_XML_PATH_BEARER_TOKEN, 'bearerToken');
$this->config->saveBearerToken('bearerToken');
}
/**
* @test
* @magentoConfigFixture default/carriers/temando/account_id accountId
* @magentoConfigFixture default/carriers/temando/bearer_token bearerToken
*/
public function credentialsAreAvailable()
{
$this->assertTrue($this->config->isRegistered());
}
/**
* @test
* @magentoConfigFixture default/carriers/temando/bearer_token bearerToken
*/
public function credentialsAccountMissing()
{
$this->assertFalse($this->config->isRegistered());
}
/**
* @test
* @magentoConfigFixture default/carriers/temando/account_id accountId
*/
public function credentialsBearerTokenMissing()
{
$this->assertFalse($this->config->isRegistered());
}
/**
* @test
*/
public function credentialsAreNotAvailable()
{
$this->assertFalse($this->config->isRegistered());
}
/**
* @test
* @magentoConfigFixture default/carriers/temando/bearer_token_expiry 123456
*/
public function getBearerTokenExpiry()
{
$this->assertEquals('123456', $this->config->getBearerTokenExpiry());
}
/**
* @test
*/
public function saveBearerTokenExpiry()
{
$this->configWriterMock
->expects($this->once())
->method('save')
->with(ModuleConfig::CONFIG_XML_PATH_BEARER_TOKEN_EXPIRY, '123456');
$this->config->saveBearerTokenExpiry('123456');
}
/**
* @test
*/
public function setAccount()
{
$this->configWriterMock
->expects($this->exactly(3))
->method('save')
->withConsecutive(
['carriers/temando/account_id', '12'],
['carriers/temando/bearer_token', 'bearerToken'],
['carriers/temando/bearer_token_expiry', '123456']
);
$this->config->setAccount('12', 'bearerToken', '123456');
}
/**
* @test
*/
public function unsetAccount()
{
$this->configWriterMock
->expects($this->exactly(3))
->method('delete')
->withConsecutive(
['carriers/temando/account_id'],
['carriers/temando/bearer_token'],
['carriers/temando/bearer_token_expiry']
);
$this->config->unsetAccount();
}
}