Completed
Push — master ( dd21cf...b0fced )
by AJ
07:09
created

ShopifyAPIComponentTest::testValidateHMAC()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 14
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 9
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";
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...
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";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal random.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...
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);
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...
90
        $this->assertFalse($return);
91
        $return = $this->component->getShopDomain();
92
        $this->assertFalse($return);
93
        
94
        $shopDomain = true;
95
        $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...
96
        $this->assertTrue($return);
97
        $return = $this->component->getShopDomain();
98
        $this->assertTrue($return);
99
        
100
        $shopDomain = "test.myshopify.com";
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...
101
        $return = $this->component->validDomain($shopDomain);
102
        $this->assertTrue($return);
103
        
104
        $shopDomain = "TEST.MYshopify.COM";
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...
105
        $return = $this->component->validDomain($shopDomain);
106
        $this->assertTrue($return);
107
        
108
        $shopDomain = "random.myshopify.com";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal random.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...
109
        $return = $this->component->validDomain($shopDomain);
110
        $this->assertTrue($return);
111
        
112
        $shopDomain = "www.myshopify.com";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal www.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...
113
        $return = $this->component->validDomain($shopDomain);
114
        $this->assertTrue($return);
115
        
116
        /*$shopDomain = "test.myshopify.net";
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
142
    {
143
        $this->markTestIncomplete('Not implemented yet.');
144
    }
145
146
    public function testGetAuthorizeUrl()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
147
    {
148
        $this->markTestIncomplete('Not implemented yet.');
149
    }
150
151
    public function testGetAccessToken()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
152
    {
153
        $this->markTestIncomplete('Not implemented yet.');
154
    }
155
156
    public function testNonce()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
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);
0 ignored issues
show
Documentation introduced by
$nonce 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...
178
        $this->assertFalse($return);
179
        $return = $this->component->getNonce();
180
        $this->assertFalse($return);
181
        
182
        $nonce = true;
183
        $return = $this->component->setNonce($nonce);
0 ignored issues
show
Documentation introduced by
$nonce 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...
184
        $this->assertTrue($return);
185
        $return = $this->component->getNonce();
186
        $this->assertTrue($return);
187
    }
188
	
189
	public function testValidateHMAC()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
190
	{
191
		$return = $this->component->validateHMAC();
0 ignored issues
show
Bug introduced by
The call to validateHMAC() misses a required argument $query.

This check looks for function calls that miss required arguments.

Loading history...
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"]);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal string 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...
201
		$this->assertFalse($return);
202
	}
203
}
204