|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package wpmautic\tests |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Test Mautic options validation |
|
8
|
|
|
*/ |
|
9
|
|
|
class OptionsValidationTest extends WP_UnitTestCase |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
21
|
|
|
$this->assertArrayHasKey('script_location', $options); |
|
|
|
|
|
|
22
|
|
|
$this->assertArrayHasKey('fallback_activated', $options); |
|
|
|
|
|
|
23
|
|
|
$this->assertEmpty($options['base_url']); |
|
|
|
|
|
|
24
|
|
|
$this->assertEquals('header', $options['script_location']); |
|
|
|
|
|
|
25
|
|
|
$this->assertFalse($options['fallback_activated']); |
|
|
|
|
|
|
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']); |
|
|
|
|
|
|
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']); |
|
|
|
|
|
|
43
|
|
|
$this->assertEquals('footer', $options['script_location']); |
|
|
|
|
|
|
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']); |
|
|
|
|
|
|
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']); |
|
|
|
|
|
|
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']); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.