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\Event\Event; |
21
|
|
|
use Cake\Network\Request; |
22
|
|
|
use Cake\Network\Response; |
23
|
|
|
use Cake\TestSuite\TestCase; |
24
|
|
|
use Multidimensional\Cakephpify\Controller\Component\ShopifyAPIComponent; |
25
|
|
|
use Multidimensional\Cakephpify\Test\Fixture\AccessTokensFixture; |
26
|
|
|
use Multidimensional\Cakephpify\Test\Fixture\ShopsFixture; |
27
|
|
|
|
28
|
|
|
class ShopifyAPIComponentTest extends TestCase |
29
|
|
|
{ |
30
|
|
|
|
31
|
|
|
public $component = null; |
32
|
|
|
public $controller = null; |
33
|
|
|
public $fixtures = ['plugin.Multidimensional/Cakephpify.Shops', 'plugin.Multidimensional/Cakephpify.AccessTokens']; |
34
|
|
|
|
35
|
|
|
public function setUp() |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
parent::setUp(); |
38
|
|
|
$request = new Request(); |
39
|
|
|
$response = new Response(); |
40
|
|
|
$this->controller = $this->getMockBuilder('Cake\Controller\Controller') |
41
|
|
|
->setConstructorArgs([$request, $response]) |
42
|
|
|
->setMethods(null) |
43
|
|
|
->getMock(); |
44
|
|
|
$registry = new ComponentRegistry($this->controller); |
45
|
|
|
$this->component = new ShopifyAPIComponent($registry); |
46
|
|
|
$this->component->initialize(['apiKey' => 'abc123']); |
47
|
|
|
$event = new Event('Controller.startup', $this->controller); |
48
|
|
|
$this->component->startup($event); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function tearDown() |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
parent::tearDown(); |
54
|
|
|
unset($this->component, $this->controller); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testShopDomain() |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
$shopDomain = "test.myshopify.com"; |
|
|
|
|
60
|
|
|
$return = $this->component->setShopDomain($shopDomain); |
61
|
|
|
$this->assertSame($return, $shopDomain); |
62
|
|
|
$return = $this->component->getShopDomain(); |
63
|
|
|
$this->assertSame($return, $shopDomain); |
64
|
|
|
|
65
|
|
|
$shopDomain = "random.myshopify.com"; |
|
|
|
|
66
|
|
|
$this->component->setShopDomain($shopDomain); |
67
|
|
|
$return = $this->component->setShopDomain($shopDomain); |
68
|
|
|
$this->assertSame($return, $shopDomain); |
69
|
|
|
$return = $this->component->getShopDomain(); |
70
|
|
|
$this->assertSame($return, $shopDomain); |
71
|
|
|
|
72
|
|
|
$shopDomain = NULL; |
|
|
|
|
73
|
|
|
$return = $this->component->setShopDomain($shopDomain); |
74
|
|
|
$this->assertNull($return); |
75
|
|
|
$return = $this->component->getShopDomain(); |
76
|
|
|
$this->assertNull($return); |
77
|
|
|
|
78
|
|
|
$shopDomain = false; |
79
|
|
|
$return = $this->component->setShopDomain($shopDomain); |
|
|
|
|
80
|
|
|
$this->assertFalse($return); |
81
|
|
|
$return = $this->component->getShopDomain(); |
82
|
|
|
$this->assertFalse($return); |
83
|
|
|
|
84
|
|
|
$shopDomain = true; |
85
|
|
|
$return = $this->component->setShopDomain($shopDomain); |
|
|
|
|
86
|
|
|
$this->assertTrue($return); |
87
|
|
|
$return = $this->component->getShopDomain(); |
88
|
|
|
$this->assertTrue($return); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function testSetAccessToken() |
|
|
|
|
92
|
|
|
{ |
93
|
|
|
$this->markTestIncomplete('Not implemented yet.'); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function testGetAuthorizeUrl() |
|
|
|
|
97
|
|
|
{ |
98
|
|
|
$this->markTestIncomplete('Not implemented yet.'); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function testGetAccessToken() |
|
|
|
|
102
|
|
|
{ |
103
|
|
|
$this->markTestIncomplete('Not implemented yet.'); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function testNonce() |
|
|
|
|
107
|
|
|
{ |
108
|
|
|
$nonce = md5(rand()); |
109
|
|
|
$return = $this->component->setNonce($nonce); |
110
|
|
|
$this->assertSame($return, $nonce); |
111
|
|
|
$return = $this->component->getNonce(); |
112
|
|
|
$this->assertSame($return, $nonce); |
113
|
|
|
|
114
|
|
|
$nonce = md5(rand()); |
115
|
|
|
$this->component->setNonce($nonce); |
116
|
|
|
$return = $this->component->setNonce($nonce); |
117
|
|
|
$this->assertSame($return, $nonce); |
118
|
|
|
$return = $this->component->getNonce(); |
119
|
|
|
$this->assertSame($return, $nonce); |
120
|
|
|
|
121
|
|
|
$nonce = NULL; |
|
|
|
|
122
|
|
|
$return = $this->component->setNonce($nonce); |
123
|
|
|
$this->assertNull($return); |
124
|
|
|
$return = $this->component->getNonce(); |
125
|
|
|
$this->assertNull($return); |
126
|
|
|
|
127
|
|
|
$nonce = false; |
128
|
|
|
$return = $this->component->setNonce($nonce); |
|
|
|
|
129
|
|
|
$this->assertFalse($return); |
130
|
|
|
$return = $this->component->getNonce(); |
131
|
|
|
$this->assertFalse($return); |
132
|
|
|
|
133
|
|
|
$nonce = true; |
134
|
|
|
$return = $this->component->setNonce($nonce); |
|
|
|
|
135
|
|
|
$this->assertTrue($return); |
136
|
|
|
$return = $this->component->getNonce(); |
137
|
|
|
$this->assertTrue($return); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
} |
141
|
|
|
|