Issues (128)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

tests/TableShippingMethodTest.php (14 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
class TableShippingMethodTest extends SapphireTest{
4
    
5
    static $fixture_file = array(
6
        'silvershop-shipping/tests/fixtures/TableShippingMethod.yml'
7
    );
8
9
    protected $fixtureclass = "TableShippingMethod";
10
    
11
    public function setUp(){
12
        parent::setUp();
13
        $this->addressshipping = $this->objFromFixture($this->fixtureclass, "address");
0 ignored issues
show
The property addressshipping does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
14
        $this->weightshipping = $this->objFromFixture($this->fixtureclass, "weight");
0 ignored issues
show
The property weightshipping does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
15
        $this->volumeshipping = $this->objFromFixture($this->fixtureclass, "volume");
0 ignored issues
show
The property volumeshipping does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
16
        $this->valueshipping = $this->objFromFixture($this->fixtureclass, "value");
0 ignored issues
show
The property valueshipping does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
17
        $this->quantityshipping = $this->objFromFixture($this->fixtureclass, "quantity");
0 ignored issues
show
The property quantityshipping does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
18
19
        $this->nzaddress = new Address(array(
0 ignored issues
show
The property nzaddress does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
20
            "Country" =>    "NZ",
21
            "State" =>      "Wellington",
22
            "PostalCode" => "6022"
23
        ));
24
25
        $this->internationaladdress = new Address(array(
0 ignored issues
show
The property internationaladdress does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
26
            "Company" => 'Nildram Ltd',
27
            "Address" => 'Ardenham Court',
28
            "Address2" =>    'Oxford Road',
29
            "City" => 'AYLESBURY',
30
            "State" => 'BUCKINGHAMSHIRE',
31
            "PostalCode" => 'HP19 3EQ',
32
            "Country" => 'UK'
33
        ));     
34
35
        //create some package fixtures
36
        $this->p0 = new ShippingPackage();
0 ignored issues
show
The property p0 does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
37
        $this->p1 = new ShippingPackage(2.34, array(0.5,1,2), array('value' => 2, 'quantity' => 3));
0 ignored issues
show
The property p1 does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
38
        $this->p2 = new ShippingPackage(17, array(1,2,3), array('value' => 6, 'quantity' => 10));
0 ignored issues
show
The property p2 does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
39
        $this->p3 = new ShippingPackage(100, array(12.33,51,30.1), array('value' => 1000, 'quantity' => 55));
0 ignored issues
show
The property p3 does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
40
        $this->p4 = new ShippingPackage(1000, array(100,200,300), array('value' => 1000000, 'quantity' => 12412));
0 ignored issues
show
The property p4 does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
41
    }
42
    
43
    public function testAddressTable() {
44
        $type = "address";
45
46
        $address = new Address(array(
47
            'Country' => 'NZ',
48
            'State' => 'Wellington'
49
        ));
50
        $this->assertMatch($type, $this->p0, $address, 30);
51
        $this->assertMatch($type, $this->p2, $address, 30);
52
        $this->assertMatch($type, $this->p4, $address, 30);
53
54
        $address = new Address(array(
55
            'Country' => 'NZ',
56
            'PostalCode' => '6000'
57
        ));
58
        $this->assertMatch($type, $this->p0, $address, 45);
59
        $this->assertMatch($type, $this->p2, $address, 45);
60
        $this->assertMatch($type, $this->p4, $address, 45); 
61
62
        //empty package rate
63
        $address = $this->internationaladdress;
64
65
        $this->assertMatch($type, $this->p0, $address, 0);
66
        $this->assertMatch($type, $this->p2, $address, 0);
67
        $this->assertMatch($type, $this->p4, $address, 0);
68
    }
69
70
    public function testDefaultRate() {
71
        $type = "address";
72
        $address = $this->internationaladdress;
73
        $defaultrate = new TableShippingRate(array(
74
            "Rate" => 100
75
        ));
76
        $defaultrate->write();
77
        $this->addressshipping->Rates()->add($defaultrate);
78
79
        $this->assertMatch($type, $this->p0, $address, 100);
80
        $this->assertMatch($type, $this->p2, $address, 100);
81
        $this->assertMatch($type, $this->p4, $address, 100);
82
    }
83
84
    public function testInternationalRates(){
85
        $address_int = $this->internationaladdress;
86
87
        //weight based
88
        $type = "weight";
89
        $this->assertMatch($type, $this->p0, $address_int, 8); //weight = 0kg
90
        $this->assertMatch($type, $this->p1, $address_int, 8); //weight = 2.34kg
91
        $this->assertMatch($type, $this->p2, $address_int, 96); //weight= 17kg, 
92
        $this->assertMatch($type, $this->p3, $address_int, 116); //weight = 100kg
93
        $this->assertNoMatch($type, $this->p4, $address_int);  //weight = 1000kg
94
95
        //volume based
96
        $type = "volume";
97
        $this->assertMatch($type, $this->p0, $address_int, 2); //volume = 0cm3
98
        $this->assertMatch($type, $this->p1, $address_int, 2); //volume = 1cm3
99
        $this->assertMatch($type, $this->p2, $address_int, 6); //volume = 6cm3
100
        $this->assertMatch($type, $this->p3, $address_int, 520); //volume = 18927.783cm3
101
        $this->assertNoMatch($type, $this->p4, $address_int); //volume = 2000000cm3
102
103
        //value based
104
        $type = "value";
105
        $this->assertMatch($type, $this->p0, $address_int, 2); //value = $0
106
        $this->assertMatch($type, $this->p1, $address_int, 2); //value = $2
107
        $this->assertMatch($type, $this->p2, $address_int, 6); //value = $6
108
        $this->assertNoMatch($type, $this->p3, $address_int); //value = $1000
109
        $this->assertNoMatch($type, $this->p4, $address_int); //value = $1,000,000
110
        
111
        //quantity based
112
        $type = "quantity";
113
        $this->assertNoMatch($type, $this->p0, $address_int); //quantity = 0
114
        $this->assertMatch($type, $this->p1, $address_int, 11); //quantity = 3
115
        $this->assertMatch($type, $this->p2, $address_int, 18.6); //quantity = 10
116
        $this->assertNoMatch($type, $this->p3, $address_int); //quantity = 155
117
        $this->assertNoMatch($type, $this->p4, $address_int); //quantity = 12412
118
    }
119
    
120
    public function testLocalRates(){
121
        $address_loc = $this->nzaddress;
122
        
123
        //weight based
124
        $type = "weight";
125
        $this->assertMatch($type, $this->p0, $address_loc, 4); //weight = 0kg
126
        $this->assertMatch($type, $this->p1, $address_loc, 4); //weight = 2.34kg
127
        $this->assertMatch($type, $this->p2, $address_loc, 48); //weight= 17kg,
128
        $this->assertMatch($type, $this->p3, $address_loc, 58); //weight = 100kg
129
        $this->assertNoMatch($type, $this->p4, $address_loc);  //weight = 1000kg
130
        
131
        //volume based
132
        $type = "volume";
133
        $this->assertMatch($type, $this->p0, $address_loc, 1); //volume = 0cm3
134
        $this->assertMatch($type, $this->p1, $address_loc, 1); //volume = 1cm3
135
        $this->assertMatch($type, $this->p2, $address_loc, 3); //volume = 6cm3
136
        $this->assertMatch($type, $this->p3, $address_loc, 520); //volume = 18927.783cm3
137
        $this->assertNoMatch($type, $this->p4, $address_loc); //volume = 2000000cm3
138
        
139
        //value based
140
        $type = "value";
141
        $this->assertMatch($type, $this->p0, $address_loc, 1); //value = $0
142
        $this->assertMatch($type, $this->p1, $address_loc, 1); //value = $2
143
        $this->assertMatch($type, $this->p2, $address_loc, 3); //value = $6
144
        $this->assertNoMatch($type, $this->p3, $address_loc); //value = $1000
145
        $this->assertNoMatch($type, $this->p4, $address_loc); //value = $1,000,000
146
        
147
        //quantity based
148
        $type = "quantity";
149
        $this->assertNoMatch($type, $this->p0, $address_loc); //quantity = 0
150
        $this->assertMatch($type, $this->p1, $address_loc, 5.5); //quantity = 3
151
        $this->assertMatch($type, $this->p2, $address_loc, 9.3); //quantity = 10
152
        $this->assertNoMatch($type, $this->p3, $address_loc); //quantity = 155
153
        $this->assertNoMatch($type, $this->p4, $address_loc); //quantity = 12412
154
        
155
    }
156
    
157
    protected function assertMatch($type = "weight", $package, $address, $amount){
158
        $rate = $this->{$type."shipping"}->calculateRate($package, $address);
159
        $this->assertEquals($amount, $rate, "Check rate for package $package is $amount");
0 ignored issues
show
The method assertEquals() does not seem to exist on object<TableShippingMethodTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
160
    }
161
    
162
    protected function assertNoMatch($type = "weight", $package, $address){
163
        $rate = $this->{$type."shipping"}->calculateRate($package,$address);
164
        $this->assertNull($rate,"Check rate for package $package is not found");
0 ignored issues
show
The method assertNull() does not seem to exist on object<TableShippingMethodTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
165
    }
166
    
167
}