Test Failed
Branch master (4a30b9)
by John
02:00
created

test_validation_with_invalid_url()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package wpmautic\tests
4
 */
5
6
/**
7
 * Test Mautic options validation
8
 */
9
class OptionsValidationTest extends WP_UnitTestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
{
11
    public function setUp()
12
    {
13
        parent::setUp();
14
        require_once(VPMAUTIC_PLUGIN_DIR.'/options.php');
15
    }
16
17
    public function test_validation_when_empty()
18
    {
19
        $options = wpmautic_options_validate(array());
20
        $this->assertArrayHasKey('base_url', $options);
0 ignored issues
show
Bug introduced by
The method assertArrayHasKey() does not seem to exist on object<OptionsValidationTest>.

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...
21
        $this->assertArrayHasKey('script_location', $options);
0 ignored issues
show
Bug introduced by
The method assertArrayHasKey() does not seem to exist on object<OptionsValidationTest>.

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...
22
        $this->assertArrayHasKey('fallback_activated', $options);
0 ignored issues
show
Bug introduced by
The method assertArrayHasKey() does not seem to exist on object<OptionsValidationTest>.

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...
23
        $this->assertEmpty($options['base_url']);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<OptionsValidationTest>.

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...
24
        $this->assertEquals('header', $options['script_location']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<OptionsValidationTest>.

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...
25
        $this->assertFalse($options['fallback_activated']);
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<OptionsValidationTest>.

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...
26
    }
27
28
    public function test_validation_with_invalid_script_location()
29
    {
30
        $options = wpmautic_options_validate(array(
31
            'script_location' => 'toto'
32
        ));
33
        $this->assertEquals('header', $options['script_location']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<OptionsValidationTest>.

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...
34
    }
35
36
    public function test_validation_with_whitespaces_in_values()
37
    {
38
        $options = wpmautic_options_validate(array(
39
            'base_url' => '    http://example.com    ',
40
            'script_location' => '    footer    '
41
        ));
42
        $this->assertEquals('http://example.com', $options['base_url']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<OptionsValidationTest>.

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...
43
        $this->assertEquals('footer', $options['script_location']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<OptionsValidationTest>.

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...
44
    }
45
46
    public function test_validation_with_invalid_url()
47
    {
48
        $options = wpmautic_options_validate(array(
49
            'base_url' => 'url'
50
        ));
51
        $this->assertEquals('http://url', $options['base_url']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<OptionsValidationTest>.

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...
52
    }
53
54
    public function test_validation_with_invalid_fallback_activated()
55
    {
56
        $options = wpmautic_options_validate(array(
57
            'fallback_activated' => 'toto'
58
        ));
59
        $this->assertFalse($options['fallback_activated']);
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<OptionsValidationTest>.

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...
60
    }
61
62
    public function test_validation_with_valid_fallback_activated()
63
    {
64
        $options = wpmautic_options_validate(array(
65
            'fallback_activated' => '1'
66
        ));
67
        $this->assertTrue($options['fallback_activated']);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<OptionsValidationTest>.

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...
68
    }
69
}
70