Passed
Branch develop (bae466)
by Paul
06:12
created

HelperTest::test_is_less_then_or_equal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Tests;
4
5
use GeminiLabs\SiteReviews\Helper;
6
use WP_UnitTestCase;
0 ignored issues
show
Bug introduced by
The type WP_UnitTestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
/**
9
 * Test case for the Plugin.
10
 * @group plugin
11
 */
12
class HelperTest extends WP_UnitTestCase
13
{
14
    public function test_build_class_name()
15
    {
16
        $this->assertEquals(Helper::buildClassName('hello-doll'), 'HelloDoll');
17
        $this->assertEquals(
18
            Helper::buildClassName('Doll', 'Hello'),
19
            'GeminiLabs\SiteReviews\Hello\Doll'
20
        );
21
    }
22
23
    public function test_build_method_name()
24
    {
25
        $this->assertEquals(Helper::buildMethodName('get', 'Hello-Doll'), 'getHelloDoll');
26
    }
27
28
    public function test_compare_versions()
29
    {
30
        $this->assertTrue(Helper::compareVersions('1.0', '1'));
31
        $this->assertTrue(Helper::compareVersions('1.0', '1.00'));
32
        $this->assertFalse(Helper::compareVersions('1.0', '1.0.10'));
33
    }
34
35
    public function test_filter_input()
36
    {
37
        $_POST['xxx'] = 'xxx';
38
        $this->assertEquals(Helper::filterInput('xxx'), 'xxx');
39
        $this->assertEquals(Helper::filterInput('zzz'), null);
40
    }
41
42
    public function test_filter_input_array()
43
    {
44
        $test = ['a' => ['b', 'c']];
45
        $_POST['xxx'] = $test;
46
        $this->assertEquals(Helper::filterInputArray('xxx'), $test);
47
        $this->assertEquals(Helper::filterInputArray('zzz'), []);
48
    }
49
50
    public function test_get_ip_address()
51
    {
52
        $this->assertEquals(Helper::getIpAddress(), '127.0.0.1');
53
    }
54
55
    public function test_get_page_number()
56
    {
57
        $queryvar = glsr()->constant('PAGED_QUERY_VAR');
58
        $this->assertEquals(Helper::getPageNumber("https://test.com?{$queryvar}=2"), '2');
59
        $this->assertEquals(Helper::getPageNumber(), '1');
60
    }
61
62
    public function test_if_empty()
63
    {
64
        $this->assertEquals(Helper::ifEmpty(0, 'abc'), 0);
65
        $this->assertEquals(Helper::ifEmpty(0, 'abc', $strict = true), 'abc');
66
        $this->assertEquals(Helper::ifEmpty([], 'abc'), 'abc');
67
        $this->assertEquals(Helper::ifEmpty([], 'abc', $strict = true), 'abc');
68
        $this->assertEquals(Helper::ifEmpty(false, 'abc'), $strict = false);
69
        $this->assertEquals(Helper::ifEmpty(false, 'abc', $strict = true), 'abc');
70
        $this->assertEquals(Helper::ifEmpty(null, 'abc'), 'abc');
71
        $this->assertEquals(Helper::ifEmpty(null, 'abc', $strict = true), 'abc');
72
        $this->assertEquals(Helper::ifEmpty('', 'abc'), 'abc');
73
        $this->assertEquals(Helper::ifEmpty('', 'abc', $strict = true), 'abc');
74
    }
75
76
    public function test_is_greater_then()
77
    {
78
        $this->assertFalse(Helper::isGreaterThan('1.0', '1'));
79
        $this->assertFalse(Helper::isGreaterThan('1.0.0', '1.0'));
80
        $this->assertFalse(Helper::isGreaterThan('1.0.0', '1.0.0'));
81
        $this->assertFalse(Helper::isGreaterThan('1.0.0', '1.0.1'));
82
    }
83
84
    public function test_is_greater_then_or_equal()
85
    {
86
        $this->assertTrue(Helper::isGreaterThanOrEqual('1.0', '1'));
87
        $this->assertTrue(Helper::isGreaterThanOrEqual('1.0.0', '1.0'));
88
        $this->assertTrue(Helper::isGreaterThanOrEqual('1.0.0', '1.0.0'));
89
        $this->assertFalse(Helper::isGreaterThanOrEqual('1.0.0', '1.0.1'));
90
    }
91
92
    public function test_is_less_then()
93
    {
94
        $this->assertFalse(Helper::isLessThan('1', '1.0'));
95
        $this->assertFalse(Helper::isLessThan('1.0', '1.0.0'));
96
        $this->assertFalse(Helper::isLessThan('1.0.0', '1.0.0'));
97
        $this->assertFalse(Helper::isLessThan('1.0.1', '1.0.0'));
98
    }
99
100
    public function test_is_less_then_or_equal()
101
    {
102
        $this->assertTrue(Helper::isLessThanOrEqual('1', '1.0'));
103
        $this->assertTrue(Helper::isLessThanOrEqual('1.0', '1.0.0'));
104
        $this->assertTrue(Helper::isLessThanOrEqual('1.0.0', '1.0.0'));
105
        $this->assertFalse(Helper::isLessThanOrEqual('1.0.1', '1.0.0'));
106
    }
107
}
108