Completed
Push — master ( c6d68c...a74e45 )
by AJ
02:24
created

ShopifyAPIComponentTest::testRequestAccessToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
37
    {
38
        parent::setUp();
39
        
40
        Configure::write('Multidimensional/Cakephpify', [
41
                'abc123' =>
42
                    [
43
                    'sharedSecret' => 'abc123',
44
                    'scope' => '',
45
                    'privateApp' => false,
46
                    'privateAppPassword' => NULL]
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
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()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
62
    {
63
        parent::tearDown();
64
        unset($this->component, $this->controller);
65
    }
66
67
    public function testShopDomain()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
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);
0 ignored issues
show
Documentation introduced by
$shopDomain is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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);
0 ignored issues
show
Documentation introduced by
$shopDomain is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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);
0 ignored issues
show
Documentation introduced by
$shopDomain is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
139
        $this->assertFalse($return);
140
        
141
        $shopDomain = true;
142
        $this->assertTrue($shopDomain);
143
        $return = $this->component->validDomain($shopDomain);
0 ignored issues
show
Documentation introduced by
$shopDomain is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
144
        $this->assertFalse($return);
145
    }
146
147
    public function testAccessToken()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
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);
0 ignored issues
show
Documentation introduced by
$token is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
165
        $this->assertFalse($return);
166
        $return = $this->component->getAccessToken();
167
        $this->assertFalee($return);
0 ignored issues
show
Bug introduced by
The method assertFalee() does not exist on Multidimensional\Cakephp...ShopifyAPIComponentTest. Did you maybe mean assertFalse()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
168
        
169
        $token = true;
170
        $this->assertTrue($token);
171
        $return = $this->component->setAccessToken($token);
0 ignored issues
show
Documentation introduced by
$token is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
172
        $this->assertTrue($return);
173
        $return = $this->component->getAccessToken();
174
        $this->assertTrue($return);
175
    }
176
177
    public function testGetAuthorizeUrl()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
178
    {
179
        $this->markTestIncomplete('Not implemented yet.');
180
    }
181
182
    public function testRequestAccessToken()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
183
    {
184
        $this->markTestIncomplete('Not implemented yet.');
185
    }
186
187
    public function testNonce()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
188
    {
189
        $shopDomain = "test.myshopify.com"; //339fdccae930940993141bde32be560f
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal test.myshopify.com does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
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
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal TeSt.MySHoPiFy.CoM does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
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
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal example.com does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
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);
0 ignored issues
show
Documentation introduced by
$shopDomain is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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);
0 ignored issues
show
Documentation introduced by
$shopDomain is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
224
        $this->assertSame($return, 'c4ca4238a0b923820dcc509a6f75849b');
225
        $return = $this->component->getNonce();
226
        $this->assertSame($return, 'c4ca4238a0b923820dcc509a6f75849b');
227
    }
228
    
229
    public function testValidateHMAC()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
230
    {
231
        $return = $this->component->validateHMAC(null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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