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
|
|
|
$return = $this->component->validDomain($shopDomain); |
133
|
|
|
$this->assertFalse($return); |
134
|
|
|
|
135
|
|
|
$shopDomain = false; |
136
|
|
|
$return = $this->component->validDomain($shopDomain); |
137
|
|
|
$this->assertFalse($return); |
138
|
|
|
|
139
|
|
|
$shopDomain = true; |
140
|
|
|
$return = $this->component->validDomain($shopDomain); |
141
|
|
|
$this->assertFalse($return);*/ |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function testSetAccessToken() |
|
|
|
|
145
|
|
|
{ |
146
|
|
|
$this->markTestIncomplete('Not implemented yet.'); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function testGetAuthorizeUrl() |
|
|
|
|
150
|
|
|
{ |
151
|
|
|
$this->markTestIncomplete('Not implemented yet.'); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function testGetAccessToken() |
|
|
|
|
155
|
|
|
{ |
156
|
|
|
$this->markTestIncomplete('Not implemented yet.'); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function testNonce() |
|
|
|
|
160
|
|
|
{ |
161
|
|
|
$shopDomain = "test.myshopify.com"; //339fdccae930940993141bde32be560f |
|
|
|
|
162
|
|
|
$return = $this->component->setNonce($shopDomain); |
163
|
|
|
$this->assertSame($return, '339fdccae930940993141bde32be560f'); |
164
|
|
|
$return = $this->component->getNonce(); |
165
|
|
|
$this->assertSame($return, '339fdccae930940993141bde32be560f'); |
166
|
|
|
|
167
|
|
|
$shopDomain = "TeSt.MySHoPiFy.CoM"; //339fdccae930940993141bde32be560f |
|
|
|
|
168
|
|
|
$return = $this->component->setNonce($shopDomain); |
169
|
|
|
$this->assertSame($return, '339fdccae930940993141bde32be560f'); |
170
|
|
|
$return = $this->component->getNonce(); |
171
|
|
|
$this->assertSame($return, '339fdccae930940993141bde32be560f'); |
172
|
|
|
|
173
|
|
|
$shopDomain = "example.com"; //5ababd603b22780302dd8d83498e5172 |
|
|
|
|
174
|
|
|
$return = $this->component->setNonce($shopDomain); |
175
|
|
|
$this->assertSame($return, '5ababd603b22780302dd8d83498e5172'); |
176
|
|
|
$return = $this->component->getNonce(); |
177
|
|
|
$this->assertSame($return, '5ababd603b22780302dd8d83498e5172'); |
178
|
|
|
|
179
|
|
|
$shopDomain = null; //d41d8cd98f00b204e9800998ecf8427e |
180
|
|
|
$this->assertNull($shopDomain); |
181
|
|
|
$return = $this->component->setNonce($shopDomain); |
182
|
|
|
$this->assertSame($return, 'd41d8cd98f00b204e9800998ecf8427e'); |
183
|
|
|
$return = $this->component->getNonce(); |
184
|
|
|
$this->assertSame($return, 'd41d8cd98f00b204e9800998ecf8427e'); |
185
|
|
|
|
186
|
|
|
$shopDomain = false; //d41d8cd98f00b204e9800998ecf8427e |
187
|
|
|
$this->assertFalse($shopDomain); |
188
|
|
|
$return = $this->component->setNonce($shopDomain); |
|
|
|
|
189
|
|
|
$this->assertSame($return, 'd41d8cd98f00b204e9800998ecf8427e'); |
190
|
|
|
$return = $this->component->getNonce(); |
191
|
|
|
$this->assertSame($return, 'd41d8cd98f00b204e9800998ecf8427e'); |
192
|
|
|
|
193
|
|
|
$shopDomain = true; //c4ca4238a0b923820dcc509a6f75849b |
194
|
|
|
$this->assertTrue($shopDomain); |
195
|
|
|
$return = $this->component->setNonce($nonce); |
|
|
|
|
196
|
|
|
$this->assertSame($return, 'c4ca4238a0b923820dcc509a6f75849b'); |
197
|
|
|
$return = $this->component->getNonce(); |
198
|
|
|
$this->assertSame($return, 'c4ca4238a0b923820dcc509a6f75849b'); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
public function testValidateHMAC() |
|
|
|
|
202
|
|
|
{ |
203
|
|
|
$return = $this->component->validateHMAC(null); |
|
|
|
|
204
|
|
|
$this->assertFalse($return); |
205
|
|
|
|
206
|
|
|
$return = $this->component->validateHMAC([]); |
207
|
|
|
$this->assertFalse($return); |
208
|
|
|
|
209
|
|
|
$return = $this->component->validateHMAC(['hmac' => null]); |
210
|
|
|
$this->assertFalse($return); |
211
|
|
|
|
212
|
|
|
$return = $this->component->validateHMAC(['hmac' => 'string']); |
213
|
|
|
$this->assertFalse($return); |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|