1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* CakePHPify : CakePHP Plugin for Shopify API Authentication |
4
|
|
|
* Copyright (c) Multidimension.al (http://multidimension.al) |
5
|
|
|
* Github : https://github.com/multidimension-al/cakephpify |
6
|
|
|
* |
7
|
|
|
* Licensed under The MIT License |
8
|
|
|
* For full copyright and license information, please see the LICENSE file |
9
|
|
|
* Redistributions of files must retain the above copyright notice. |
10
|
|
|
* |
11
|
|
|
* @copyright (c) Multidimension.al (http://multidimension.al) |
12
|
|
|
* @link https://github.com/multidimension-al/cakephpify CakePHPify Github |
13
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Multidimensional\Cakephpify\Test\TestCase\Controller\Component; |
17
|
|
|
|
18
|
|
|
use Cake\Controller\ComponentRegistry; |
19
|
|
|
use Cake\Controller\Controller; |
20
|
|
|
use Cake\Core\Configure; |
21
|
|
|
use Cake\Event\Event; |
22
|
|
|
use Cake\Network\Request; |
23
|
|
|
use Cake\Network\Response; |
24
|
|
|
use Cake\TestSuite\TestCase; |
25
|
|
|
use Multidimensional\Cakephpify\Controller\Component\ShopifyAPIComponent; |
26
|
|
|
use Multidimensional\Cakephpify\Test\Fixture\AccessTokensFixture; |
27
|
|
|
use Multidimensional\Cakephpify\Test\Fixture\ShopsFixture; |
28
|
|
|
|
29
|
|
|
class ShopifyAPIComponentTest extends TestCase |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
public $component = null; |
33
|
|
|
public $controller = null; |
34
|
|
|
public $fixtures = ['plugin.Multidimensional/Cakephpify.Shops', 'plugin.Multidimensional/Cakephpify.AccessTokens']; |
35
|
|
|
|
36
|
|
|
public function setUp() |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
parent::setUp(); |
39
|
|
|
|
40
|
|
|
Configure::write('Multidimensional/Cakephpify', [ |
41
|
|
|
'abc123' => |
42
|
|
|
[ |
43
|
|
|
'sharedSecret' => 'abc123', |
44
|
|
|
'scope' => '', |
45
|
|
|
'privateApp' => false, |
46
|
|
|
'privateAppPassword' => NULL] |
|
|
|
|
47
|
|
|
]); |
48
|
|
|
|
49
|
|
|
$request = new Request(); |
50
|
|
|
$response = new Response(); |
51
|
|
|
$this->controller = $this->getMockBuilder('Cake\Controller\Controller') |
52
|
|
|
->setConstructorArgs([$request, $response]) |
53
|
|
|
->setMethods(null) |
54
|
|
|
->getMock(); |
55
|
|
|
$registry = new ComponentRegistry($this->controller); |
56
|
|
|
$this->component = new ShopifyAPIComponent($registry, ['apiKey' => 'abc123']); |
57
|
|
|
$event = new Event('Controller.startup', $this->controller); |
58
|
|
|
$this->component->startup($event); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function tearDown() |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
parent::tearDown(); |
64
|
|
|
unset($this->component, $this->controller); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testShopDomain() |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$shopDomain = 'test.myshopify.com'; |
70
|
|
|
$return = $this->component->setShopDomain($shopDomain); |
71
|
|
|
$this->assertSame($return, $shopDomain); |
72
|
|
|
$return = $this->component->getShopDomain(); |
73
|
|
|
$this->assertSame($return, $shopDomain); |
74
|
|
|
|
75
|
|
|
$shopDomain = 'random.myshopify.com'; |
76
|
|
|
$this->component->setShopDomain($shopDomain); |
77
|
|
|
$return = $this->component->setShopDomain($shopDomain); |
78
|
|
|
$this->assertSame($return, $shopDomain); |
79
|
|
|
$return = $this->component->getShopDomain(); |
80
|
|
|
$this->assertSame($return, $shopDomain); |
81
|
|
|
|
82
|
|
|
$shopDomain = null; |
83
|
|
|
$this->assertNull($shopDomain); |
84
|
|
|
$return = $this->component->setShopDomain($shopDomain); |
85
|
|
|
$this->assertNull($return); |
86
|
|
|
$return = $this->component->getShopDomain(); |
87
|
|
|
$this->assertNull($return); |
88
|
|
|
|
89
|
|
|
$shopDomain = false; |
90
|
|
|
$this->assertFalse($shopDomain); |
91
|
|
|
$return = $this->component->setShopDomain($shopDomain); |
|
|
|
|
92
|
|
|
$this->assertFalse($return); |
93
|
|
|
$return = $this->component->getShopDomain(); |
94
|
|
|
$this->assertFalse($return); |
95
|
|
|
|
96
|
|
|
$shopDomain = true; |
97
|
|
|
$this->assertTrue($shopDomain); |
98
|
|
|
$return = $this->component->setShopDomain($shopDomain); |
|
|
|
|
99
|
|
|
$this->assertTrue($return); |
100
|
|
|
$return = $this->component->getShopDomain(); |
101
|
|
|
$this->assertTrue($return); |
102
|
|
|
|
103
|
|
|
$shopDomain = 'test.myshopify.com'; |
104
|
|
|
$return = $this->component->validDomain($shopDomain); |
105
|
|
|
$this->assertTrue($return); |
106
|
|
|
|
107
|
|
|
$shopDomain = 'TEST.MYshopify.COM'; |
108
|
|
|
$return = $this->component->validDomain($shopDomain); |
109
|
|
|
$this->assertTrue($return); |
110
|
|
|
|
111
|
|
|
$shopDomain = 'random.myshopify.com'; |
112
|
|
|
$return = $this->component->validDomain($shopDomain); |
113
|
|
|
$this->assertTrue($return); |
114
|
|
|
|
115
|
|
|
$shopDomain = 'www.myshopify.com'; |
116
|
|
|
$return = $this->component->validDomain($shopDomain); |
117
|
|
|
$this->assertTrue($return); |
118
|
|
|
|
119
|
|
|
$shopDomain = 'test.myshopify.net'; |
120
|
|
|
$return = $this->component->validDomain($shopDomain); |
121
|
|
|
$this->assertFalse($return); |
122
|
|
|
|
123
|
|
|
$shopDomain = 'http://test.myshopify.com/'; |
124
|
|
|
$return = $this->component->validDomain($shopDomain); |
125
|
|
|
$this->assertFalse($return); |
126
|
|
|
|
127
|
|
|
$shopDomain = 'google.com'; |
128
|
|
|
$return = $this->component->validDomain($shopDomain); |
129
|
|
|
$this->assertFalse($return); |
130
|
|
|
|
131
|
|
|
$shopDomain = null; |
132
|
|
|
$this->assertNull($shopDomain); |
133
|
|
|
$return = $this->component->validDomain($shopDomain); |
134
|
|
|
$this->assertFalse($return); |
135
|
|
|
|
136
|
|
|
$shopDomain = false; |
137
|
|
|
$this->assertFalse($shopDomain); |
138
|
|
|
$return = $this->component->validDomain($shopDomain); |
|
|
|
|
139
|
|
|
$this->assertFalse($return); |
140
|
|
|
|
141
|
|
|
$shopDomain = true; |
142
|
|
|
$this->assertTrue($shopDomain); |
143
|
|
|
$return = $this->component->validDomain($shopDomain); |
|
|
|
|
144
|
|
|
$this->assertFalse($return); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function testAccessToken() |
|
|
|
|
148
|
|
|
{ |
149
|
|
|
$token = md5(rand()); |
150
|
|
|
$return = $this->component->setAccessToken($token); |
151
|
|
|
$this->assertSame($return, $token); |
152
|
|
|
$return = $this->component->getAccessToken(); |
153
|
|
|
$this->assertSame($return, $token); |
154
|
|
|
|
155
|
|
|
$token = null; |
156
|
|
|
$this->assertNull($token); |
157
|
|
|
$return = $this->component->setAccessToken($token); |
158
|
|
|
$this->assertNull($return); |
159
|
|
|
$return = $this->component->getAccessToken(); |
160
|
|
|
$this->assertNull($return); |
161
|
|
|
|
162
|
|
|
$token = false; |
163
|
|
|
$this->assertFalse($token); |
164
|
|
|
$return = $this->component->setAccessToken($token); |
|
|
|
|
165
|
|
|
$this->assertFalse($return); |
166
|
|
|
$return = $this->component->getAccessToken(); |
167
|
|
|
$this->assertFalee($return); |
|
|
|
|
168
|
|
|
|
169
|
|
|
$token = true; |
170
|
|
|
$this->assertTrue($token); |
171
|
|
|
$return = $this->component->setAccessToken($token); |
|
|
|
|
172
|
|
|
$this->assertTrue($return); |
173
|
|
|
$return = $this->component->getAccessToken(); |
174
|
|
|
$this->assertTrue($return); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function testGetAuthorizeUrl() |
|
|
|
|
178
|
|
|
{ |
179
|
|
|
$this->markTestIncomplete('Not implemented yet.'); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function testRequestAccessToken() |
|
|
|
|
183
|
|
|
{ |
184
|
|
|
$this->markTestIncomplete('Not implemented yet.'); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
public function testNonce() |
|
|
|
|
188
|
|
|
{ |
189
|
|
|
$shopDomain = "test.myshopify.com"; //339fdccae930940993141bde32be560f |
|
|
|
|
190
|
|
|
$return = $this->component->setNonce($shopDomain); |
191
|
|
|
$this->assertSame($return, '339fdccae930940993141bde32be560f'); |
192
|
|
|
$return = $this->component->getNonce(); |
193
|
|
|
$this->assertSame($return, '339fdccae930940993141bde32be560f'); |
194
|
|
|
|
195
|
|
|
$shopDomain = "TeSt.MySHoPiFy.CoM"; //339fdccae930940993141bde32be560f |
|
|
|
|
196
|
|
|
$return = $this->component->setNonce($shopDomain); |
197
|
|
|
$this->assertSame($return, '339fdccae930940993141bde32be560f'); |
198
|
|
|
$return = $this->component->getNonce(); |
199
|
|
|
$this->assertSame($return, '339fdccae930940993141bde32be560f'); |
200
|
|
|
|
201
|
|
|
$shopDomain = "example.com"; //5ababd603b22780302dd8d83498e5172 |
|
|
|
|
202
|
|
|
$return = $this->component->setNonce($shopDomain); |
203
|
|
|
$this->assertSame($return, '5ababd603b22780302dd8d83498e5172'); |
204
|
|
|
$return = $this->component->getNonce(); |
205
|
|
|
$this->assertSame($return, '5ababd603b22780302dd8d83498e5172'); |
206
|
|
|
|
207
|
|
|
$shopDomain = null; //d41d8cd98f00b204e9800998ecf8427e |
208
|
|
|
$this->assertNull($shopDomain); |
209
|
|
|
$return = $this->component->setNonce($shopDomain); |
210
|
|
|
$this->assertSame($return, 'd41d8cd98f00b204e9800998ecf8427e'); |
211
|
|
|
$return = $this->component->getNonce(); |
212
|
|
|
$this->assertSame($return, 'd41d8cd98f00b204e9800998ecf8427e'); |
213
|
|
|
|
214
|
|
|
$shopDomain = false; //d41d8cd98f00b204e9800998ecf8427e |
215
|
|
|
$this->assertFalse($shopDomain); |
216
|
|
|
$return = $this->component->setNonce($shopDomain); |
|
|
|
|
217
|
|
|
$this->assertSame($return, 'd41d8cd98f00b204e9800998ecf8427e'); |
218
|
|
|
$return = $this->component->getNonce(); |
219
|
|
|
$this->assertSame($return, 'd41d8cd98f00b204e9800998ecf8427e'); |
220
|
|
|
|
221
|
|
|
$shopDomain = true; //c4ca4238a0b923820dcc509a6f75849b |
222
|
|
|
$this->assertTrue($shopDomain); |
223
|
|
|
$return = $this->component->setNonce($shopDomain); |
|
|
|
|
224
|
|
|
$this->assertSame($return, 'c4ca4238a0b923820dcc509a6f75849b'); |
225
|
|
|
$return = $this->component->getNonce(); |
226
|
|
|
$this->assertSame($return, 'c4ca4238a0b923820dcc509a6f75849b'); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
public function testValidateHMAC() |
|
|
|
|
230
|
|
|
{ |
231
|
|
|
$return = $this->component->validateHMAC(null); |
|
|
|
|
232
|
|
|
$this->assertFalse($return); |
233
|
|
|
|
234
|
|
|
$return = $this->component->validateHMAC([]); |
235
|
|
|
$this->assertFalse($return); |
236
|
|
|
|
237
|
|
|
$return = $this->component->validateHMAC(['hmac' => null]); |
238
|
|
|
$this->assertFalse($return); |
239
|
|
|
|
240
|
|
|
$return = $this->component->validateHMAC(['hmac' => 'string']); |
241
|
|
|
$this->assertFalse($return); |
242
|
|
|
} |
243
|
|
|
} |
244
|
|
|
|