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
|
|
|
$return = $this->component->setShopDomain($shopDomain); |
84
|
|
|
$this->assertNull($return); |
85
|
|
|
$return = $this->component->getShopDomain(); |
86
|
|
|
$this->assertNull($return); |
87
|
|
|
|
88
|
|
|
$shopDomain = false; |
89
|
|
|
$return = $this->component->setShopDomain($shopDomain); |
|
|
|
|
90
|
|
|
$this->assertFalse($return); |
91
|
|
|
$return = $this->component->getShopDomain(); |
92
|
|
|
$this->assertFalse($return); |
93
|
|
|
|
94
|
|
|
$shopDomain = true; |
95
|
|
|
$return = $this->component->setShopDomain($shopDomain); |
|
|
|
|
96
|
|
|
$this->assertTrue($return); |
97
|
|
|
$return = $this->component->getShopDomain(); |
98
|
|
|
$this->assertTrue($return); |
99
|
|
|
|
100
|
|
|
$shopDomain = "test.myshopify.com"; |
|
|
|
|
101
|
|
|
$return = $this->component->validDomain($shopDomain); |
102
|
|
|
$this->assertTrue($return); |
103
|
|
|
|
104
|
|
|
$shopDomain = "TEST.MYshopify.COM"; |
|
|
|
|
105
|
|
|
$return = $this->component->validDomain($shopDomain); |
106
|
|
|
$this->assertTrue($return); |
107
|
|
|
|
108
|
|
|
$shopDomain = "random.myshopify.com"; |
|
|
|
|
109
|
|
|
$return = $this->component->validDomain($shopDomain); |
110
|
|
|
$this->assertTrue($return); |
111
|
|
|
|
112
|
|
|
$shopDomain = "www.myshopify.com"; |
|
|
|
|
113
|
|
|
$return = $this->component->validDomain($shopDomain); |
114
|
|
|
$this->assertTrue($return); |
115
|
|
|
|
116
|
|
|
/*$shopDomain = "test.myshopify.net"; |
|
|
|
|
117
|
|
|
$return = $this->component->validDomain($shopDomain); |
118
|
|
|
$this->assertFalse($return); |
119
|
|
|
|
120
|
|
|
$shopDomain = "http://test.myshopify.com/"; |
121
|
|
|
$return = $this->component->validDomain($shopDomain); |
122
|
|
|
$this->assertFalse($return); |
123
|
|
|
|
124
|
|
|
$shopDomain = "google.com"; |
125
|
|
|
$return = $this->component->validDomain($shopDomain); |
126
|
|
|
$this->assertFalse($return); |
127
|
|
|
|
128
|
|
|
$shopDomain = NULL; |
129
|
|
|
$return = $this->component->validDomain($shopDomain); |
130
|
|
|
$this->assertFalse($return); |
131
|
|
|
|
132
|
|
|
$shopDomain = false; |
133
|
|
|
$return = $this->component->validDomain($shopDomain); |
134
|
|
|
$this->assertFalse($return); |
135
|
|
|
|
136
|
|
|
$shopDomain = true; |
137
|
|
|
$return = $this->component->validDomain($shopDomain); |
138
|
|
|
$this->assertFalse($return);*/ |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function testSetAccessToken() |
|
|
|
|
142
|
|
|
{ |
143
|
|
|
$this->markTestIncomplete('Not implemented yet.'); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function testGetAuthorizeUrl() |
|
|
|
|
147
|
|
|
{ |
148
|
|
|
$this->markTestIncomplete('Not implemented yet.'); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function testGetAccessToken() |
|
|
|
|
152
|
|
|
{ |
153
|
|
|
$this->markTestIncomplete('Not implemented yet.'); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function testNonce() |
|
|
|
|
157
|
|
|
{ |
158
|
|
|
$nonce = md5(rand()); |
159
|
|
|
$return = $this->component->setNonce($nonce); |
160
|
|
|
$this->assertSame($return, $nonce); |
161
|
|
|
$return = $this->component->getNonce(); |
162
|
|
|
$this->assertSame($return, $nonce); |
163
|
|
|
|
164
|
|
|
$nonce = md5(rand()); |
165
|
|
|
$return = $this->component->setNonce($nonce); |
166
|
|
|
$this->assertSame($return, $nonce); |
167
|
|
|
$return = $this->component->getNonce(); |
168
|
|
|
$this->assertSame($return, $nonce); |
169
|
|
|
|
170
|
|
|
$nonce = null; |
171
|
|
|
$return = $this->component->setNonce($nonce); |
172
|
|
|
$this->assertNull($return); |
173
|
|
|
$return = $this->component->getNonce(); |
174
|
|
|
$this->assertNull($return); |
175
|
|
|
|
176
|
|
|
$nonce = false; |
177
|
|
|
$return = $this->component->setNonce($nonce); |
|
|
|
|
178
|
|
|
$this->assertFalse($return); |
179
|
|
|
$return = $this->component->getNonce(); |
180
|
|
|
$this->assertFalse($return); |
181
|
|
|
|
182
|
|
|
$nonce = true; |
183
|
|
|
$return = $this->component->setNonce($nonce); |
|
|
|
|
184
|
|
|
$this->assertTrue($return); |
185
|
|
|
$return = $this->component->getNonce(); |
186
|
|
|
$this->assertTrue($return); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
public function testValidateHMAC() |
|
|
|
|
190
|
|
|
{ |
191
|
|
|
$return = $this->component->validateHMAC(); |
|
|
|
|
192
|
|
|
$this->assertFalse($return); |
193
|
|
|
|
194
|
|
|
$return = $this->component->validateHMAC([]); |
195
|
|
|
$this->assertFalse($return); |
196
|
|
|
|
197
|
|
|
$return = $this->component->validateHMAC(['hmac' => null]); |
198
|
|
|
$this->assertFalse($return); |
199
|
|
|
|
200
|
|
|
$return = $this->component->validateHMAC(['hmac' => "string"]); |
|
|
|
|
201
|
|
|
$this->assertFalse($return); |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|